#rene_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1492080409087840266
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
๐ happy to help
normally if you use the same parameters the invoice preview should generate the same amount_due as its counterpart
Here's our exact flow:
- Call invoices/upcoming with subscription_items, proration_date, proration_behavior, billing_cycle_anchor, discounts โ returns amount_due
- Create a standalone PaymentIntent with that exact amount_due. Customer pays via Klarna.
- On payment_intent.succeeded webhook, call subscriptions/update with the exact same parameters stored in PI metadata. This creates an invoice.
- Call attach_payment to link the PI to that invoice. It works most of the time, but occasionally the invoice from step 3 has amount_due 1 cent less than what invoices/upcoming returned in step 1. The attach_payment then fails with amount_too_large.
In the Stripe Dashboard under Transactions I can see the PaymentIntent with amount 1448.27 but the invoice shows 1448.26.
the amount due is 1,488.26 whereas the PI is 1,488.27
Yes, exactly. That's the issue. The PI was created with the amount from invoices/upcoming (1,488.27) but when we later called subscriptions/update with the same parameters, the invoice was created with 1,488.26. So
attach_payment fails because the PI amount is larger than the invoice amount. Why is there a 1 cent difference if the parameters are identical?
would you mind sharing the request ID where you do the preview?
I think you're best approach here is to upgrade to newer API version (minimum 2025-06-30.basil https://docs.stripe.com/changelog/basil/2025-06-30/billing-mode#whats-new) to get access to billing_mode: "flexible", this guarantees a more accurate calculation and instead of using the upcoming invoice API, you would use the https://docs.stripe.com/api/invoices/create_preview)
Thanks for the suggestion!
Can you explain what causes the 1-cent discrepancy between invoices/upcoming and the actual invoice when all parameters are identical? Is this a known rounding issue with proration calculations?
๐ Hi there! I'm taking over for my colleague. Let me take a look
would you mind sharing the request ID where you do the preview?
Do you have an example of this, and the invoice update? Are they using the same proration timestamp, for example?
We don't have the exact request ID for the preview call, but the parameters sent are identical โ they come from the same UpgradeConfig object in our code. The preview call uses:
subscription: sub_1TKGXhHBmm4kY2j7md2czElJ
subscription_items: [{id: "si_UIsIxVMssK1AMm", price: "price_1PsQeAHBmm4kY2j7NoDlEBWG", quantity: 1}]
subscription_proration_date: 1775733332
subscription_proration_behavior: always_invoice
subscription_billing_cycle_anchor: unchanged
This returned amount_due: 148827.
Step 2 โ PaymentIntent creation (request ID: req_lENkLDIjqUqvT7):
Created with amount: 148827 (the exact value from the preview).
proration_date in metadata: "proration_date": "1775733332",
Step 3 โ Subscription update (on payment_intent.succeeded webhook):
{
"items": [{"id": "si_UIsIxVMssK1AMm", "price": "price_1PsQeAHBmm4kY2j7NoDlEBWG", "quantity": "1"}],
"proration_date": "1775733332",
"proration_behavior": "always_invoice",
"billing_cycle_anchor": "unchanged",
"collection_method": "send_invoice",
"days_until_due": "1"
}
This created an invoice with amount_due: 148826 (1 cent less).
So yes, the same proration_date timestamp (1775733332) is used in both the preview and the actual update. The only differences are:
- Preview uses subscription_* prefixed params (as required by the upcoming endpoint)
- Update adds collection_method: send_invoice and days_until_due: 1 (needed for the deferred payment flow)
Could collection_method: send_invoice affect the proration calculation or rounding? That's the only parameter that differs between preview and update
You'd really need to provide request IDs in order for us to look at it more closely. The one ID you provided wasn't for a Payment Intent create.
Though as my colleague mentioned, using the newers APIs can help here:
I think you're best approach here is to upgrade to newer API version (minimum 2025-06-30.basil https://docs.stripe.com/changelog/basil/2025-06-30/billing-mode#whats-new) to get access to billing_mode: "flexible", this guarantees a more accurate calculation and instead of using the upcoming invoice API, you would use the https://docs.stripe.com/api/invoices/create_preview)