Merge pull request #6132 from Matt-Yorkley/stripe-multiple-payments-spec

Stripe Tests: multiple attempted payments
This commit is contained in:
Luis Ramos
2020-10-06 17:17:25 +01:00
committed by GitHub

View File

@@ -88,6 +88,7 @@ feature "Check out with Stripe", js: true do
create(:stripe_sca_payment_method, distributors: [distributor])
}
let!(:shipping_method) { create(:shipping_method) }
let(:error_message) { "Card was declined: insufficient funds." }
context "with guest checkout" do
before do
@@ -111,8 +112,6 @@ feature "Check out with Stripe", js: true do
end
context "when the card is rejected" do
let(:error_message) { "Card was declined: insufficient funds." }
before do
stub_payment_intents_post_request order: order
stub_failed_capture_request order: order, response: { message: error_message }
@@ -163,8 +162,6 @@ feature "Check out with Stripe", js: true do
end
describe "and the authorization fails" do
let(:error_message) { "Card was declined: insufficient funds." }
before do
stub_failed_capture_request order: order, response: { message: error_message }
end
@@ -181,6 +178,32 @@ feature "Check out with Stripe", js: true do
end
end
end
context "with multiple payment attempts; one failed and one succeeded" do
before do
stub_payment_intents_post_request order: order
end
it "records failed payment attempt and allows order completion" do
# First payment attempt is rejected
stub_failed_capture_request(order: order, response: { message: error_message })
checkout_with_stripe
expect(page).to have_content error_message
expect(order.reload.payments.count).to eq 1
expect(order.state).to eq "cart"
expect(order.payments.first.state).to eq "failed"
# Second payment attempt is accepted
stub_successful_capture_request order: order
place_order
expect(page).to have_content "Confirmed"
expect(order.reload.payments.count).to eq 2
expect(order.state).to eq "complete"
expect(order.payments.last.state).to eq "completed"
end
end
end
end
end