#Ben Clum - usage record
1 messages · Page 1 of 1 (latest)
Hi there!
You cannot reverse a usage record, or create a negative one. Instead you can create a new usage record with action: set with the correct total value directly.
ah perfect. that makes sense! Thanks!
actually the set action seems to be incrementing instead of setting the usage value. I'm updating like: record = Stripe::SubscriptionItem.create_usage_record("si_MBsQaoVZ0uT5by", { quantity: 40, action: 'set', timestamp: Time.now.to_i })
and the usage keeps going up instead of staying at 40: https://dashboard.stripe.com/test/subscription_items/si_MBsQaoVZ0uT5by/usage_records
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
the record ID is mbur_0LUUBS250JCmBXjUZkaoV5rg
and also the usage record summary also is not 40: irb(main):082:0> Stripe::SubscriptionItem.list_usage_record_summaries("si_MBsQaoVZ0uT5by", { limit: 1 }) => #<Stripe::ListObject:0xee278> JSON: { "object": "list", "data": [ {"id":"sis_0LUUDr250JCmBXjUheulLtHg","object":"usage_record_summary","invoice":null,"livemode":false,"period":{"end":null,"start":null},"subscription_item":"si_MBsQaoVZ0uT5by","total_usage":161} ], "has_more": false, "url": "/v1/subscription_items/si_MBsQaoVZ0uT5by/usage_record_summaries" }
here is a recording of me also creating a usage record via the stripe dashboard with unexpected behavior: https://monosnap.com/file/bUo1vZlf90fNXPbfypD25k4d5icF1l
Monosnap — the best tool to take & share your screenshots.
Looking into this...
Here is the request where you set it to 40, and it did set it to 40: https://dashboard.stripe.com/test/logs/req_AVqfvcsuiMeK6Y
here is a recording of me also creating a usage record via the stripe dashboard with unexpected behavior
That looks odd. Investigating...
I tried it on a different subscription item that had never had usage reported before and set works as expected. I think maybe if increment has been used already on that subscription item, then using set doesn't work.
Well I managed to reproduce, so that's a bug!
I'll open an investigation internally, and we will fix that soon.
Oh wait. Actually you need to use aggregate_usage:last_during_period on the Price in order for the set action to work as expected https://stripe.com/docs/api/prices/create?lang=php#create_price-recurring-aggregate_usage
So it's not a bug.
ah got it. so sum ignores set and increment. which sort of makes sense, but that wasn't super clear when I read the documentation on aggregate_usage
Agreed, I'll send that feedback to the team. Thanks!