Skip to content

Invoice: Add support for Create Preview Invoice API#249

Merged
bravier merged 1 commit intoadrienverge:masterfrom
bravier:add-invoices-create-preview
Sep 2, 2025
Merged

Invoice: Add support for Create Preview Invoice API#249
bravier merged 1 commit intoadrienverge:masterfrom
bravier:add-invoices-create-preview

Conversation

@bravier
Copy link
Collaborator

@bravier bravier commented Aug 29, 2025

The Upcoming Invoice API is deprecated and removed since API version 2025-03-31:
https://docs.stripe.com/changelog/basil/2025-03-31/invoice-preview-api-deprecations

The new Create Preview Invoice API is almost the same and only the parameters structure changed.

Reference: https://docs.stripe.com/api/invoices/create_preview

# Do not store this invoice
del store[cls.object + ':' + invoice.id]

invoice.id = f'upcoming_{invoice.id}'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Create Preview Invoice API adds an ID to the returned invoice whereas the Upcoming Invoice API didn't do that.

Copy link
Collaborator

@feliixx feliixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clean !

subscription_trial_end=trial_end)

# Do not store this invoice
del store[cls.object + ':' + invoice.id]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Stripe docs says that an upcoming invoice can be retrieved via the /v1/invoices/id for 72 hours (cf https://docs.stripe.com/invoicing/preview), so maybe it would make more sense to keep these upcoming invoice in the store ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks for pointing this out.

I was misguided by the API doc that says:

Note that when you are viewing an upcoming invoice, you are simply viewing a preview – the invoice has not yet been created. As such, the upcoming invoice will not show up in invoice listing calls, and you cannot use the API to pay or edit the invoice.

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

I don't want to implement such "temporary" store in localstripe that would complicate things.
Also, please note that the /v1/invoices/:id route is not supported in localstripe right now so storing the invoice would not be useful.

Maybe I can change the comment to says that real Stripe servers keep these invoices for a limited amount of time? What do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would work for me. I'm curious about what @feliixx thinks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to implement such "temporary" store in localstripe that would complicate things.

+1 not to implement a "temporary" store: we don't need to access the preview invoices via the /v1/invoices/:id route right now so it's not worth the extra complexity

Also, please note that the /v1/invoices/:id route is not supported in localstripe right now so storing the invoice would not be useful.

Ok interesting, I wasn't aware of that !

Maybe I can change the comment to says that real Stripe servers keep these invoices for a limited amount of time? What do you think?

Seems like the best solution 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment updated: diff

@bravier bravier force-pushed the add-invoices-create-preview branch from 590adb3 to 019a82f Compare September 1, 2025 09:20
Copy link
Owner

@adrienverge adrienverge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of that!

-d subscription_details[default_tax_rates][0]=$txr1 \
-d subscription_details[items][0][id]=si_RBrVStcKDimMnp \
-d subscription_details[items][0][plan]=basique-annuel \
-d subscription_details[proration_date]=1504182686
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read that this is an old timestamp (from 2017), so I guess that if it works today, it will keep working in a month or a year 👍

The Upcoming Invoice API is deprecated and removed since API version
2025-03-31:
https://docs.stripe.com/changelog/basil/2025-03-31/invoice-preview-api-deprecations

The new Create Preview Invoice API is almost the same and only the
parameters structure changed.

Reference: https://docs.stripe.com/api/invoices/create_preview
@bravier bravier force-pushed the add-invoices-create-preview branch from 019a82f to 9e0c094 Compare September 1, 2025 15:06
Copy link
Collaborator

@feliixx feliixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me, thanks 👍

@bravier
Copy link
Collaborator Author

bravier commented Sep 2, 2025

Thanks!
Let's merge and release a new version.

@bravier bravier merged commit b0bb83a into adrienverge:master Sep 2, 2025
6 checks passed
@bravier bravier deleted the add-invoices-create-preview branch September 2, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants