From fbec6ab1236c26ff7e94593e2ba297764ea8fd10 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Sat, 10 May 2025 01:09:07 +0530 Subject: [PATCH] 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. --- corporate/lib/stripe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 27d9dd4984..174e0a1937 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -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)