1
votes

I am using Stripe to create product subscriptions. The workflow is:

  • Create a customer and subscription (with a trial) when a new user signs up
  • The customer can enter card details anytime before the end of trial but will not be billed until the trial is over

When I do this in Stripe, I am finding two subscriptions on the customer.

The subscription is created with parameters:

 {customer: customer, 
  trial_period_days: 30, 
  proration_behavior: 'none', 
  items: [{price: ENV['STRIPE_SUBSCRIPTION_PRICE']}]}

When the customer wants to enter their card details, the checkout session is created with:

session = Stripe::Checkout::Session.create(
  customer: customer,
  payment_method_types: ['card'],
  mode: 'subscription',
  line_items: [
    {price: ENV['STRIPE_SUBSCRIPTION_PRICE'], quantity: 1},
  ],
  success_url: "#{domain}/subscription-success?session_id={CHECKOUT_SESSION_ID}",
  cancel_url: "#{domain}/subscription-cancel",
  )

In Stripe, you can see two subscriptions created for this customer (one with a trial and one without). An invoice is immediately raised for one of the subscriptions.

How can I create a Checkout Session that will keep the first subscription only and start billing at the end of the trial?

Many thanks

Nick

1

1 Answers

2
votes

If you're updating an existing subscription via Stripe Checkout, you need to use mode: 'setup' instead, and pass the subscription_id inside the setup intent's metadata.

https://stripe.com/docs/payments/checkout/subscriptions/update-payment-details

Alternative, consider implementing the customer billing portal instead:

https://stripe.com/docs/billing/subscriptions/customer-portal