mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-21 05:09:15 +00:00
Wait until the end to mark payment as processed
This gives us the opportunity to retry the operation in case the processing fails.
This commit is contained in:
@@ -144,6 +144,10 @@ module Spree
|
||||
I18n.t('payment_method_fee')
|
||||
end
|
||||
|
||||
def mark_as_processed
|
||||
update_attribute(:cvv_response_message, nil)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Don't charge fees for invalid or failed payments.
|
||||
|
||||
@@ -33,12 +33,12 @@ class ProcessPaymentIntent
|
||||
validate_intent!
|
||||
return Result.new(ok: false) unless valid?
|
||||
|
||||
mark_as_processed
|
||||
|
||||
OrderWorkflow.new(order).next
|
||||
|
||||
if last_payment.can_complete?
|
||||
last_payment.complete!
|
||||
last_payment.mark_as_processed
|
||||
|
||||
Result.new(ok: true)
|
||||
else
|
||||
Result.new(ok: false, error: "The payment could not be completed")
|
||||
@@ -64,10 +64,6 @@ class ProcessPaymentIntent
|
||||
last_payment&.state == "pending" && last_payment&.response_code == payment_intent
|
||||
end
|
||||
|
||||
def mark_as_processed
|
||||
last_payment.update_attribute(:cvv_response_message, nil)
|
||||
end
|
||||
|
||||
def stripe_account_id
|
||||
StripeAccount.find_by(enterprise_id: preferred_enterprise_id).stripe_user_id
|
||||
end
|
||||
|
||||
@@ -926,4 +926,13 @@ describe Spree::Payment do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#mark_as_processed" do
|
||||
let(:payment) { create(:payment, cvv_response_message: "message") }
|
||||
|
||||
it "removes the cvv_response_message" do
|
||||
payment.mark_as_processed
|
||||
expect(payment.cvv_response_message).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user