From a6fcbf58e418c5615fcbd5cd52464cb0b76f215a Mon Sep 17 00:00:00 2001 From: Etienne <45695613+etiennejouan@users.noreply.github.com> Date: Thu, 11 Jun 2026 14:45:01 +0200 Subject: [PATCH] fix(billing) - enable upgrade if invoice already paid (#21450) Had an issue concerning a user with credits, then invoice automatically paid. Upgrade failed --- .../stripe/services/stripe-invoice.service.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-invoice.service.ts b/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-invoice.service.ts index f91b4807ac..76c29d4308 100644 --- a/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-invoice.service.ts +++ b/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-invoice.service.ts @@ -68,9 +68,22 @@ export class StripeInvoiceService { }); await this.stripe.invoices.finalizeInvoice(invoice.id, { - auto_advance: false, + auto_advance: true, }); - await this.stripe.invoices.pay(invoice.id); + try { + await this.stripe.invoices.pay(invoice.id); + } catch (error) { + // With auto_advance Stripe may already have collected payment by the time + // we explicitly request it. Only swallow that case, rethrow real failures. + if ( + !( + error instanceof this.stripe.errors.StripeInvalidRequestError && + error.code === 'invoice_already_paid' + ) + ) { + throw error; + } + } } }