Reputation: 5582
I'm developing a subscription payment system where users can upgrade from a monthly to an annual plan. The challenge I'm facing involves correctly calculating the order summary when a user decides to upgrade a few days after purchasing the monthly plan. I want to ensure the final amount accurately reflects the remaining days of the monthly plan and the full cost of the annual plan.
Example:-
Is there any option on stripe payment gateway, where I send some information and Stripe provide me all the full order summary, before the payment something like
Monthly Plan (Remaining Days): $xxx
Annual Plan (12 months): $xxx
Total Credit from Monthly: $xxx
Total Amount for Upgrade: $xxx
I appreciate any insights or code examples or reference links that could help me implement this upgrade logic effectively.
Thank you!
Upvotes: 0
Views: 205
Reputation: 1143
Stripe Subscription supports prorations. In your case, you can update the Subscription to the annual price and set proration to none.
Imagine you've created the monthly Subscription using the following request:
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [{
price: monthlyPrice,
}],
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
expand: ['latest_invoice.payment_intent'],
});
After a while(couple of days), you want to upgrade the customer to an annual Subscription without creating a proration for the current month and charge the full next year:
const subscription = await stripe.subscriptions.update(subscriptionId, {
items: [{
price: annualPrice,
}],
proration_behavior: 'none'
});
You can test this scenario using Stripe Test clock, where you can create a simulation and advance time.
Upvotes: 1