mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Extract redirect stub to stripe_helper
This commit is contained in:
@@ -89,21 +89,9 @@ feature '
|
||||
end
|
||||
|
||||
context "with a card that fails on registration because it requires(redirects) extra auth" do
|
||||
let(:stripe_redirect_url) { checkout_path(payment_intent: "pi_123") }
|
||||
let(:payment_intent_authorize_response) do
|
||||
{ status: 200, body: JSON.generate(id: "pi_123",
|
||||
object: "payment_intent",
|
||||
next_source_action: {
|
||||
type: "authorize_with_url",
|
||||
authorize_with_url: { url: stripe_redirect_url }
|
||||
},
|
||||
status: "requires_source_action") }
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://api.stripe.com/v1/payment_intents")
|
||||
.with(basic_auth: ["sk_test_12345", ""], body: /.*#{order.number}/)
|
||||
.to_return(payment_intent_authorize_response)
|
||||
stub_payment_intents_post_request_with_redirect order: order,
|
||||
redirect_url: "www.dummy.org"
|
||||
end
|
||||
|
||||
it "fails to add a payment due to card error" do
|
||||
|
||||
@@ -127,21 +127,10 @@ feature "Check out with Stripe", js: true do
|
||||
end
|
||||
|
||||
context "when the card needs extra SCA authorization", js: true do
|
||||
let(:stripe_redirect_url) { checkout_path(payment_intent: "pi_123") }
|
||||
let(:payment_intent_authorize_response) do
|
||||
{ status: 200, body: JSON.generate(id: "pi_123",
|
||||
object: "payment_intent",
|
||||
next_source_action: {
|
||||
type: "authorize_with_url",
|
||||
authorize_with_url: { url: stripe_redirect_url }
|
||||
},
|
||||
status: "requires_source_action") }
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://api.stripe.com/v1/payment_intents")
|
||||
.with(basic_auth: ["sk_test_12345", ""], body: /.*#{order.number}/)
|
||||
.to_return(payment_intent_authorize_response)
|
||||
stripe_redirect_url = checkout_path(payment_intent: "pi_123")
|
||||
stub_payment_intents_post_request_with_redirect order: order,
|
||||
redirect_url: stripe_redirect_url
|
||||
end
|
||||
|
||||
describe "and the authorization succeeds" do
|
||||
|
||||
@@ -42,6 +42,12 @@ module StripeHelper
|
||||
stub.to_return(payment_intent_authorize_response_mock(response))
|
||||
end
|
||||
|
||||
def stub_payment_intents_post_request_with_redirect(order:, redirect_url:)
|
||||
stub_request(:post, "https://api.stripe.com/v1/payment_intents")
|
||||
.with(basic_auth: ["sk_test_12345", ""], body: /.*#{order.number}/)
|
||||
.to_return(payment_intent_redirect_response_mock(redirect_url))
|
||||
end
|
||||
|
||||
def stub_payment_intent_get_request(response: {}, stripe_account_header: true)
|
||||
stub = stub_request(:get, "https://api.stripe.com/v1/payment_intents/pi_123")
|
||||
stub = stub.with(headers: { 'Stripe-Account' => 'abc123' }) if stripe_account_header
|
||||
@@ -83,6 +89,16 @@ module StripeHelper
|
||||
charges: { data: [{ id: "ch_1234", amount: 2000 }] }) }
|
||||
end
|
||||
|
||||
def payment_intent_redirect_response_mock(redirect_url)
|
||||
{ status: 200, body: JSON.generate(id: "pi_123",
|
||||
object: "payment_intent",
|
||||
next_source_action: {
|
||||
type: "authorize_with_url",
|
||||
authorize_with_url: { url: redirect_url }
|
||||
},
|
||||
status: "requires_source_action") }
|
||||
end
|
||||
|
||||
def payment_successful_capture_mock(options)
|
||||
{ status: options[:code] || 200,
|
||||
body: JSON.generate(object: "payment_intent",
|
||||
|
||||
Reference in New Issue
Block a user