Add detailed explanation of why #destroy_orphaned_paypal_payments is required

This commit is contained in:
Rob Harrington
2017-09-20 18:12:28 +10:00
parent f4b1c5de9c
commit 3f3085c66b

View File

@@ -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)