Getting price before Stripe Subscription creation

Viewed 506

I am trying to show the price of the invoice before creating the subscription.

Is this possible?

This is the call to create the subscription:

stripe.subscriptions.create({
  customer: 'cus_4fdAW5ftNQow1a',
  items: [
    {
      plan: 'plan_CBXbz9i7AIOTzr',
    },
  ],
  expand: ['latest_invoice.payment_intent'],
}, function(err, subscription) {
    // asynchronously called
  }
);

There is a section on previewing proration:

https://stripe.com/docs/billing/subscriptions/prorations#previewing-proration

However it requires a subscription to exist.

I can't find a way to see the cost at the time of subscription creation.

1 Answers

Stripe does support this, although it seems to be hidden way deep in API documentation. If you look at the upcoming invoices API, you'll see that you can calculate the price of an upcoming invoice, without having a subscription.

https://stripe.com/docs/api/invoices/upcoming

Just set the subscription_items plan value, and a quantity if your plan charges per unit. You can also set a default tax rate on the subscription as part of the invoice, or the plan line item if you want to also have stripe calculate tax for you.

Note: You will need a customer to apply this to, to have it calculate though.

Related