2

I'd like to show a customer a preview (or a quote) of what their subscription charges will be if they make changes to their subscription. For this, I'm using the "upcoming invoice" API endpoint:

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

From that link, they state that "You can preview the effects of updating a subscription, including a preview of what proration will take place.".

When changing plans, you have to first fetch the current subscription item ID (https://stripe.com/docs/api/subscription_items), and specify "deleted" => true. Then you add the new plan as a subscription_item.

Here's an example call:

[
  "subscription" => "sub_GUw5iYoBYiSAEl"
  "subscription_items" => [
    [
      "id" => "si_GUw53rbtqOpZYB"
      "deleted" => true
    ],
    [
      "plan" => "plan_GAf8EkL1VIPYZ9"
      "quantity" => "1"
    ]
  ]
]

This works great when the user is not in their trial period.

However, if the user is in their trial period, this only works if the billing interval of the plan you are changing to is the same. E.g. if you are on a monthly plan, changing to another monthly plan works.

If you are in your trial period on a monthly plan, and you are changing to a yearly plan (or vice versa), then it shows the upcoming invoice as $0.00 due today.

This also happens via the Stripe Dashboard:

Stripe Upcoming Invoice

Is there a way to show the actual amount, not $0.00?

karel
  • 468
  • 5
  • 14
  • 2
    You likely want to pass [subscription_trial_end](https://stripe.com/docs/api/invoices/upcoming#upcoming_invoice-subscription_trial_end) to see what it would look like if the trial ended immediately. – taintedzodiac Jan 07 '20 at 14:33
  • @taintedzodiac thanks, that's actually a useful workaround. I won't be able to display the invoice date (I'd have to keep track of the trial end date and use that), but at least the amount would be correct. If you add it as an answer I'll mark it as accepted. – karel Jan 08 '20 at 07:49
  • Glad that helped! Added as an answer. – taintedzodiac Jan 08 '20 at 16:05

1 Answers1

1

You can pass subscription_trial_end to see what it would look like if the trial ended immediately.

taintedzodiac
  • 2,658
  • 1
  • 18
  • 16
  • This helps! One obnoxious behavior is if you use the current timestamp, you'll need to take into account clock skew as you still might get $0 back if your computer is slightly fast since the last NTP run. If you go too far back, and the customer recently updated the subscription, you'll get an error with it not being in the current invoice period. I threw up my hands and asked for the current timestamp less 3 seconds. – Nicholas Piasecki Feb 25 '21 at 14:54