Merge pull request #8873 from Matt-Yorkley/stripe-retries

Update checkout retry logic
This commit is contained in:
Filipe
2022-02-14 15:28:56 +00:00
committed by GitHub
2 changed files with 13 additions and 1 deletions

View File

@@ -206,7 +206,7 @@ module Spree
# Makes newly entered payments invalidate previously entered payments so the most recent payment
# is used by the gateway.
def invalidate_old_payments
order.payments.with_state('checkout').where.not(id: id).each do |payment|
order.payments.incomplete.where.not(id: id).each do |payment|
# Using update_column skips validations and so it skips validate_source. As we are just
# invalidating past payments here, we don't want to validate all of them at this stage.
payment.update_columns(

View File

@@ -49,6 +49,18 @@ describe Spree::Payment do
end
end
context "creating a new payment alongside other incomplete payments" do
let(:order) { create(:order_with_totals) }
let!(:incomplete_payment) { create(:payment, order: order, state: "pending") }
let(:new_payment) { create(:payment, order: order, state: "checkout") }
it "invalidates other incomplete payments on the order" do
new_payment
expect(incomplete_payment.reload.state).to eq "invalid"
end
end
# Regression test for https://github.com/spree/spree/pull/2224
context 'failure' do
it 'should transition to failed from pending state' do