#kosherslayer
1 messages · Page 1 of 1 (latest)
Hello
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
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
i thought with 'set' overrides it?
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
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:
- Add the invoice line items for the previous subscriptions usages to the next upcoming invoice
- Clear all the usages
- 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?
So what you likely want to do then is just mutate the usage at the same timestamp every time
cause right now, i correctly create the invoice line items but the usages for the old subscription stays. So now I'm overcounting it
So then you only have to clear out one timestamp
Otherwise you do have to clear each one as you noted
Well I suppose there would be one other way which is to set aggregate_usage: last_during_period (https://stripe.com/docs/api/prices/create#create_price-recurring-aggregate_usage)
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
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?