Fix profile_storer.rb and profile_storer_spec

This commit is contained in:
Nihal Mohammed
2021-08-06 14:49:59 +05:30
committed by Nihal
parent 6ac835de2e
commit fa9f6432c3
2 changed files with 15 additions and 11 deletions

View File

@@ -65,9 +65,13 @@ module Stripe
def customer_profile_id(response)
response.params['customer'] || response.params['id']
end
def payment_profile_id(response)
response.params['default_source'] || response.params['default_card']
if response.params['customer'] # Payment Intents API
response.params['id']
else
response.params['default_source'] || response.params['default_card']
end
end
end
end

View File

@@ -4,28 +4,28 @@ require 'spec_helper'
module Stripe
describe ProfileStorer do
include StripeStubs
describe "create_customer_from_token" do
let(:payment) { create(:payment) }
let(:stripe_payment_method) { create(:stripe_sca_payment_method) }
let(:card) { create(:credit_card, gateway_payment_profile_id: card_id) }
let(:payment) { create(:payment, source: card, payment_method: stripe_payment_method) }
let(:profile_storer) { Stripe::ProfileStorer.new(payment, stripe_payment_method.provider) }
let(:customer_id) { "cus_A123" }
let(:card_id) { "card_2342" }
let(:customer_response_mock) { { status: 200, body: customer_response_body } }
let(:customer_response_mock) {
{ status: 200, body: JSON.generate(id: customer_id, sources: { data: [{ id: "1" }] }) }
}
before do
Stripe.api_key = "sk_test_12345"
stub_request(:post, "https://api.stripe.com/v1/customers")
.with(basic_auth: ["sk_test_12345", ""], body: { email: payment.order.email })
.to_return(customer_response_mock)
stub_customers_post_request(email: payment.order.email, response: customer_response_mock)
stub_payment_method_attach_request(payment_method: card_id, customer: customer_id)
end
context "when called from Stripe SCA" do
let(:customer_response_body) {
JSON.generate(customer: customer_id, default_card: card_id, sources: { data: [{ id: "1" }] })
}
it "fetches the customer id and the card id from the correct response fields" do
profile_storer.create_customer_from_token