#kosherslayer

1 messages · Page 1 of 1 (latest)

placid sandBOT
muted ibex
#

Hello

astral totem
#

await stripe.subscriptionItems.createUsageRecord(item_id, {
action: "set",
quantity: 0,
});

However, it jsut records a usage of 0 and doesn't set anything?

#

and the usages are carried forwards on upgrades

#

Hey

#

Cause what I'm trying to do is on a subscription upgrade, add the usages of the old subscription prices as invoice line items to the next invoice

muted ibex
#

You need to overwrite usage if you want to clear it

#

So you have to pass the same timestamp as your previous usage

#

Otherwise it just creates a new usage record

astral totem
#

i thought with 'set' overrides it?

muted ibex
#

The set action will overwrite the usage quantity at that timestamp.

#

So you need to grab the correct timestamp for the usage you are trying to overwrite

astral totem
#

oh hmm, but what if they have 20 usage records over a month period? I dont want to have it get the timestamp for all 20 and set those to 0?

#

I want to:

  1. Add the invoice line items for the previous subscriptions usages to the next upcoming invoice
  2. Clear all the usages
  3. Put customer on upgraded subscription
#

Or if there's another way to do this im open for that too

#

This relates to the problem I was facing in my previous thread, repasting it here:

Ie. t1 charges are 2$ / item, t2 charges are 1$ / item.

What happens is when they upgrade, they aren't billed and their usages are just transferred over to the new subscription where they'll now pay the lower rate for all their past usages. I don't want to charge them for their usages on the old subscription immediately, but want the new invoice to be 2$ / [# of items on old usage] and 1$ for all future usages. Is that possible?

muted ibex
#

So what you likely want to do then is just mutate the usage at the same timestamp every time

astral totem
#

cause right now, i correctly create the invoice line items but the usages for the old subscription stays. So now I'm overcounting it

muted ibex
#

So then you only have to clear out one timestamp

#

Otherwise you do have to clear each one as you noted

astral totem
#

oh hmm

#

This is the only way I can accomplish what I want to do?

muted ibex
#

Then you don't have to pass the same time stamp but you would have to track the sum of the usage yourself and add the total amount each time you create a usage record

astral totem
#

so right before they upgrade i create a usage record for all the usages they've made this month, and last_during_period will make it so that it will always just access the last value?

muted ibex
#

Yeah or you can just create the usage records as they go but instead of doing 1, 1, 1 you would do 1, 2, 3 for the amount of usage.

#

Then when you are ready to clear you just create a usage record for 0

astral totem
#

wait why would I do 1, 2, 3? Confused about that

#

oh nvm

#

I see

#

got it. Thank you!