ewang
ewang

Reputation: 506

Scheduling recurring payments with end date on stripe

I am trying to create a 6-week course, where the customer signs up for the course and then gets automatically charged for portion of the course fee each week.

I am able to create the 6-week subscription schedule but I am struggling to figure out how to get create a checkout session where the customer can put in their credit card information and start paying for this 6-week subscription.

I am creating the subscription schedule like this:

// First, I create a price object which returns to me a price object with id: price_IK...
const price = await stripe.prices.create({
  unit_amount: 100,
  currency: 'usd',
  recurring: {interval: 'week'},
  product: 'prod_LDD...',
});

// Then, I create a subscription schedule object which returns to make subscriptionSchedule object with id: sub_sched_1K...
const schedule = await stripe.subscriptionSchedules.create({
  start_date: 'now',
  end_behavior: 'release',
  phases: [
    {
      items: [{ price: 'price_1K...', quantity: 1 }],
      iterations: 6,
    },
  ],
});

Now, how do I display a create a checkout session with this subscription schedule to allow a customers to put in their credit card information and start paying for this subscription?

For recurring payments with no end date, I'm able to just set a subscription payment in the checkout session itself:

const session = await stripe.checkout.sessions.create({
  mode: 'subscription',
  line_items: [
    {
      price: price_1K...,
      quantity: 1,
    },
  ],
  success_url: 'https://example.com/success.html?session_id={CHECKOUT_SESSION_ID}',
  cancel_url: 'https://example.com/canceled.html',
});

I want to do something similar for recurring payments with an end date but don't seem to be able to.

Upvotes: 1

Views: 1820

Answers (1)

orakaro
orakaro

Reputation: 1991

You have 2 choices:

  1. Create a Checkout Session, mode = 'subscription' with a trial. When it's still in trial, create a Subscription Schedule to apply to that Subscription and modify the schedule as you want.
  2. Create a Checkout Session, mode = 'setup' to collect your customer payment info. Then later on create Subscription Schedule specifying that Customer Id

Upvotes: 2

Related Questions