#evan_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/1298197968268296194
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
This is also how am performing the upgrade:
updatedSubscription = await stripeGatewayClient.subscriptions.update(
providerSubscription.id,
{
items: [
{
id: providerSubscription.items.data[0].id,
price: newProviderPlan.id,
},
],
metadata: {
subscriptionPlanId: paymentObj.newSubscriptionPlan.id,
},
proration_behavior: 'create_prorations',
payment_behavior: 'default_incomplete',
billing_cycle_anchor: 'now',
payment_settings: {
save_default_payment_method: 'on_subscription',
},
expand: ['latest_invoice.payment_intent'],
}
)
The amount_due or amount_subtotal I get from the retrieve upcoming invoice is 3999 AED, but when I check the invoice on the dashbaord, the invoice is 4001 AED
in_1QCd8HD9sYh65PYtv0eZst8S
Hi, let me help you with this.
What's the payload you receive from the upcoming Invoice endpoint?
Am using the total to show to the customer, which is 3999, but if I subscribe the invoice amount will be 4001, which is few cents different
Are you using a specific proration_date?
these are my settings when doing the upgrade:
updatedSubscription = await stripeGatewayClient.subscriptions.update(
providerSubscription.id,
{
items: [
{
id: providerSubscription.items.data[0].id,
price: newProviderPlan.id,
},
],
metadata: {
subscriptionPlanId: paymentObj.newSubscriptionPlan.id,
},
proration_behavior: 'create_prorations',
payment_behavior: 'default_incomplete',
billing_cycle_anchor: 'now',
payment_settings: {
save_default_payment_method: 'on_subscription',
},
expand: ['latest_invoice.payment_intent'],
}
)
am not specifying prorate_date here
but I am doing that when I preview the proration amount
return stripeGatewayClient.invoices.retrieveUpcoming({
customer: stripeCustomerObj.stripeCustomerId,
subscription: providerSubscription.id,
subscription_details: {
items: newItem,
proration_date: proration_date,
proration_behavior: 'always_invoice',
},
})
What's the proration_date in the second call?
It mainly defines how the proration is calculated, and unless it's exactly the same as on the actual update, the total might differ slightly
const proration_date = Math.floor(Date.now() / 1000)
this should be the time of the current timestamp shown in seconds
Could this be the issue?
https://docs.stripe.com/billing/subscriptions/prorations#:~:text=Use this information,the same time.
Yes, but Date.now() is not the same when you make the 2 calls. That's why the proration amount is different.
Okay so you think that the proration amount from the first call (for preview), should be passed to the endpoint when users actually confirms and upgrades?
And is there away I can preview the proration amount but not calculated per second, but to be calculated per hour, or day?
So that slight mismatch does not happen..
No, but you can just pass the same proration date when you upgrade the Subscription. Just make sure it's somewhere in the future, e.g. in an hour.
But if I set it in the future would not that mean that the prorated amount will be different than now? Meaning users will have to pay even more?
๐ taking over for my colleague. Let me catch up.
if you use the same timestamp in the preview API and in the subscription update you'll get the same proration amount
Yeah I got that
Thanks for that
I will try this out
thanks for the clarification
let me know if you need any more help
sure I am testing this flow now
I followed these steps
this is what I got from the prorate preview..
then I used "subscription_proration_date": 1729590818,
And passed it when updating the subscription..
as follows:
updatedSubscription = await stripeGatewayClient.subscriptions.update(
providerSubscription.id,
{
items: [
{
id: providerSubscription.items.data[0].id,
price: newProviderPlan.id,
},
],
metadata: {
subscriptionPlanId: paymentObj.newSubscriptionPlan.id,
},
proration_behavior: 'create_prorations',
payment_behavior: 'default_incomplete',
billing_cycle_anchor: 'now',
proration_date: paymentObj?.proration_date || undefined,
payment_settings: {
save_default_payment_method: 'on_subscription',
},
expand: ['latest_invoice.payment_intent'],
}
)
paymentObj?.proration_date is basically 1729590818
Hey! Taking over for my colleague. Let me catch up.
this is the invoice that was created
I am expecting the invoice to have a total of 3999, but it is showing 4001
Can you share the formula you are using that you were expecting to get 3999 amount ?
Am not using a custom formula
const newItem = [
{
id: providerSubscription.items.data[0].id,
price: stripePlanId,
},
]
const proration_date = Math.floor(Date.now() / 1000)
console.log("๐ ~ getProrateAmount ~ proration_date:", proration_date)
return stripeGatewayClient.invoices.retrieveUpcoming({
customer: stripeCustomerObj.stripeCustomerId,
subscription: providerSubscription.id,
subscription_details: {
items: newItem,
proration_date: proration_date,
proration_behavior: 'always_invoice',
},
})
That invoice has 4001:
- Zendy: 3400-1(unused time) = -3499
- Zendy 7500 : 7500
=> 7500- -3499 = 4001
What is not expected in the calculation above ?
Am using retrieveUpcoming invoice to get the preview of the price if the customer wants to upgrade
yeah above is correct
but when gettiing the upconing invoice to show the user the price they will pay
I can see that in the total it is written 3499
and that's the value that it is previewed to the user
......
"subscription_proration_date": 1729590818,
"subtotal": 3999,
"subtotal_excluding_tax": 3999,
"tax": null,
"test_clock": null,
"total": 3999,
"total_discount_amounts": [],
"total_excluding_tax": 3999,
"total_tax_amounts": [],
"transfer_data": null,
"webhooks_delivered_at": null
Above was the result from retrieveUpcoming endpoint
so a mismatch is happenning between what the user is seeing, and how much they are paying
It depends what params you send with the upcoming invoice
this is how am performing the endpoint
const newItem = [
{
id: providerSubscription.items.data[0].id,
price: stripePlanId,
},
]
const proration_date = Math.floor(Date.now() / 1000)
console.log("๐ ~ getProrateAmount ~ proration_date:", proration_date)
return stripeGatewayClient.invoices.retrieveUpcoming({
customer: stripeCustomerObj.stripeCustomerId,
subscription: providerSubscription.id,
subscription_details: {
items: newItem,
proration_date: proration_date,
proration_behavior: 'always_invoice',
},
})
For example, you need to set the exact proroation date:
https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_proration_date
You need to provide the exact timestamp when the customer would like to make the update
so that you have the same amount at the end
yeah I did that above
And what is the difference ?
There must be a difference in the timestamp
or could you please make another test and share with me the response payload you got from Stripe.
the retireve upcoming invoice I shared above is the following:
if I now subtract the next plan price which is 7500 - (amount of first line item) which is 3499 I get 4001 which is correct
For the demo purpose, to show the final deducted price for the user before they upgrade, am using the total field that comes from same response which says 3999, but am interested in showing what the user will pay at the moment which is 4001, the calculation I did previously
My question would be, what field I should be using to show the user the amount they are paying when they upgrade( from retrieveUpcoming invoice), should I do the calculation manually to show the price, or use the total ? which in my case mismatches for now. but when doing the calculation as per your formula above, getting numbers from the retireve upcoming invoice, it is correct 4001