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

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.

Related

Best way to handle monthly subscription allowance with Stripe?

What will be the best pratice to compute monthly allowance of our service when using a Stripe monthly subscription?
I can see 2 strategies:
Add usage to a monthly usage hash (ie. {month_1: 342, month_2: 20}). Calculate current month based on the Stripe subscription start date. Kind of ignore variance in Stripe subscription actual renewal dates, and require manual intervention to block a customer if renewal doesn't go through.
Have a monthy_allowance (credit counter still avaiable for the current month) variable that is replenish when Stripe fires the successful subscription renewal web hook. It's more tie to the actual subscription status, but I can see being an issue as it seems harder to test and subject to bugs if the web hook doesn't properly receive the event. Can be an issue if some customers got locked out until we manually allow them back in.
I suppose it doesn't really matter in this question, but we are using Ruby on Rails with MongoDB as backend.
If you're talking about having some kind of 'usage credit' that your users will 'use up', and that is replenished when a Subscription charge is made, I think you could likely handle this by just having a bucket (like, a counter) that you draw down when they use something, and you fill up when the Subscription is successfully paid, and where you block them (or provide a way to buy more) when the bucket hits zero.
Does that make sense?

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.

Braintree how do I change the subscription lifecycle period?

I am new to braintree and I am implementing a braintree payment gateway for my nodeJs app. I have few concerns when it come to application testing.
How can I change the period of one billing cycle. Currently its limited to minimum of 1 month. If it is not changeable what is the workaround for testing multiple billing cycle transactions ??
PS: I did refer to this how-can-i-change-subscription-period-on-braintree but a valid answer can not be found.
My next question is related to the webhooks in Braintree. When a webhook is triggered for successful charge for subscription it returns a Subscription object which a transaction array which includes all the transactions for that subscription. Is there a way to filter out the data for the transaction which the webhook was triggered for ? It says the array is sorted. Does that mean that 0th position of the transaction array is the last transaction made ??
Braintree Subscription object reference
Since the test environment does not let us change the billing cycle time I have to wait a month to test this. And if there is a better way to do handle this please advice me on it.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
It’s not possible to create a subscription billing period shorter than a month in sandbox or production. The previous answer linked in your question — creating a subscription with a 1-day trial period — is a good way to test subscription billing transactions.
The array of transactions inside a subscription object is sorted by creation date with most recent first, so the first transaction within a subscription returned in a webhook notification will be the transaction that triggered the webhook.
You can also take a look at our webhooks testing page for examples of how to generate sample webhook notifications.

Set end date when setting up Stripe subscription

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

Resources