From 2cb3da56abe873c4204ed96e61520fb87a387566 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 11 Jan 2017 14:51:10 +1100 Subject: [PATCH] Fix regression: Transaction fee double-charged --- app/models/spree/payment_decorator.rb | 1 + app/views/checkout/_summary.html.haml | 14 +++++----- .../consumer/shopping/checkout_spec.rb | 26 +++++++++++++++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb index 2ae08430b5..98b996cce7 100644 --- a/app/models/spree/payment_decorator.rb +++ b/app/models/spree/payment_decorator.rb @@ -16,6 +16,7 @@ module Spree adjustment.save else payment_method.create_adjustment(adjustment_label, order, self, true) + association(:adjustment).reload end end diff --git a/app/views/checkout/_summary.html.haml b/app/views/checkout/_summary.html.haml index 0fec419556..a6bb5ca651 100644 --- a/app/views/checkout/_summary.html.haml +++ b/app/views/checkout/_summary.html.haml @@ -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} diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index e1b696d0da..d9c9e8bf8f 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -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