stripe: Only attempt payment if invoice is not paid.

Since it is possible that invoice can be paid before we reach here,
so only attempt payment if the invoice is not marked as 'paid'.

Fixes invoice already paid error from stripe when running tests.
This commit is contained in:
Aman Agrawal
2025-05-10 01:09:07 +05:30
committed by Tim Abbott
parent abdad3d485
commit fbec6ab123

View File

@@ -1189,8 +1189,8 @@ class BillingSession(ABC):
is_created_for_free_trial_upgrade=current_plan_id is not None and on_free_trial,
)
if charge_automatically:
# Stripe takes its sweet hour to charge customers after creating an invoice.
if stripe_invoice.status != "paid" and charge_automatically:
# Stripe can take its sweet hour to charge customers after creating an invoice.
# Since we want to charge customers immediately, we charge them manually.
# Then poll for the status of the invoice to see if the payment succeeded.
stripe_invoice = stripe.Invoice.pay(stripe_invoice.id)