Skip to content

Commit

Permalink
add params to stubbed stripe methods
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpbrett committed Aug 18, 2021
1 parent 2a2135a commit 6c2d949
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spec/features/consumer/shopping/checkout_stripe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
stub_payment_intents_post_request order: order
stub_successful_capture_request order: order
stub_customers_post_request email: "[email protected]" # 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

Expand Down
1 change: 1 addition & 0 deletions spec/lib/stripe/credit_card_cloner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions spec/requests/checkout/stripe_sca_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions spec/support/request/stripe_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c2d949

Please sign in to comment.