From a52c4b542c2c7a604f8d9383f2b419ea48461794 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 13 Jan 2020 17:45:26 +0000 Subject: [PATCH] Make destroy stored cards work for stripe SCA by setting stripe account id before making the call to the stripe api This account id cannot be sent when dealing with the old StripeConnect gateway --- app/controllers/spree/credit_cards_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/credit_cards_controller.rb b/app/controllers/spree/credit_cards_controller.rb index 79f60b4323..a46937eb6c 100644 --- a/app/controllers/spree/credit_cards_controller.rb +++ b/app/controllers/spree/credit_cards_controller.rb @@ -54,10 +54,17 @@ module Spree # Currently can only destroy the whole customer object def destroy_at_stripe - stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id) + options = { stripe_account: stripe_account_id } if @credit_card.payment_method.type == "Spree::Gateway::StripeSCA" + + stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id, options || {}) stripe_customer.delete if stripe_customer end + def stripe_account_id + StripeAccount.find_by_enterprise_id(@credit_card.payment_method.preferred_enterprise_id).andand.stripe_user_id + end + + def create_customer(token) Stripe::Customer.create(email: spree_current_user.email, source: token) end