diff --git a/spec/features/consumer/shopping/checkout_stripe_spec.rb b/spec/features/consumer/shopping/checkout_stripe_spec.rb index c81c44d5770..c3ae3f793c6 100644 --- a/spec/features/consumer/shopping/checkout_stripe_spec.rb +++ b/spec/features/consumer/shopping/checkout_stripe_spec.rb @@ -234,7 +234,7 @@ stub_payment_intents_post_request order: order stub_successful_capture_request order: order stub_customers_post_request email: "test@test.com" # First checkout with default details - stub_customers_post_request email: user.email # Second checkout with saved user details + stub_customers_post_request email: user.email, card: nil # Second checkout with saved user details stub_payment_method_attach_request end diff --git a/spec/lib/stripe/credit_card_cloner_spec.rb b/spec/lib/stripe/credit_card_cloner_spec.rb index 1e808498732..b0520520315 100644 --- a/spec/lib/stripe/credit_card_cloner_spec.rb +++ b/spec/lib/stripe/credit_card_cloner_spec.rb @@ -27,6 +27,7 @@ module Stripe Stripe.api_key = "sk_test_12345" stub_customers_post_request email: credit_card.user.email, + card: nil, response: { customer_id: new_customer_id }, stripe_account_header: true diff --git a/spec/requests/checkout/stripe_sca_spec.rb b/spec/requests/checkout/stripe_sca_spec.rb index 14a825e4595..0b1147c65ad 100644 --- a/spec/requests/checkout/stripe_sca_spec.rb +++ b/spec/requests/checkout/stripe_sca_spec.rb @@ -207,6 +207,8 @@ source_attributes = params[:order][:payments_attributes][0][:source_attributes] source_attributes[:save_requested_by_customer] = '1' + stub_customers_post_request email: order.user.email, response: customer_response_mock + # Attaches the payment method to the customer stub_request(:post, "https://api.stripe.com/v1/payment_methods/#{stripe_payment_method}/attach") @@ -215,6 +217,12 @@ end context "and the customer, payment_method and payment_intent requests are successful" do + before do + stub_add_metadata_request(payment_method: "pm_123", response: {}) + stub_payment_methods_post_request request: { customer: "cus_A123" }, + response: { pm_id: "pm_123" } + end + it "should process the payment, and store the card/customer details" do put update_checkout_path, params: params diff --git a/spec/support/request/stripe_stubs.rb b/spec/support/request/stripe_stubs.rb index 637c8b7ab7f..876a0755973 100644 --- a/spec/support/request/stripe_stubs.rb +++ b/spec/support/request/stripe_stubs.rb @@ -41,9 +41,11 @@ def stub_retrieve_payment_method_request(payment_method_id = "pm_1234") end # Stubs the customers call to both the main stripe account and the connected account - def stub_customers_post_request(email:, response: {}, stripe_account_header: false) + def stub_customers_post_request(email:, response: {}, stripe_account_header: false, card: "pm_123") + body = { email: email } + body.merge!({ card: card }) if card.present? stub = stub_request(:post, "https://api.stripe.com/v1/customers") - .with(body: { email: email }) + .with(body: body) stub = stub.with(headers: { 'Stripe-Account' => 'abc123' }) if stripe_account_header stub.to_return(customers_response_mock(response)) end