#blackbearftw_docs
1 messages ยท Page 1 of 1 (latest)
๐ 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/1296416865446264922
๐ 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.
- blackbearftw_docs, 13 hours ago, 33 messages
Our goal is to bill per resource the user creates, per month, so if a user creates 20 records in a month, I would like to get that value, at the start of the billing period it would go back to 0 again
hi there!
to get the current value of a meter, you should use MeterEventSummaryListOptions, which you seem to be already using.
what's the issue with the code you shared?
Stripe.StripeException: start_time 1726567998 should be aligned with daily boundaries (expected 1726531200) because thevalue_grouping_windowis day.
I also have another question, if I create a pay as you go subscription with a monthly billing, will the user be charged at the end of each calendar month or is a charge being made relative to when the user started their subscription (e.g. user subscribes on 2 okt, will they be charged on the 2 nov)?
if I create a pay as you go subscription with a monthly billing, will the user be charged at the end of each calendar month or is a charge being made relative to when the user started their subscription
by default it's relative to their start date, but that's something you could configure: https://docs.stripe.com/billing/subscriptions/billing-cycle
Stripe.StripeException
can you share the request ID (req_xxx)? you can find it here https://dashboard.stripe.com/test/logs
req_9p9JsYM3RUdCvX
mhm that makes it very difficult to figure out from my side how I can know what usage they are currently on, especially since I need to set a start and end time
because now I need to figure out the start and end time relative to the customer right
to get their billing period synced up
๐ taking over for my colleague. Let me catch up.
basically the error here is kind of self-explanatory.
when using value_grouping_window you need to respect the start of the hour or the start of the day depending on the value_grouping_window you're choosing
basically if you choose to group by hour
the start_time needs to be set on the top of the hour (e.g. 01:00, 02:00,...,22:00, etc.)
yeah I understand
the same applies for the end_time and when you're using the value_grouping_window day
but in reality I don't really care about that, I just want the get the current value on this moment in time
yeah
then you don't need to use the grouping
the grouping is to aggregate by day or hour
can I then only pass the customerId?
yes
and you can send start and end time as well
but just remove the value_grouping_window in that case
since it's not Required
what do I then set the start and end time to?
as I said, I want to get the current value of the meter for the billing period of the customer
I know a meter can only go up
then from the subscription
you can get the https://docs.stripe.com/api/subscriptions/object#subscription_object-current_period_start and https://docs.stripe.com/api/subscriptions/object#subscription_object-current_period_end
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
and use these as the start_time and end_time
but how does that work on stripes side, does this meter reset at the start of the next billing period?
no
technically the billing meter will keep receiving events
but we will use the events between the current_period_start and current_period_end to calculate the usage of this period
its really annoying how I have to figure all of that out on my side
my entire use case is to have a customer, with a pay-as-you-go subscription, they create a resource through our API, at the end of their billing period, it checks how many resources were created that month (or whatever the billing is set to) and then just charges the user for that amount
but you are saying, I now need to first figure out the billing period of the current customer, which requires an api request, then I need to ask for their metered events, which is an api request, then I need to look at the first value in that collection and then at the last value and then subtract those from eachother just to get the relative value for this billing period
I agree, we're working on improving our docs about this
that's not entirely correct
you don't have to do any of that
since the subscription will calculate everything for you
and would generate the invoice on your behalf
I'm not sure I totally understand what you mean by that
what I want to do in OUR api, is simply call some wrapper service, call something like StripeBuildingMeterService.AddToMeter(1) (our resource is called building)
this is for the usage record
yeah
yeah see how value is not a relative number
and if you need to fix an incorrect usage you use https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage#fix-incorrect-usage
yes you don't have to pass a relative number
but I want to
that is the whole idea
as soon as our create API endpoint is hit, I want the meter to do +1
it will
depending on the aggregation formulat you choose https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage#aggregation-formula
so if I pass a value
you can either choose sum or count
if it's count then it will only the count the number of events
if you choose sum
each time you send an event the value is added to the previous ones
then your documentation sucks because it gives 25 as an example
making it look like that is the current whole value of the meter
if the formula the meters uses is sum (which is generally the case)
this means that you're adding 25 to the previous quantities recorded
I highly recommend taking the time to read this doc https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage
the whole thing
so you get familiar with the different concepts
I'm here to answer any other question you have
so please let me know if you have any follow-ups
aka how many units are created this billing period
even here it doesn't mention anything about this being a relative value: https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage-api#usage-values
you can use the https://docs.stripe.com/api/invoices/upcoming
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
because it's not always a relative value
in https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage#aggregation-formula
you also have Last
and when choosing Last, it means that each time you override the value
alright
the difference about sum and count is still not very clear to me to be honest
even when reading the documentation
sum means Stripe will add all the values you passed to the different meter events you sent during the billing period
count means Stripe will count the number of times you sent meter events during the billing period
is that clearer?
so sum looks at the overal value per billing period (however many events that might have taken), while count looks at the amount of events (and not at their value) send that billing period
Correct, yes