Finishing trial early in Stripe - stripe-payments

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

Related

How to give discount on new Stripe subscription?

We have a free subscription concept separate from Stripe. When a user signs up for a paid subscription we want to charge them immediately but still honor any remaining free-period.
I know I can use trial period to delay the start of the Stripe subscription, but we wanted to charge immediately to confirm valid credit card details. Is it possible to give a discount on a new subscription instead, to account for the users remaining free-time?
For example, if
today is the 1st
user has free subscription until 15th
monthly subscription is $10
I would like to charge them $5 today and immediately begin their subscription in Stripe with a Stripe renewal on the next 1st.
Easiest way to do this is to add an invoice item for the amount you want to charge and set a trial period until you want the renewing charge to occur (so in your example you set a trial_end for the next 1st of month). This will generate an initial invoice with the invoice item and then set your recurring payment as you desire.

Change Stripe Subscription Price at end of current period

I have a subscription setup for a user that has subscribed to the "pro" plan at $5 per month.
Halfway through the period, they decide they want to downgrade to the "basic" plan at $1 per month.
Current behavior immediately changes the subscription.
Does stripe have the functionality that would allow the actual change of plan to occur when the next billing cycle begins?
This would be similar to the cancel at billing period end when a subscription is cancelled.
From what I can tell, my application might have to handle this logic and make a no proration change close to but not after the billing period change.
You can update the subscription and set proration_behavior to none. This should keep the same billing cycle and charge the customer $1/month at the start of the next cycle: https://stripe.com/docs/api/subscriptions/update
You could also use Subscription Schedules, though that might be more useful if you had a few different phases to account for instead of a one-off update like this one: https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#downgrading-subscriptions

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

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.

Resuming a subscription with Stripe (and charging for previously unpaid service)

I have a web service which publishes and hosts certain information for my users. Each user's editing interface is separate from the information they've published. I'm billing for it using Stripe subscriptions, but I'm having trouble coming up with a workable way of handling unpaid subscriptions. Here's the logic I want to implement:
Upon the first failed billing attempt, my app should lock down the user's editing interface; instead, it should present them with a page with options for resolving their payment problem. However, information they've published will still be published, so a late payment doesn't interrupt things for their visitors.
Upon the last failed billing attempt, 15 days later, my app should remove information they've published as well. At this point, the user's editing interface is replaced with one that allows them to either re-activate their account with a new credit card, or completely delete the account.
If the user chooses to re-activate the account, they should not get a trial period
If the user re-activates, they should also have to pay for the 15 days they previously skipped out on, either by having their first billing period shortened by 15 days or by having a charge equal to 15 days' service added to their first bill.
#1 and #2 are very easy to implement if I watch for the right webhooks—just redirect requests for a delinquent customer, or a customer with a deleted or unpaid subscription, to a "fix this problem" page. #3 is pretty easy too—just create the subscription with trial_end set to now.
It's #4 that's tricky. How do I determine exactly how long the user's last invoice went unpaid before their subscription was canceled? How do I shorten the first billing period of the new subscription? Alternately, how do I pro-rate the customer's last invoice total to represent the portion that I actually provided to them, so I can add that amount to the new invoice? (I know I can create an Invoice Item to charge for the amount before I start the new subscription, so at least that's a possibility.)
Finally, does Stripe's "Mark Subscription Unpaid" option help with any of this? It looks like it keeps creating invoices but doesn't try to charge for them; I don't think that's what I want here.
You can definitely do all of that with Stripe's subscriptions. As you mentioned, the first two questions should be solved with webhooks. You would listen for invoice.payment_failedon your end to detect when a payment fails and immediately block you UI asking your customer to update their card details.
To update their card details you can use Stripe Checkout and just not set the data-amount parameter so that it doesn't display a price to your customer. Here is an example for this:
<form action="/charge" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_XXXX"
data-image="/square-image.png"
data-name="Demo Site"
data-description="Update Card Details"
data-panel-label="Update Card Details"
data-label="Update Card Details">
</script>
</form>
Each time your customer tries to update his card, you would use the Update Customer API and pass the new card token in the card parameter. This will delete the default card on the customer and replace it with the new one. It will also try and pay the latest invoice of each subscription in the "Past Due" state. In your case it means that the latest invoice still in retry mode will be attempted to be paid. This does not count as a retry and can be seen as independent. If it succeeds, you just reenable the UI otherwise you continue asking the customer to update his card details.
When you reach the fourth failed payment you will get a customer.subscription.canceled if that's what you set up in your retry settings in the dashboard. You can detect that it's an automatic cancelation by checking the request key on the event and making sure it's null. In that case you block the UI/account completely for your customer.
For the last 15 days, if I understood your flow correctly, the customer hasn't really been able to use your application since you locked down the UI partially. But if you still want him to pay for that amount, you should store in your database that the customer owes you $X for the 15 days he couldn't use the subscription.
Later on, your customer finally comes back and want to reenable his account. At that point you inform him that the payment flow will restart from today and that you will charge him for the extra 15 days he missed before. To do that, I would use Invoice Items which will allow you to add an extra amount to the first invoice automatically. You would follow those steps:
Create the invoice item for $X for your customer.
Create a new subscription to your plan setting trial_end to "now" in case you have a trial period set by default on your plan.
This will automatically create the first invoice for the plan amount and add the invoice item created before.
Another solution here would be to reopen their latest closed invoice that wasn't paid and use the Pay Invoice API. When this happens you know your customer paid you for a full month now instead of just the 15 days he owed you. In that case you would create a new subscription and set a trial period of 15 days so that he starts paying again after that trial.
I wouldn't use the "Mark as unpaid" option here because you completely lock the customer out of your application. This feature for me is to be used when you let your customer use your application and plan to charge him in a few months for each of the invoices. This would be used for an electricity provider for example who would keep your electricity on for multiple billing cycles and continue to try charging you for each invoice.
The amount your customer really owes you in that case is dependent on the number of retries you allow and the days between each retry. What you can do here is use the created value on the invoice and compare it to the current time when you get the customer.subscription.canceled to determine how much time passed and calculate the proration of how much your customer owes you at that point.

How to make a Stripe subscription status go from trialing to cancelled if there is no card?

We let our customers do a 30 day free trial using Stripe subscriptions. We want the trial period to last exactly 30 days. If the subscription status is trialing, active or past_due then the customer can use our service.
If the customer has moved out of the trial period and has been paying and for some reason their card is no longer good then the subscription status goes from active to past_due. And the subscription status is past_due for 15 days (dictated by our retry settings). In other words, if they have been a paying customer and their card is not good when their monthly payment is due, then they can still use our service for an additional 15 days while they fix their card.
If the 30 day trial period ends and there is no card then the status moves from trialing to active. And then 3 minutes later the status goes from active to past_due. And then the status stays past_due for 15 days - essentially making the trial period 45 days. We don't want that; we want the trial period to only be 30 days.
How do we not allow those 15 extra days?
I would think that there would be a setting to make the subscription status go from trialing to cancelled in this situation so that it is easy to set the trial period length given the way we have it setup above. But this setting does not appear to exist.
So do I need to manually cancel the subscription when I detect(via webhook) the trialing to active, and then 3 minutes later active to past_due? I would store the datetime in my database when it goes from trialing to active. And then when it goes from active to past_due, I would check to see if that stored datatime was say less than 15 minutes ago - and if it is then I know I have a trial period that ended without a card and I cancel the subscription. Or is there a simpler way to do it?
I was researching this myself. Turns out you can just set the cancel_at on creating a subscription using the same timestamp as your trial_end. When you receive a validated Payment Method from the user, you can remove the cancel_at timestamp by setting it to null so the subscription continues. Then just check if payments succeed and handle that properly.
So, if a user does not give you a Payment Method before the trial ends, then the subscription will get canceled at the cancel_at timestamp.
The first solution would be to change the way you want failed payments for subscriptions to be handled. By default, when an invoice payment fails it is automatically retried after 3 days, then 5 days, then 7 days and then gets ultimately cancelled. You can definitely decide that the subscription needs to be cancelled after the first failed payment by changing the settings in your dashboard.
The second solution is to catch the invoice.payment_failed in the webhook and immediately cancel the subscription on your end.
EDIT: Even if the customer does not have any active card associated and is now out of the trial period it should definitely be raised:
Occurs whenever an invoice attempts to be paid, and the payment fails. This can occur either due to a declined payment, or because the customer has no active card. A particular case of note is that if a customer with no active card reaches the end of its free trial, an invoice.payment_failed notification will occur.
EDIT 2: If you want to know whether the trial just ended the easiest solution would be to save this on your end. You could just store when the customer subscribes to a plan and then detect whether this is the end of the trial based on the date when the invoice.payment_failed is received.
The simplest way I can think of is to add a boolean has_paid attribute to your user model, which is only set to true when you receive an invoice.payment_succeeded webhook for an invoice whose total is greater than 0. (When a trial begins, Stripe creates a $0 invoice for the trial period, which is always paid successfully, so you have to ignore that invoice.) Then your invoice.payment_failed webhook can cancel the subscription immediately if has_paid is false, or let the automatic retry cycle continue if has_paid is true.

Resources