#mike-usagerecord-fix

1 messages ยท Page 1 of 1 (latest)

nocturne craneBOT
glad field
#

Hello ๐Ÿ‘‹
Can you share the test request IDs where you're seeing the error you've mentioned in the previous thread?

magic stone
#

I've got the request_log_url in the responses if that helps? I'm using the CLI integration in the browser from within my Stripe Dashboard

glad field
magic stone
#

Thanks - managed to dig these out of the logs:

req_IkXouWkxnIaRjY
req_DZZe68gbOPB4PE
req_lWa96D8tgAx3k9 (I tried "increment" with this - the other two were "set")

nocturne craneBOT
glad field
#

thanks for sharing these, I'm still looking..

rapid patrol
#

mike-usagerecord-fix

#

@magic stone sorry taking over and Discord is really busy. Can you re-summarize what you are really trying to do and how your Price is configured? The grace period is really specific and only for

when using the default aggregation mode (aggregate_usage=sum).

magic stone
#

Sure...

  • We have a product / price configured that is metered and set to aggregate_usage=sum
  • We send a daily usage record to Stripe with a fixed timestamp, that we "set" every time we need to update the value for that day
  • We will Sync to stripe when users do certain things (so fairly ad-hoc), or on a schedule every few hours, to ensure we always have a usage record written out to Stripe for that day, even if no activity took place that would mean we'd write out anyhow
  • For one of our prices we can't sync into Stripe as it happens, so we rely on syncing that data in on our scheduled sync every few hours
  • For that last point, it's entirely possible that when we come to do it, the billing day in Stripe has rolled forward and if we're now in a new billing cycle, that we have some usage we need to report for the previous billing cycle, but we're now in the current billing cycle

...so I'm trying to find the right way to handle this and the docs saying "Your integration is allowed to write events occuring in the last 5 minutes of the previous period at any time in the current period. Events written this way are billed in the current period." ...says to me that at any point in the current period I can write usage records that occurred in the last 5 minutes of the previous billing cycle?

hard brook
#

Hello! I'm taking a look at the requests you provided above, give me a couple minutes. ๐Ÿ™‚

#

No, that's not correct unfortunately. The grace period means that for five minutes after the previous period ends you can still add usage for that previous period, but only for five minutes. For example, let's say you have a period that ends at exactly midnight, and now it's 12:03 AM. You can add usage records for, say, 11:58 PM at that time. Now let's say it's 12:07 AM and you want to add usage records for 11:59 PM. You can't do it. 12:07 AM is seven minutes past the end of the previous period, which is more than five minutes.

magic stone
#

If it's not possible to do what I think, then I could take a different approach and try to work out the delta between the last numbers I reported, the numbers I should have reported for that day and then just add those numbers onto the current day I report? ๐Ÿค”

hard brook
#

Yep, you could do that.

magic stone
#

@hard brook thanks - I reckon those docs need rewording a bit as they suggest you can do what I was hoping?

hard brook
#

Usage reported during the grace period ends up on the next Invoice anyway, so the result is going to be essentially the same.

magic stone
#

"Your integration is allowed to write events occuring in the last 5 minutes of the previous period at any time in the current period"

hard brook
#

Yeah, I just looked at our current docs, and wow, I was surprised. I totally understanding your confusion. We'll get that sorted out.

#

The previous version of the docs said this, which is more accurate:

Reporting usage outside the current billing interval results in an error. Stripe leaves a 5 minute window in the default aggregation mode (aggregate_usage=sum) after the period ends to allow for clock drift. Your integration is allowed to write events for a billing period up to 5 minutes after the period is closed, but might generate an invoice before that window is elapsed. If Stripe has invoiced for the period before you write usage events, those events roll over to be invoiced in the subsequent billing period.

magic stone
#

Yeah that you describe was what I suspected the behaviour is. I think me working out the delta and whacking it onto the current period is the best route forward.

hard brook
#

Yep, that's probably what I would do. ๐Ÿ™‚

magic stone
#

Thanks for your help on this ๐Ÿ‘