How to use Python SDK stripe.Invoice.upcoming
Call to preview new invoices with different quantities and plans?
There is a reference in the Stripe Invoice documentation on how to pass values when retrieving upcoming invoices to simulate a what-if scenario
When fetching the preview, you can also model what the invoice would look like if you changed the subscription in one of these ways:
Swapping the underlying price.
Altering the quantity.
Applying a trial period.
Adding a coupon.
There is not enough information in the API or SDK change logs to determine how to replace the deprecated parameters we were using with new ones
Old:
return stripe.Invoice.upcoming(
customer=customer_id,
subscription=stripe_subscription_id,
subscription_quantity=quantity_to_calculate_with, # if None, defaults to current
subscription_proration_date=proration_date_as_unix_seconds,
subscription_plan=plan_to_calculate_with, # if None, defaults to current
)
Try new ones:
subscription_details = dict(
proration_date=proration_date_as_unix_seconds,
items=[
{
'quantity': quantity_to_calculate_with,
'plan': plan_to_calculate_with
}
])
return stripe.Invoice.upcoming(
customer=customer_id,
subscription=stripe_subscription_id,
subscription_details=subscription_details
)
When I try this I get an error saying “Must use one of price or Price_id” and in addition to not understanding how to convert between plans and pricing, I don’t get the same calculation as before.