#nerder
1 messages · Page 1 of 1 (latest)
👋 how can I help?
Hey
I'll show you my current implementation, is not working as expected but i'm not sure on how to make it so
const invoice = await this.stripe.invoices.retrieveUpcoming(
{
subscription: subscriptionId,
subscription_items: [
{
id: oldItemId,
price: newPriceId,
},
],
subscription_proration_date: Math.floor(Date.now() / 1000),
},
{ stripeAccount: accountId.value },
)
I'm trying to preview the user in the frontend with a little breakdown of how much they need to pay if they proceeds updating their sub
i'm mainly following this tutorial: https://stripe.com/docs/billing/subscriptions/prorations#preview-proration
the problem is that this example is only showing a scenario when the proration_behaviour of the update is the default (so the one that add a new item to the sub)
since you're not passing subscription_proration_behavior above, the default value for this is create_prorations, so that lines up with ^
this is the code for my update:
await this.stripe.subscriptions.update(
subscriptionId,
{
cancel_at_period_end: false,
proration_behavior: 'always_invoice',
items: [
{
id: oldItemId,
price: newPriceId,
},
],
},
{
stripeAccount: accountId.value,
},
);
aah ok
i think you want to include subscription_proration_behavior: 'always_invoice' with invoices.retrieveUpcoming
ok I see!
I was looking for proration_behavior instead of subscription_proration_behavior
my bad 🤦♂️
happy to help!
Ah sorry since we are here
lines are guaranteed to be always in the same order?
so first showing the Unused time for the previous item, than the Remaining time for the new price?
This might help: https://stripe.com/docs/api/invoices/object?lang=node#invoice_object-lines
lines is sorted as follows: (1) pending invoice items (including prorations) in reverse chronological order, (2) subscription items in reverse chronological order, and (3) invoice items added after invoice creation in chronological order.
so yes, in this case, prorations for unused time will come before the remaining time