Stripe: Plan change after period ends - stripe-payments

I have several customers subscribed to many other several Stripe plans on my website: These plans are all 'yearly' and have different subscribing amounts. Notice that I also have customers with a subscription status "active" and many others with "trialing".
Now, I need to automatically change their subscription plans to an unique new yearly plan, with a different subscription amount, at the end of their respective billing cycles.
I was looking for the properly event in order to do the change of plan programmatically within a webhook, but I don't know which to choose having both 'active' and 'trialing' subscriptions.
Any ideas?

I think invoice.upcoming the event will work for both trailing and active. subscription.
you can configure invoice.upcoming webhook to arrive 1 day before and modify customer's subscription and invoice.
invoice.upcoming : Occurs X number of days before a subscription is
scheduled to create an invoice that is charged automatically, where X
is determined by your subscriptions settings. Note the received
invoice object will not have an invoice ID.
Hope this helps you

Related

How to identify Stripe customers who started a payment subscription after trial ends

Is there an specific API endpoint or events that triggers when for example a customer is in a trial period and ended paying the first subscription invoice?
In short, I would like to track customers who paid the first subscription after a trial ends.
I'm thinking to do this processing on my end where I would listen to customer.subscription.trial_will_end webhook event and mark them on a table and once a invoice.payment_succeeded event happens I can check the same table who came from a trial. But if there's any recommended way to do this from the API alone it would be great.
Thanks in advance.
I would just listen to invoice.payment_succeeded and check two things :
the billing_reason is subscription_update (in order to filter out invoices from creating a subscription for example) https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
retrieve the related subscription object(invoice.subscription) and check that trial_end == current_period_start https://stripe.com/docs/api/subscriptions/object#subscription_object-current_period_start + https://stripe.com/docs/api/subscriptions/object#subscription_object-trial_end
When a trial ends it starts a new billing cycle, and trial_end is the time that most recent trial ended so this should always hold when you're looking at an event like this.
There is a stripe event that you can listen to in your webhook: customer.subscription.updated.
You can use the subscription status field. When the customer pays for the first time the status changes from "trialing" to "active".

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.

can i create a sku object into a service type product?

suppose i have a membership service which cost $10/month in a subscription way
but some users can not have a reusable source to make a subscription via plan api ,alternatively i will let him to do an one-time payment via order api.(at least accept one month's money)
it is the same product,same amount,difference is one is for plan,another is for order,so question is, should i create two products one is goods type(for order),one is service(for plan/subscription). or one service type product is enough?
As a concept in the Stripe Dashboard, product SKUs are only used for recurring plans or invoicing. Any one time purchase can just be a charge, and does not need to be associated with any "Product" within your Stripe configuration.
If the product in this case is literally just one month of the plan, then you should probably use the same Product you have specified.
If the payment method will only work once, you could do nothing, and when the first period is up, and Stripe tries to renew, the payment will fail and the subscription will be canceled.
Or, if you're positive beforehand that it should only be charged once, you could cancel the subscription right after the first payment is completed. The customer would still have an active subscription for the period they paid for, but Stripe would not try to charge them automatically when that first period expired.

Handling a 2-year subscription in Stripe

I need to be able to handle two types of subscriptions that Stripe doesn't seem to support out of the box:
A lifetime subscription
A two-year subscription
Lifetime subscription is easy. I'll just create a single charge and be done with it. It would've been nice to have a subscription record that I could check for validity.
Two-year subscription is where I am not sure what to do. I figure I'd create a one year subscription (current max in Stripe) and will have to use web hooks for when a new invoice will be generated. What would be the proper way of cancelling an upcoming charge? I am also worried that customers will receive an email alerting them for an upcoming charge in the middle of the period. Any way to avoid this?
Thanks in advance!
Stripe's subscriptions do not have a set end date. The 1 year maximum that you mention is the maximum interval, i.e. the frequency at which the customer will be billed.
If you want to end a subscription after a set number of payments, your best bet is to use webhooks to count the number of successful payments (via the invoice.payment_succeeded events) and cancel the subscription when the desired number of payments has been reached.
Stripe does not send emails to customers about upcoming charges. It can optionally send email receipts after a charge is created, but you can disable this from your dashboard.

How to start a subscription in stripe with delay?

I have a number of users who are currently subscribers to a monthly subscription.
For business reason, I want to be able to
1) Charge the customer when he decides to subscribe to our plan
2) Let the subscription become effective a number of days after the purchase
Currently a charge is immediately attempted when a subscription is added to a customer in stripe.
I want to stick to the stripe subscription because a) I still want to have stripe to manage subscription for me in future dates, and b) I have written a lot of code for the subscription model.
Is it feasible at all to demarcate the charge/invoice and the subscription start date?
You can control the time when the subscription actually starts (i.e. when Stripe will start billing the customer) by using the trial_end parameter in your subscription creation request. Simply set the value of the parameter to the timestamp of the exact time you wish Stripe to start automatically billing the customer.
If I understand your desired payment flow correctly, you'd want to do something like this when a customer signs up:
Collect and tokenize the customer's payment information (using Elements or Checkout).
Using the resulting token, create a customer object and save the resulting customer ID in your database.
Create a one-off charge using the customer object for the first payment.
Create a subscription using the customer object and the trial_end parameter set to the time you want Stripe to start automatically billing the customer.
See https://stripe.com/docs/subscriptions/trials for more information about using trial periods.
This is possible now through Stripe Subscription Schedules. With that, you can create a one phase schedule that starts in the future. By default, this will start the subscription on the date you want, automatically renew, and charge the customer on the start date. Also by default, it will immediately perform a transaction to pay for the subscription.
I found the required iterations to be a bit confusing. Essentially that is a multiplier against how many times the original price's interval repeats before moving on.
If all you want to do is start a subscription price in the future, use the Subscription Schedule API call. Create an items array of 1. Set the price_id of the price, the iterations on that item, and the start_date to the unix timestamp you want to start the subscription.
Stripe has different use cases for subscription schedules. The first one they list is exactly this purpose, starting and charging a subscription on a future date. Look through them if you want to adjust some more, like making the first phase a trial period instead.

Resources