#vero_meter-usage

1 messages ยท Page 1 of 1 (latest)

ancient dawnBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1283481546476748993

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

swift pagoda
#

if my customer made 25 usages they should be billed for 25 usages. 10 usages were successfully sent but not one was accounted for. they did show up in the meter dashboard page.

full latch
#

๐Ÿ‘‹ Please give me a few minutes, the server is quite busy. Can you in the meantim show a clear reproduction example with exact object ids and what you see in the API so I understand your ask?

swift pagoda
#

i will try my best.

#

i deleted my test clock so i will have to start over to be able to send you screen shots

full latch
#

I'd love to get a clear explanation with exact code and API object ids and not screenshots if possible

swift pagoda
#

my code?

full latch
#

Hopefully yes. This server focuses on helping developers with their Stripe integration so that almost always means you are writing real end to end code to understand our products and APIs and integrate them

swift pagoda
#

ok

#

this is gonna take me a min, please bear with me ๐Ÿ™‚

full latch
#

Sure but are you saying you weren't yet writing code? Or something else?

#

Sorry the server is suddenly super busy and I'm confused by most questions ๐Ÿ˜…

swift pagoda
#

my code is written and i am testing failures and retries to make sure we are billing our customer correctly.

full latch
#

Perfect. So yeah once you have a clear end to end example wth details I should be able to clarify the problem!

swift pagoda
#

ok thanks.

full latch
#

vero_meter-usage

swift pagoda
#

MeterEvent meterEvent = usageRecordService.sendMeteredUsageRecord(stripeSubscriptionItem.getStripeCustomerId(), meterName, apiUsageRecord.getCreatedAt().toEpochSecond(), idempotencyKey);
if (meterEvent.getLastResponse().code() == 200) { apiUsageRecord.setStatus(ApiUsageRecordStatus.PROCESSED);
}
...
catch (StripeException e) {
apiUsageRecord.setStatus(ApiUsageRecordStatus.FAILED);
apiUsageRecord.setErrorCode(e.getStatusCode());
if (e.getMessage().startsWith("An event already exists with identifier")) {
// since we already have an event with that key we do not want to reprocess it.
apiUsageRecord.setStatus(ApiUsageRecordStatus.PROCESSED);
}
apiUsageRecord.setErrorMessage(e.getMessage());
apiUsageRecordRepository.saveAndFlush(apiUsageRecord);
throw new RuntimeException(e.getMessage()); // this is for kafka retryable topic to pick up
}

#

this is part of the code

#

stripe customer id = cus_QpYUmnYikJYVim
subscription item id = si_QpYWO0ZRg0uEBz
subscription id = sub_1PxtP7LTGhL6Kyay5nERP8YV

i sent 10 meter events to this customer
req_zEpYsUL39hDTFV
req_DFCUTPmaQ8xIt9
req_HbXgKUdNkc3tKg
req_O08Ur6CR2Yuj8T
req_mehCJ7KDqKSGqx
req_a1epdpdargY2UL
req_M6Djnb0eHqB31g
req_7PcLUvNYIvR6DN
req_TJoJHqFeiUEi0K
req_xquDsrGAdJpxv1

i can see the count to 10 on my usage under upcoming invoice.

#

advanced clock to sept 12 16:34
POST /v1/test_helpers/test_clocks
{
"id": "clock_1Pxv6bLTGhL6KyayVaRlirhu",
"object": "test_helpers.test_clock",
"created": 1726078649,
"frozen_time": 1726078649,
"name": "Test clock for cus_QpYUmnYikJYVim",
"status": "advancing"
}

invoice 6DC205BE-0002 is in a draft state with 10 count for billing.

sent two new meter events all status 200.
req_aDHbpxohvUMMhz
req_K5Ro9OVoOitfFX

POST /v1/test_helpers/test_clocks/clock_1Pxv6bLTGhL6Kyay... req_tzuNTynUZntXfq
{
"id": "clock_1Pxv6bLTGhL6KyayVaRlirhu",
"object": "test_helpers.test_clock",
"created": 1726078649,
"frozen_time": 1726158840,
"name": "Test clock for cus_QpYUmnYikJYVim",
"status": "advancing"
}

advanced time to 18:34
6DC205BE-0002 was paid for $12. works as intended.

#

sending 3 new meter event with now date simulating a glitch such as throttling and i have a cron job that resend every failed usage around 2-3 am.

req_x8XiwKXqNrD3oR
req_hcxwSlfAZeQUZs
req_TX9ihFutQqj1Rr

all three of those calls returned a 200 response.

https://dashboard.stripe.com/test/meters/mtr_test_61R6XgqaEiSEsBptF41LTGhL6KyayQae is showing 15 counts same as I have in my database.

forward clock to sept 13 18:34 req_9MXp3rG1379wF1
{
"id": "clock_1Pxv6bLTGhL6KyayVaRlirhu",
"object": "test_helpers.test_clock",
"created": 1726078649,
"frozen_time": 1726166040,
"name": "Test clock for cus_QpYUmnYikJYVim",
"status": "advancing"
}

6DC205BE-0003 was paid with $0.00 where is the three event i sent earlier? the timestamps on those three event were dated from Sept 11 before invoice 0002 was finalized. i would have thought that either stripe would throw an exception or add the count to the next upcoming invoice.

full latch
#

Okay, let me try to grasp all of this for a few minutes

#

sending 3 new meter event with now date simulating a glitch such as throttling and i have a cron job that resend every failed usage around 2-3 am.
can you reword that sentence? I don't get it at all

#

on those three event were dated from Sept 11 before invoice 0002 was finalized.
also can I ask you to be really crips about exact unix timestamps? Because the exact second matters

ancient dawnBOT
swift pagoda
#

I have set up a simulation (time-clock) on my customer where the subscription period ended and has created an invoice that is now finalized. I am trying to resend a meter event from the previous subscription period (time period before the invoice finalized).

#

when stripe throttle my request, i store those in a database with a created timestamp. this created timetamp is the timestamp i use on the meter event

winter pilot
#

๐Ÿ‘‹ stepping in here

swift pagoda
#

as you can see i sent 15 event but was only billed for 12

winter pilot
#

If you are sending a Meter Event with a timestamp for the previous billing period then it isn't going to get picked up in this new billing period.

swift pagoda
#

so they just don't get accounted for?

#

even though i get a 200 response back

winter pilot
#

Yes because a Meter Event is not directly tied to a Subscription

swift pagoda
#

yes i am aware of this. so what would you suggest. what if i have a burst of calls and 100s of them are getting throttle. when my cron job sends those again should i adjust the date to now and not the date the record was created?

winter pilot
#

If you are going to cross a billing period for that then yes

#

And really the easiest thing to do is just always set now for that so yeah that's what I'd recommend

swift pagoda
#

ok . thanks

#

in your old model which i also implemented stripe returns an error so i was testing all the angle possible.

winter pilot
#

Yep makes sense

swift pagoda
#

thanks again ๐Ÿ™‚