Fix checkout Stripe: ricrea customer se ID test su ambiente live.

Evita errore «No such customer» dopo passaggio da sk_test a sk_live.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-02 19:11:42 +02:00
parent 2b8f842752
commit 1a84d6ae42
3 changed files with 90 additions and 15 deletions

View File

@@ -16,7 +16,7 @@ module Billing
price_id = PriceCatalog.price_id(plan_slug: @plan_slug, interval: @interval)
customer_id = ensure_customer_id!
customer_id = EnsureCustomer.call(club: @club, user: @user)
CustomerSync.call(club: @club, customer_id: customer_id)
session = ::Stripe::Checkout::Session.create(
@@ -48,7 +48,7 @@ module Billing
def portal_url
raise "Stripe non configurato" unless MatchLiveTv.stripe_enabled?
customer_id = ensure_customer_id!
customer_id = EnsureCustomer.call(club: @club, user: @user)
CustomerSync.call(club: @club, customer_id: customer_id)
session = ::Stripe::BillingPortal::Session.create(
customer: customer_id,
@@ -59,19 +59,6 @@ module Billing
private
def ensure_customer_id!
sub = @club.subscription || @club.build_subscription(plan: Plan["free"], status: "active")
return sub.stripe_customer_id if sub.stripe_customer_id.present?
customer = ::Stripe::Customer.create(
email: @user.email,
name: @club.billing_legal_name.presence || @club.name,
metadata: { club_id: @club.id }
)
sub.update!(stripe_customer_id: customer.id)
customer.id
end
def success_url
"#{billing_url}?checkout=success&session_id={CHECKOUT_SESSION_ID}"
end