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:
Pau Perez
2021-05-06 16:07:59 +02:00
parent dea6a01e61
commit 69b91ea136
3 changed files with 15 additions and 6 deletions

View File

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

View File

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

View File

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