#yuvi00001

1 messages · Page 1 of 1 (latest)

mild mauveBOT
orchid crystal
manic mountain
#

so in order to overwrite a created usage I need to use set action with the previous created record's timestamp ?

orchid crystal
#

If the Usage Records that were originally created with action:increment, you cannot just set final quantity since a single timestamp could be tied to multiple Usage Records that were added together. Instead, you need to retrieve the current total usage reported for that timestamp, subtract the quantity they want to delete, and use that value as the quantity in the creation request.

For example,

curl https://api.stripe.com/v1/subscription_items/si_xxx/usage_records \
  -u sk_test_xxx: \
  -d quantity={{TOTAL_USAGE - QUANTITY_TO_DELETE}} \
  -d timestamp={{TIMESTAMP}} \
  -d action=set
manic mountain
#

I just checked my code base, every time I want to increase user's usage, I increase the quantity of metered sub, by creating a usage-record with action as "set" , I think I was having some trouble using action as "increment" previously when I was developing this.
Is there a way to reduce quantity if all other usage were created with action as "set" ?

or is it ideal to create a usage with action set to "increment" and then use "set" to settle quantity.?

orchid crystal
#

For Usage Records that were originally created with action:set, you can reset the quantity reported for that timestamp by setting to the new quantity.

For example,

curl https://api.stripe.com/v1/subscription_items/si_xxx/usage_records \
  -u sk_test_xxx: \
  -d quantity={{NEW_QUANTITY}} \
  -d timestamp={{TIMESTAMP}} \
  -d action=set
manic mountain
#

Like, within a billing cycle,
if on the first day, user uses my product for 10 mins , I create a usage record with action as "set".

then, if on 10th day, they use product for 20 mins, I create a usage record with action as "set".

then , if on last day of month, they use product for 30 mins ,I create a usage record with action as "set".

is this an ideal approach to handle metered usage ?

orchid crystal
#

Have you tried to test with set with lower quantity?

manic mountain
#

I created a usage record for 10 quantity with x timestamp,
i created another request with 0 quantity with the same timestamp. But it didnt reduce the estimated price of my upcoming invoice.

orchid crystal
#

Can you share the subscription ID (sub_xxx)?

manic mountain
#

yeah sure

#

sub_1N9A4PSDGA5oE739XNRGmlwx

orchid crystal
manic mountain
#

okay, I get it so I need to store recordID and timestamp if I want to overwrite them.

orchid crystal
#

Yup!