Skip to content

Commit

Permalink
Delete fee on payment method if payment invalid
Browse files Browse the repository at this point in the history
PayPalExpress is always creating two payments. The first one is
invalidated and the second one succeeds. Without deleting the old fee on
the invalidated payment, the order lists the fee twice.
  • Loading branch information
mkllnk committed Jul 15, 2016
1 parent af6d0ec commit ddb54d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/helpers/checkout_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def checkout_adjustments_for(order, opts={})
# Remove empty tax adjustments and (optionally) shipping fees
adjustments.reject! { |a| a.originator_type == 'Spree::TaxRate' && a.amount == 0 }
adjustments.reject! { |a| a.originator_type == 'Spree::ShippingMethod' } if exclude.include? :shipping
adjustments.reject! { |a| a.originator_type == 'Spree::PaymentMethod' } if exclude.include? :payment
adjustments.reject! { |a| a.source_type == 'Spree::LineItem' } if exclude.include? :line_item

enterprise_fee_adjustments = adjustments.select { |a| a.originator_type == 'EnterpriseFee' && a.source_type != 'Spree::LineItem' }
Expand Down
7 changes: 6 additions & 1 deletion app/models/spree/payment_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ module Spree
after_save :ensure_correct_adjustment, :update_order

def ensure_correct_adjustment
if adjustment
# Don't charge for invalid payments.
# PayPalExpress always creates a payment that is invalidated later.
# Unknown: What about failed payments?
if state == "invalid"
adjustment.andand.destroy
elsif adjustment
adjustment.originator = payment_method
adjustment.label = adjustment_label
adjustment.save
Expand Down
2 changes: 1 addition & 1 deletion app/views/checkout/_summary.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
= t :checkout_cart_total
%td.cart-total.text-right= display_checkout_subtotal(@order)

- checkout_adjustments_for(current_order, exclude: [:shipping, :line_item]).reject{ |a| a.amount == 0 }.each do |adjustment|
- checkout_adjustments_for(current_order, exclude: [:shipping, :payment, :line_item]).reject{ |a| a.amount == 0 }.each do |adjustment|
%tr
%th= adjustment.label
%td.text-right= adjustment.display_amount.to_html
Expand Down

0 comments on commit ddb54d1

Please sign in to comment.