mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add detailed explanation of why #destroy_orphaned_paypal_payments is required
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user