diff --git a/app/controllers/spree/credit_cards_controller.rb b/app/controllers/spree/credit_cards_controller.rb index fbad74e943..d2d7939d0f 100644 --- a/app/controllers/spree/credit_cards_controller.rb +++ b/app/controllers/spree/credit_cards_controller.rb @@ -56,15 +56,9 @@ module Spree private - # Currently can only destroy the whole customer object + # It destroys the whole customer object def destroy_at_stripe - if @credit_card.payment_method && - @credit_card.payment_method.type == "Spree::Gateway::StripeSCA" - options = { stripe_account: stripe_account_id } - end - - stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id, - options || {}) + stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id, {}) stripe_customer.delete if stripe_customer end diff --git a/app/models/spree/gateway/stripe_sca.rb b/app/models/spree/gateway/stripe_sca.rb index e0849d2dbb..78fff7d0cd 100644 --- a/app/models/spree/gateway/stripe_sca.rb +++ b/app/models/spree/gateway/stripe_sca.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'stripe/profile_storer' +require 'stripe/credit_card_cloner' require 'active_merchant/billing/gateways/stripe_payment_intents' require 'active_merchant/billing/gateways/stripe_decorator' @@ -52,7 +53,7 @@ module Spree def create_profile(payment) return unless payment.source.gateway_customer_profile_id.nil? - profile_storer = Stripe::ProfileStorer.new(payment, provider, stripe_account_id) + profile_storer = Stripe::ProfileStorer.new(payment, provider) profile_storer.create_customer_from_token end diff --git a/app/views/spree/admin/payments/source_forms/_stripe_sca.html.haml b/app/views/spree/admin/payments/source_forms/_stripe_sca.html.haml index b8939ea4a7..fbdba84ac3 100644 --- a/app/views/spree/admin/payments/source_forms/_stripe_sca.html.haml +++ b/app/views/spree/admin/payments/source_forms/_stripe_sca.html.haml @@ -2,7 +2,7 @@ %script{:src => "https://js.stripe.com/v3/", :type => "text/javascript"} - if Stripe.publishable_key :javascript - angular.module('admin.payments').value("stripeObject", Stripe("#{Stripe.publishable_key}", { stripeAccount: "#{StripeAccount.find_by_enterprise_id(payment_method.preferred_enterprise_id).andand.stripe_user_id}" })) + angular.module('admin.payments').value("stripeObject", Stripe("#{Stripe.publishable_key}")) .row .three.columns diff --git a/app/views/spree/checkout/payment/_stripe_sca.html.haml b/app/views/spree/checkout/payment/_stripe_sca.html.haml index 00ded42afe..2929b90d3e 100644 --- a/app/views/spree/checkout/payment/_stripe_sca.html.haml +++ b/app/views/spree/checkout/payment/_stripe_sca.html.haml @@ -1,7 +1,7 @@ - content_for :injection_data do - if Stripe.publishable_key :javascript - angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}", { stripeAccount: "#{StripeAccount.find_by_enterprise_id(payment_method.preferred_enterprise_id).andand.stripe_user_id}" })) + angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) .row{ "ng-show" => "savedCreditCards.length > 0" } .small-12.columns diff --git a/lib/stripe/profile_storer.rb b/lib/stripe/profile_storer.rb index 1806a48bd6..eb5212a1d2 100644 --- a/lib/stripe/profile_storer.rb +++ b/lib/stripe/profile_storer.rb @@ -4,10 +4,9 @@ module Stripe class ProfileStorer - def initialize(payment, provider, stripe_account_id = nil) + def initialize(payment, provider) @payment = payment @provider = provider - @stripe_account_id = stripe_account_id end def create_customer_from_token @@ -29,13 +28,7 @@ module Stripe email: @payment.order.email, login: Stripe.api_key, address: address_for(@payment) - }.merge(stripe_account_option) - end - - def stripe_account_option - return {} if @stripe_account_id.blank? - - { stripe_account: @stripe_account_id } + } end def address_for(payment) diff --git a/spec/controllers/spree/credit_cards_controller_spec.rb b/spec/controllers/spree/credit_cards_controller_spec.rb index b9ed2ed77b..e8996433f3 100644 --- a/spec/controllers/spree/credit_cards_controller_spec.rb +++ b/spec/controllers/spree/credit_cards_controller_spec.rb @@ -172,22 +172,6 @@ describe Spree::CreditCardsController, type: :controller do expect(response).to redirect_to spree.account_path(anchor: 'cards') end end - - context "where the payment method is StripeSCA" do - let(:stripe_payment_method) { create(:stripe_sca_payment_method) } - let!(:card) { create(:credit_card, gateway_customer_profile_id: 'cus_AZNMJ', payment_method: stripe_payment_method) } - - before do - stub_request(:delete, "https://api.stripe.com/v1/customers/cus_AZNMJ"). - to_return(status: 200, body: JSON.generate(deleted: true, id: "cus_AZNMJ")) - end - - it "the request to destroy the Stripe customer includes the stripe_account_id" do - expect(Stripe::Customer).to receive(:retrieve).with(card.gateway_customer_profile_id, { stripe_account: "abc123" }) - - expect{ delete :destroy, params }.to change(Spree::CreditCard, :count).by(-1) - end - end end end end diff --git a/spec/lib/stripe/profile_storer_spec.rb b/spec/lib/stripe/profile_storer_spec.rb index beec53feec..a5c7cfc7d2 100644 --- a/spec/lib/stripe/profile_storer_spec.rb +++ b/spec/lib/stripe/profile_storer_spec.rb @@ -7,7 +7,6 @@ module Stripe describe "create_customer_from_token" do let(:payment) { create(:payment) } let(:stripe_payment_method) { create(:stripe_payment_method) } - let(:stripe_account_id) { "12312" } let(:profile_storer) { Stripe::ProfileStorer.new(payment, stripe_payment_method.provider) } let(:customer_id) { "cus_A123" }