From 82e5977e15b77f3b51fe02f4100326e805a198c7 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 24 Mar 2024 12:59:38 +0000 Subject: [PATCH] Add proration behavior for metered plans and subscription changes --- CommonServer/Services/BillingService.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CommonServer/Services/BillingService.ts b/CommonServer/Services/BillingService.ts index 69b2292f33..8d3b77801b 100644 --- a/CommonServer/Services/BillingService.ts +++ b/CommonServer/Services/BillingService.ts @@ -115,6 +115,8 @@ export class BillingService extends BaseService { const meteredPlanSubscriptionParams: Stripe.SubscriptionCreateParams = { customer: data.customerId, + proration_behavior: 'always_invoice', + items: data.serverMeteredPlans.map((item: ServerMeteredPlan) => { return { price: item.getPriceId(), @@ -227,6 +229,8 @@ export class BillingService extends BaseService { }, ], + proration_behavior: 'always_invoice', + trial_end: trialDate && data.plan.getTrialPeriod() > 0 ? OneUptimeDate.toUnixTimestamp(trialDate) @@ -298,9 +302,9 @@ export class BillingService extends BaseService { quantity: quantity, }); - // add billing anchor, so that the billing cycle starts now. New quantity will be charged from now. + // add billing anchor, so that the billing cycle starts now. New quantity will be charged from now. https://stackoverflow.com/questions/44417047/immediately-charge-for-subscription-changes await this.stripe.subscriptions.update(subscriptionId, { - billing_cycle_anchor: 'now', + proration_behavior: 'always_invoice' }); }