#nerder

1 messages · Page 1 of 1 (latest)

distant meteorBOT
rancid dome
#

👋 how can I help?

deft iris
#

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

#

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)

rancid dome
#

since you're not passing subscription_proration_behavior above, the default value for this is create_prorations, so that lines up with ^

deft iris
#

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

rancid dome
#

i think you want to include subscription_proration_behavior: 'always_invoice' with invoices.retrieveUpcoming

deft iris
#

ok I see!

#

I was looking for proration_behavior instead of subscription_proration_behavior

#

my bad 🤦‍♂️

rancid dome
#

ah gotcha

#

np!

deft iris
#

Yes!

#

it works perfectly

#

amazing, thank you so much

rancid dome
#

happy to help!

deft iris
#

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?

rancid dome
#

so yes, in this case, prorations for unused time will come before the remaining time

deft iris
#

that's great, so for my use-case is lines.data[0] is always the unused

#

perfect

#

This should be it

#

eheh

#

thank you again