File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
app/api/billing/switch-plan Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ export async function POST(request: NextRequest) {
142142 quantity : currentQuantity ,
143143 } ,
144144 ] ,
145- proration_behavior : 'create_prorations ' ,
145+ proration_behavior : 'always_invoice ' ,
146146 } )
147147 }
148148
Original file line number Diff line number Diff line change @@ -469,6 +469,15 @@ export async function handleInvoicePaymentSucceeded(event: Stripe.Event) {
469469 return
470470 }
471471
472+ // Skip proration invoices (e.g. from mid-cycle plan upgrades) — only process cycle renewals
473+ if ( invoice . billing_reason && invoice . billing_reason !== 'subscription_cycle' ) {
474+ logger . info ( 'Skipping non-cycle invoice payment succeeded' , {
475+ invoiceId : invoice . id ,
476+ billingReason : invoice . billing_reason ,
477+ } )
478+ return
479+ }
480+
472481 const records = await db
473482 . select ( )
474483 . from ( subscriptionTable )
@@ -556,6 +565,20 @@ export async function handleInvoicePaymentFailed(event: Stripe.Event) {
556565 return
557566 }
558567
568+ // Skip proration invoices (e.g. from mid-cycle plan upgrades) — don't block users over proration failures.
569+ // Overage invoices (threshold + cycle-end) bypass this guard via !isOverageInvoice and still block.
570+ if (
571+ ! isOverageInvoice &&
572+ invoice . billing_reason &&
573+ invoice . billing_reason !== 'subscription_cycle'
574+ ) {
575+ logger . info ( 'Skipping non-cycle invoice payment failure' , {
576+ invoiceId : invoice . id ,
577+ billingReason : invoice . billing_reason ,
578+ } )
579+ return
580+ }
581+
559582 // Extract and validate customer ID
560583 const customerId = invoice . customer
561584 if ( ! customerId || typeof customerId !== 'string' ) {
You can’t perform that action at this time.
0 commit comments