Add proration behavior for metered plans and subscription changes

This commit is contained in:
Simon Larsen 2024-03-24 12:59:38 +00:00
parent 53481a58eb
commit 82e5977e15
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE

View File

@ -115,6 +115,8 @@ export class BillingService extends BaseService {
const meteredPlanSubscriptionParams: Stripe.SubscriptionCreateParams = { const meteredPlanSubscriptionParams: Stripe.SubscriptionCreateParams = {
customer: data.customerId, customer: data.customerId,
proration_behavior: 'always_invoice',
items: data.serverMeteredPlans.map((item: ServerMeteredPlan) => { items: data.serverMeteredPlans.map((item: ServerMeteredPlan) => {
return { return {
price: item.getPriceId(), price: item.getPriceId(),
@ -227,6 +229,8 @@ export class BillingService extends BaseService {
}, },
], ],
proration_behavior: 'always_invoice',
trial_end: trial_end:
trialDate && data.plan.getTrialPeriod() > 0 trialDate && data.plan.getTrialPeriod() > 0
? OneUptimeDate.toUnixTimestamp(trialDate) ? OneUptimeDate.toUnixTimestamp(trialDate)
@ -298,9 +302,9 @@ export class BillingService extends BaseService {
quantity: quantity, 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, { await this.stripe.subscriptions.update(subscriptionId, {
billing_cycle_anchor: 'now', proration_behavior: 'always_invoice'
}); });
} }