Fix regression: Transaction fee double-charged

This commit is contained in:
Rohan Mitchell
2017-01-11 14:51:10 +11:00
parent 8582e6d6b4
commit 2cb3da56ab
3 changed files with 32 additions and 9 deletions

View File

@@ -16,6 +16,7 @@ module Spree
adjustment.save
else
payment_method.create_adjustment(adjustment_label, order, self, true)
association(:adjustment).reload
end
end

View File

@@ -4,30 +4,30 @@
%legend
= t :checkout_your_order
%table
%tr
%tr.subtotal
%th
= t :checkout_cart_total
%td.cart-total.text-right= display_checkout_subtotal(@order)
- checkout_adjustments_for(current_order, exclude: [:shipping, :payment, :line_item]).reject{ |a| a.amount == 0 }.each do |adjustment|
%tr
%tr.adjustment
%th= adjustment.label
%td.text-right= adjustment.display_amount.to_html
%tr
%tr.shipping
%th
= t :checkout_shipping_price
%td.shipping.text-right {{ Checkout.shippingPrice() | localizeCurrency }}
%td.text-right {{ Checkout.shippingPrice() | localizeCurrency }}
%tr
%tr.transaction-fee
%th
= t :payment_method_fee
%td.text-right {{ Checkout.paymentPrice() | localizeCurrency }}
%tr
%tr.total
%th
= t :checkout_total_price
%td.total.text-right {{ Checkout.cartTotal() | localizeCurrency }}
%td.text-right {{ Checkout.cartTotal() | localizeCurrency }}
//= f.submit "Purchase", class: "button", "ofn-focus" => "accordion['payment']"
%a.button.secondary{href: cart_url}

View File

@@ -1,6 +1,5 @@
require 'spec_helper'
feature "As a consumer I want to check out my cart", js: true, retry: 3 do
include AuthenticationWorkflow
include ShopWorkflow
@@ -31,7 +30,7 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
let(:sm2) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 4.56)) }
let(:sm3) { create(:shipping_method, require_ship_address: false, name: "Local", tag_list: "local") }
let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") }
let!(:pm2) { create(:payment_method, distributors: [distributor]) }
let!(:pm2) { create(:payment_method, distributors: [distributor], calculator: Spree::Calculator::FlatRate.new(preferred_amount: 5.67)) }
let!(:pm3) do
Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', distributor_ids: [distributor.id]).tap do |pm|
pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com'
@@ -40,6 +39,7 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
end
end
before do
distributor.shipping_methods << sm1
distributor.shipping_methods << sm2
@@ -328,6 +328,28 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
end
end
context "when we are charged a payment method fee (transaction fee)" do
it "creates a payment including the transaction fee" do
# Selecting the transaction fee, it is displayed
expect(page).to have_selector ".transaction-fee td", text: "$0.00"
expect(page).to have_selector ".total", text: "$11.23"
toggle_payment
choose "#{pm2.name} ($5.67)"
expect(page).to have_selector ".transaction-fee td", text: "$5.67"
expect(page).to have_selector ".total", text: "$16.90"
place_order
expect(page).to have_content "Your order has been processed successfully"
# There are two orders - our order and our new cart
o = Spree::Order.complete.first
expect(o.adjustments.payment_fee.first.amount).to eq 5.67
expect(o.payments.first.amount).to eq(10 + 1.23 + 5.67) # items + fees + transaction
end
end
describe "credit card payments" do
["Spree::Gateway::Bogus", "Spree::Gateway::BogusSimple"].each do |gateway_type|
context "with a credit card payment method using #{gateway_type}" do