Stripe Invoice.Upcoming changes: switching from Plan to Price
December 16, 2024

Stripe Invoice.Upcoming changes: switching from Plan to Price

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.
Enter full screen mode

Exit full screen mode

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  
    )
Enter full screen mode

Exit full screen mode

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
)

Enter full screen mode

Exit full screen mode

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.

2024-12-16 22:22:59

Leave a Reply

Your email address will not be published. Required fields are marked *