Stripe: Preview upcoming invoice for updating subscription

Viewed 788

How to properly get upcoming invoice (bill size) which I am going to pay when upgrading/downgrading subscriptions ? So it will take into account applied coupons, current balance/credits (after downgrade) and etc.

Tried like this:

\Stripe\Invoice::upcoming([
    "customer" => $user->stripe_id,
    "subscription" => 'sub_XXXXXXXXXXX', // current user subscription (monthly)
    "subscription_prorate" => true,
    "subscription_items" => [
        ["plan" => "plan_XXXXXXXXXXX"] // plan for upgrade (annually)
    ]
]);

But I am getting "Stripe\Error\InvalidRequest: Currency and interval fields must match across all plans on this subscription. Found mismatch in interval field."
I understand that I'm getting that wrong, so please tell me how this should be done ?

1 Answers

I recently got a similar error using the .NET client, and am pretty sure the issue is the same. If you are updating a subscription's plans, they must all have the same currency and interval. For example, a subscription can't have one item on a monthly plan and another on a yearly plan. If you want to preview a switch between plans of a different interval, you must delete the old plan explicitly. My PHP is rusty, but I'm guessing something like this:

"subscription_items" => [
    ["id" => "currentPlanId", deleted => true]
    ["plan" => "plan_XXXXXXXXXXX"] // plan for upgrade (annually)
]

Looking at the Update Subscription form in the stripe dashboard helped me understand this better. A previous version of the API did not work this way, pretty sure.

Related