Set end date when setting up Stripe subscription - stripe-payments

In my application users are subscribed (and billed) each month for 24 months. Is there any way to have Stripe automatically end the subscription after the 24th month when I initially create the subscription?

What you describe is possible in Stripe, but not as an out-of-the-box solution (as of August 2014). You'll need a little bit of programming logic on your end, too.
First, you'll need to have a web hooks endpoint:
https://stripe.com/docs/webhooks
Next, you'll want to subscribe the customer to a plan like normal. We'll notify your site, via the web hooks, of when payments are made on a recurring subscription. Specifically, you'll want to watch for invoice.payment_succeeded events:
https://stripe.com/docs/api#event_types
Once a specific customer has hit the right number of payments (which you'll track on your end), you'd then issue a cancel subscription request:
https://stripe.com/docs/api#cancel_subscription
Hope that helps!
Larry
PS I work on Support at Stripe.

2020 Update
It is possible by setting up "cancel_at" date when creating subscription. More info Create a subscription with Stripe

Ya it can be done simply by passing "cancel_at_period_end" is true while creating subscription . Then subscription will automatically get cancelled on subscription end date

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".

How to set Stripe's subscription billing cycle to month end programmatically?

As title, I am using Django's djstripe library, but I cannot find a way to make subscription to be charged month-end easily.
By default, if I issue
subscription = customer.subscribe(
plan_stripe_id,
charge_immediately=False,
quantity=quantity)
The subscription billing cycle would start at the time the code executes. I want the subscription to charge at month end.
Is it a limitation of djstripe and I need to use other stripe python library like stripe-python?
Yep, that's not implemented yet. Tracking here. Pull requests are welcomed.

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.

Can you set a l limited time period for a Stripe plan?

We are writing a Saas application that users will only use for 10 months. Is there a way to define in the payplan API to limit the number of payments to take from the customer?
I have spent some time looking over the API but I just can't see it. Perhaps I'm just overlooking it.
Stripe's subscriptions will always charge indefinitely by default so you'd need some custom development to cancel the subscription after a certain number of payments. The solution would be to use webhooks to be notified about events that happen in your Stripe account.
If you listen for the invoice.payment_succeeded event you can count how many times your customer has paid and then cancel the subscription when you want to stop the payments.
Now we can use a subscription schedule and set the phases.iterations
property: https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-phases-iterations
And set the end_behavior to "cancel"
Here's the full guide: https://stripe.com/docs/billing/subscriptions/subscription-schedules

Stripe: How can I create a non-renewable subscription plan?

We would like to have a yearly plan for our service, but legally we cannot automatically-renew our customer's yearly plan. We need to communicate with our customers in a timely manner within the weeks leading up to the end of their yearly plan so that they will manually purchase another year. (this is a legal thing). So we need some method of setting up a Stripe subscription plan that will either not auto-renew, or that we can cancel via API when we're informed via a webhook that their subscription's year is about to end.
Has anyone had any luck with any creative ways of setting up a non-renewable yearly subscription plan with Stripe? Trying to avoid needing to setup a cron job that hits Stripe everyday to find subscriptions that need to be cancelled.
After contacting Stripe support, there's not an "official" way to do so.
One thought I had was to setup a custom subscription plan of 10 days with a 355 day trial period. That way I could set a webhook to trigger based on the customer.subscription.trial_will_end event.
I'm doing this with the node.js Stripe module.
Well, you could set up a $0.00 subscription, and then a listener for invoice.created webhook, and use that to trigger a flow where you inform the user that their invoice is due, and direct them to a page where they can 'approve' the payment. When they approve it, you could then just create a good old fashioned Charge to collect the money.
Basically, use Stripe as your cron job, and do the actual Charge creation separately.

Resources