mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-10 23:07:47 +00:00
remove cloned cards after removing the platform card
This commit is contained in:
@@ -63,8 +63,9 @@ module Spree
|
||||
|
||||
# It destroys the whole customer object
|
||||
def destroy_at_stripe
|
||||
stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id, {})
|
||||
Stripe::CreditCardCloner.new.destroy_clones(@credit_card)
|
||||
|
||||
stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id, {})
|
||||
stripe_customer&.delete unless stripe_customer.deleted?
|
||||
end
|
||||
|
||||
|
||||
@@ -17,11 +17,23 @@
|
||||
|
||||
module Stripe
|
||||
class CreditCardCloner
|
||||
def find_or_clone(credit_card, connected_account_id)
|
||||
if card = find_cloned_card(credit_card, connected_account_id)
|
||||
card
|
||||
def find_or_clone(card, connected_account_id)
|
||||
if cloned_card = find_cloned_card(card, connected_account_id)
|
||||
cloned_card
|
||||
else
|
||||
clone(credit_card, connected_account_id)
|
||||
clone(card, connected_account_id)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_clones(card)
|
||||
card.user.customers.each do |customer|
|
||||
next unless stripe_account = customer.enterprise.stripe_account&.stripe_user_id
|
||||
|
||||
customer_id, _payment_method_id = find_cloned_card(card, stripe_account)
|
||||
next unless customer_id
|
||||
|
||||
customer = Stripe::Customer.retrieve(customer_id, { stripe_account: stripe_account })
|
||||
customer&.delete unless customer.deleted?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user