Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 284
Anthony Kong Avatar asked Jun 20 '17 11:06

Anthony Kong


2 Answers

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:

  1. Collect and tokenize the customer's payment information (using Elements or Checkout).

  2. Using the resulting token, create a customer object and save the resulting customer ID in your database.

  3. Create a one-off charge using the customer object for the first payment.

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

like image 169
Ywain Avatar answered Oct 07 '22 16:10

Ywain


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.

like image 1
Rory O'Connell Avatar answered Oct 07 '22 16:10

Rory O'Connell