diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb index 576f2f764e..1e61883b1c 100644 --- a/app/models/spree/payment_decorator.rb +++ b/app/models/spree/payment_decorator.rb @@ -82,6 +82,15 @@ module Spree refund_amount.to_f end + # See #1074 and #1837 for more detail on why we need this + # An 'orphaned' Spree::Payment is created for every call to CheckoutController#update + # for orders that are processed using a Spree::Gateway::PayPalExpress payment method + # These payments are 'orphaned' because they are never used by the spree_paypal_express gem + # which creates a brand new Spree::Payment from scratch in PayPalController#confirm + # However, the 'orphaned' payments are useful when applying a transaction fee, because the fees + # need to be calculated before the order details are sent to PayPal for confirmation + # This is our best hook for removing the orphaned payments at an appropriate time. ie. after + # the payment details have been confirmed, but before any payments have been processed def destroy_orphaned_paypal_payments return unless source_type == "Spree::PaypalExpressCheckout" orphaned_payments = order.payments.where(payment_method_id: payment_method_id, source_id: nil)