Search code examples
stripe-paymentsstripe-tax

Getting the next invoice of a subscription on trial, not using invoice and without any payment methods


I'm using Stripe to manage payment at work.

I need to show my users a list of prices, but it's not really the price before tax that I'm after. It's the price after tax and using a coupon if any.

So this looks like the ideal use case for the get upcoming invoice endpoint. Except that with the following conditions, it doesn't work:

  • Subscription is trialing
  • The subscription is set to pay now (not the invoice option)
  • The customer currently has no payment methods at all In this case, I get an error saying
The subscription will pause at the end of the trial instead of generating an invoice because the customer has not provided a payment method and trial_settings[end_behavior][missing_payment_method] is set to `pause`.; code: invoice_upcoming_none;

No matter what state my user is in currently, I want to be able to show the price after tax, including the coupon if any.

I have been talking to someone of the Stripe team on Discord here and I have asked why it's possible from the customer portal:

enter image description here

But not in my case and the answer is unfortunately that apparently it's not part of their public API...

Am I really the first one to need this? As anyone found a workaround?

The only workaround that the person on Discord is offering is to modify the subscription and mark it to use and invoice, make the call to the upcoming invoice, then migrate back to not use an invoice by updating the subscription again.

This really feels like a terrible idea to update the subscription twice like this, especially for a readonly (GET) endpoint on my side...

I feel stuck and have no idea how to achieve what looks like a basic use case. Any help welcome!


Solution

  • I have been talking to a colleague about this and he just wouldn't accept the fact that Stripe wouldn't support that. So we talked and try different things for 2 hours and half and he eventually found the solution for this!

    Make a GET call on https://api.stripe.com/v1/invoices/upcoming with the following params:

    • subscription_details[items][0][price]: price ID
    • customer: customer ID
    • automatic_tax[enabled]: true
    • discounts[0][coupon]: (optional) the coupon ID

    And this gives me the total price, with taxes and coupon included even if the user is trialing, with charge automatically and no payment method attached!

    No need to update the subscription to pay by invoice, make the query and switch back to charge automatically.