Stripe - after changing plan, don't bill for the new subscription until current cycle ends - stripe-payments

I want to let user to change their subscription plan. However, they won't be refunded after switching. If i set the prorate to false, stripe will bill for the new subscription right away.
For example, if the user is subscribed to a yearly plan in Jun 2018, and wants to change to monthly in Oct 2018. They will be charged with monthly plan after Jun2019, as current cycle hasn't ended yet.
How can I do with stripe api when i am updating the current subscription?
in the stripe api docs (https://stripe.com/docs/api/subscriptions/update)
"if you set prorate to false when switching between different billing intervals (monthly to yearly, for example), we won't generate any credits for the old subscription's unused time—although we will still reset the billing date and will bill immediately for the new subscription."

In 2019 Stripe shipped support for Subscription Schedules which allow you to control multiple sequential phases on a Subscription. You can read more about this in the docs: https://stripe.com/docs/billing/subscriptions/subscription-schedules
With this API, you can now explicitly schedule a future change of a Subscription. The idea would be to use the Create SubscriptionSchedule API a schedule from your Subscription and plan a second phase to move the Subscription to the new price on the next billing cycle.
Past answer, which still work but less optimized:
One solution for this would be to follow those steps:
Mark the current subscription to cancel at the end of the current period so that you don't attempt to charge that customer again.
Create a new subscription to the monthly plan but put the customer on a trial period until the end of the current subscription (June 2019 in your example). This allows you to not charge him until the other subscription ends so that you switch the customer to the monthly plan as expected.

Related

Pausing and unpausing a payment collection on stripe

I'm working on stripe subscription and trying to build a flow using which admin can pause and unpause the payment collection of customers.
To achieve this I'm using this from stripe documentations.
Now the major issue which I'm facing with this method is.
Suppose a customer is on monthly subscription and is billed on 1st of every month.
Admin has paused the customer's billing on 15th October and Unpaused it on 15th November.
Now the upcoming invoice shows that customer will be billed on 1st December for the upcoming cycle.
My questions are:
Is there any way I can charge customer for the period of 16th-30th November which customer used.(Somehow adjusting amount on the 1st December invoice)
And the period of 16th-31st October, for which Customer has already paid on 1st October, can be uncharged/adjusted somehow.
Thanks
Instead of pausing, which does not take into account prorated amounts or credits, I recommend canceling the Subscription instead of pausing it. You can use the prorate parameter when canceling Subscriptions to issue a credit to the Customer for the unused time.
Later, when you want to resume payments, create a new Subscription for the Customer and specify a billing_cycle_anchor set to the first of the month. That will charge them for the partial month up front followed by full monthly Invoices starting on the first of every month.

How to reset monthly SaaS usage on an annual Stripe plan?

I am currently in the process of creating the billing system for my first SaaS. A simple tool to generate videos. There will be a free, mid, and pro tier. The main difference will be the number of minutes you can generate per month.
I created 3 Stripe products for the tiers. The free product consists of one price ($0) with a monthly charge interval. The mid and pro tier consists of 2 prices, a monthly and annual charge interval.
When a user signs up for an account, my backend automatically creates a Stripe customer and subscribe it to a free plan. A user can upgrade their account to a mid or pro tier. The plan will be downgraded to a free tier when the user cancels or if the payment failed.
I reset the number of available render minutes after each successful payment, at the start of the billing month. I do this by listening to the successful payment Stripe webhooks. Even when the user is on the free tier, the webhook still gets fired since it is a plan.
The problem is that this method would not work for annual plans.
Which made me think that the method that I went for may not be the correct one.
Do you know if this is a good method if there is a better one and if there is a workaround for annual subscriptions?
Thank you very much for your time.
I think for the annual billing you'll likely want to just set up a cron job or similar that runs daily, and that looks at which annual subscriptions' 'billing day anniversary' (i.e., billing date is Aug 7, so billing day anniversary is the 7th of each month) and resets the counts - unless it is the billing date, in which case leave it to your webhook.

Finishing trial early in Stripe

I have a thirty-day free trial of my subscription in Stripe.
I want users to have the option of paying early, at which point their remaining trial days will be added to the end of their first billing term.
If I set the subscription's trial_end and billing_cycle_anchor to the current timestamp, will the user be invoiced immediately? Or would it be best to cancel their existing subscription and create another without a trial?
Then, I guess, put the remaining trial days on to the newly created billing_cycle_anchor and prorate=false?
Thanks

Immediately charge for subscription changes

We are using Stripe payment processing for our customer's subscriptions. When users change plans, we want them to be charged immediately for the prorated difference. Stripe does this automatically when plans have different billing intervals but when changing between plans with the same interval, Stripe defers payment till the next billing period.
The way we handle this now is to create an invoice after updating the subscription, but if the billing fails for it fails, we need to do a rollback.
stripe.subscriptions.update(/* change plan */);
if (plans_have_different_billing_intervals) {
try {
stripe.invoices.create(/* for all pending charges */);
} catch (err) {
/* rollback subscription to old plan */
}
}
Overall, this feels wrong and convoluted. Is there an easier/cleaner way to implement this that we aren't seeing?
You can use billing_cycle_anchor set to now when updating a subscription to force it to change the billing cycle and thus always charge the customer immediately. Personally I think this makes a lot more sense. Also this works well with prorating.
await stripe.subscriptions.update(subscription.id, {
billing_cycle_anchor: 'now',
items: [{ id: itemId, plan: planId }]
});
https://stripe.com/docs/billing/subscriptions/billing-cycle#changing
To immediately charge your users the prorated price difference when the user upgrades, use the proration_behavior='always_invoice' option when modifying the user's subscription. Quoting from the docs:
... In order to always invoice immediately for prorations, pass always_invoice.
Python example:
stripe.Subscription.modify(
subscription_id,
items=[{
'id': item_id,
'plan': plan_id,
}],
# Charge the prorated amount immediately.
proration_behavior='always_invoice',
)
This immediately charges the user a prorated amount when the user changes to a more expensive plan. However, when the user changes to a cheaper plan, the user will be given a prorated credit, making the user's next bill cheaper by the prorated amount.
Scenarios
In these scenarios, suppose the billing date is on the first day of each month. Further suppose that the month has 30 days.
Scenario 1: The user is subscribed to a $5 monthly plan. The user decides to upgrade to a $30 plan on the 22nd day of the month. With 8 days left in the month, the unused portion of the $5 plan is approximately (8 / 30) * 5 = $1.33, and the prorated amount for the $30 plan is (8 / 30) * 30 = $8.00. So the user will be charged 8.00 - 1.33 = $6.67 immediately.
Scenario 2: The user is subscribed to a $30 monthly plan. The user decides to downgrade to a $5 plan on the 22nd day of the month. With 8 days left in the month, the unused portion of the $30 plan is approximately (8 / 30) * 30 = $8.00, and the prorated amount for the $5 plan is (8 / 30) * 5 = $1.33. In this case, the user will not be charged, but the user's next bill (on the next billing date) will be reduced by 8.00 - 1.33 = $6.67.
The example calculations above are only approximate because Stripe prorates to the exact second, not by day.
Side notes
dearsina's answer is correct, but involves at least three API calls rather than one. To explicitly follow the steps in that answer, you could do this instead:
# Step 1 in dearsina's answer: Modify the subscription.
modified_subscription = stripe.Subscription.modify(
subscription_id,
items=[{
'id': item_id,
'plan': plan_id,
}],
)
# Steps 2 and 3: Create and retrieve invoice.
invoice = stripe.Invoice.create(customer=modified_subscription.customer)
# Steps 4 and 5: Finalize and pay invoice.
stripe.Invoice.pay(invoice.id)
But why do this when you could do all the steps in one API call?
To take payment for a change of quantity or subscription plan, you need to do the following:
Update subscription with the new changes.
Create an invoice.
The thing that confused me by this is that Stripe magically knows to only invoice for the updated subscription items, and not for upcoming billing cycle items.
Retrieve the newly created invoice
Finalise the invoice
Take payment for the invoice This assumes that your customer has a payment method stored.
Only when all of the steps have been completed, you've successfully charged for the subscription change (and charged for the change only). You can do it all of it in one go. The customer should get an invoice email from Stripe at the end of it.
As OP says, it gets particularly complicated if the payment fails. The way I see it, you have three choices:
Ignore the failed payment, give the customer access to the service, and hope that they'll pay the next time payment is attempted.
Roll-back the subscription upgrade, warn the customer that payment failed.
Put the entire subscription on hold until the customer pays.
I'm only mentioning #3 because at times, the subscription upgrade process may be complicated. And the customer, having spent time upgrading their subscription, wouldn't want the work to be undone, for what could be a completely harmless reason (their credit card had expired for example).
It may be easier, from a development perspective, to mark a subscription as unpaid, than to roll back or to freeze (and then unfreeze) certain parts of the subscription. But you'll then run foul of barring the customer from a service that they have already paid for (their existing subscription) because they couldn't pay for the additional service.
You can use webhooks in Stripe. After creating an invoice, you can charge the invoice right away (invoice now). If the invoice payment fails, you can use a webhook to rollback to the old account.
Check this guide for more information about Stripe Subscriptions: https://www.truespotmedia.com/testing-webhooks-in-stripe-with-php/

Prorating/refunding the cost of a previous stripe plan when creating a new plan and subscribing user to it

I basically want to know whether Stripe is automaticall refunding customers a prorated amount.
My process for updating a customer to a new plan:
Delete the old plan.
Create the new plan.
Create the new subscription.
Update user to new subscription.
If you create a new subscription then cancel the old one, the customer will be billed for the new subscription but will not gain any credit or refund for the unused time on the old subscription.
If you update the existing subscription to switch from the old plan to the new one, then by default Stripe will compute the proration (you can disable this by setting prorate to false in the subscription update request).
If the proration ends in favor of the customer, they will be granted credit in the form of a negative account balance. Customers' account balances are applied to future invoices before trying to actually charge the customer. Stripe will not partially or totally refund any past charges.
You can read more about subscription updates and proration in this paragraph of the subscription integration guide.

Resources