#ykmb_billing-reason
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/1291455937659273278
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
To add,
Hi ๐
I'm taking a look at the Invoice now
all the invoice events inside https://dashboard.stripe.com/payments/pi_3Q5WXAFgh02vnRc707Fx8XHw#wb-N4Igdghgbglg5hALjA9mEAuUBjArgJ3wFMxEAlFXRIzUSAWxoxAHUB5MgaQCEBRAOQDCACQD6bAGq8yEgJK8WIAL4AaEABskRAM7lK1bbRAooRfLCIB3IwyasOPASPFSZ8xapAATHckjI0QyxwCEZMey4+ITEWXm5hNjZOAGVlNSJTUiC6ULt2SKcxXil+ABVUz3UUOGyQsOZ8x2jRABk2AHEKtQALIgh1RG6bXPDGqOdhXgBBFtLhNJAzfBR8WttRh3GisjIOLu8MoiqABzNZMG14bsQ1kYbNwtFZfmTZduFyhZgL0+xEFeG9QiTWcz2SAAVeIJShwFtpQsd1DpAXkHs1klMALLglq8fbaXrqdQojYFdGTFotBbYYhaAAivm+SFQYBYMAAXhB8F4Sfcyc5YvFEilRIIyNNSrwFpYjtgUPUckCxo9Yi1BGxMVLPNoiIg-DVecCtqJkrxSqVnp0FgZ9clsCQuahbkq0c5JckLfx2ibBAIpmRZGwKp4IH8YKZShAAEbhb7aX7-fAgNSIaPCGC6FYAT0wAG1jKZzDArCAALpqZZUIjpzP4HMYXOKuyCACqHo10mSojpZqmsipamOXNCtRgPOYeG0ogAigAPbjJFvCAAMbEQLZaAGss+04X18NghlhtfvD8kIAAzJjATzdCAE8JpJvhcFTACamrKXZ7pT7A5AQ74CORhjuExwwKIADM04AKwsAAGlMABicDdMuABMUBgGQ2AAOzLrhSGzgAHPBwjWCeXKHrQlEHt055XjRPT3keIDKKW2oct8cCYGAuBEj0RBXIgmAAJzETBaiwJcUYwOoMCIFmmIoD44TSTAUZIsmIBxgmALBMQ2iUAeRCyOOAEQdBcGIShaGYdheEEURpHkdpqYxswhxZNpPinGAPhgNgWZmbGYCiAAjLBCGibZGFYThhG4ZB8G4Mum48ekmQ3EYF5ydQqxGF4WhGAMTDhbh6G4cRonLsR6HocujW0dRzDaboSC4EEubliAhnGfaj5qCgUYAFZEH8IWtZlJCIKUWanINiyECsc0LQ2HFqDqSJ-EQXiTYsUCIBFUXwXSsX2QlI0tjB+BkC2dJ0m1RzjdQXhTHqRD0MciCTXxRJKADQA have billing_reason as subscription update, but if you click to see the actual invoice it says subscription creation?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sorry but we can't use dashboard links
Oh
sorry
evt_1Q5WXDFgh02vnRc7jU5rRUDD
evt_1Q5WXGFgh02vnRc7MY9nURur
evt_1Q5WXGFgh02vnRc7bFTa9ilO
^ these have billing reason subscription update
Okay so the request that is Invoice is associated with ( https://dashboard.stripe.com/logs/req_25jbN31V72UTWe ) is a Subscription creation
but in_1Q5WX9Fgh02vnRc7F73Xu0kg has subscription creation as the billing reason
Okay that is a lot of records, give me a sec

I am seeing the same billing reason in this event for that Invoice: https://dashboard.stripe.com/events/evt_1Q5WXDFgh02vnRc7a0fupVhR
I have an idea of why this is happening though
I think this is because you are explicitly passing trial_period_days: 0 in your Subscription creation requests like this one: https://dashboard.stripe.com/logs/req_25jbN31V72UTWe
In Test mode, can you try making the same request but without the trial_period_days parameter?
ok let me try.
I suspect (don't know for sure) that this parameter is causing us to create a Subscription in a trial mode for, like, a second. And then when we determine the trial is over and we need to invoice, we are considering an update. That's just a guess though
I have another question as well: what is the condition for it to show billing_reason: subscription_cycle?
I am seeing in some legacy code that we have that is condition to check if the invoice is related to subscription (or v.s. one time), but I don't think I see subscription_cycle as the reason in many invoices ( just my random manual checks )
for example, is subscription_cycle only for subscription extention? not for first invoice?
I suspect (don't know for sure) that this parameter is causing us to create a Subscription in a trial mode for, like, a second. And then when we determine the trial is over and we need to invoice, we are considering an update. That's just a guess though
checking this now, 1 sec
Subscription cycle means invoices that are generated because of a new billing cycle
So if you create a Subscription with a monthly price, the first invoice will have billing_reason: 'subscription_creation' (or it should).
The next month, if you don't make any changes, the Invoice should have a billing reason of subscription_cycle. This means it's the normal billing cycle that triggere the invoice generation.
This distinguishes those invoices from Invoices that may be created due to changes made to the subscription
test mode subscription sub_1Q5tNEFgh02vnRc7C5xf5MgT
I am still seeing subscription_update as the billing_reason
this is the request id if that helps - req_AQPZwue1eZE166
I used stripe cli in webapp to test , but I would assume that python bindings would work the same way
I just used my Python code with the following params
{
customer: "cus_M3iS9VTsMdI7Qj",
description: "test sub",
expand: {
0: "latest_invoice",
1: "pending_setup_intent",
},
items: {
0: {
price: "price_1MCrmaIlCeH6bP8RSZAQIIXa",
},
},
metadata: {
foo: "barr",
},
}
And I got a billing_reason: 'subscription_create'
I noticed that your API version is 2018-02-28 .... but the docs you are looking at should be for that version
(my default API version is 2020-08-27)
how do I check to make sure I am looking at the right api doc version?
I am logged in, so that should suffice?
on top right corner of https://docs.stripe.com/api/subscriptions/create?lang=cli
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yes, I think so. I don't think that is what is doing this.
Can you try using Python code? I know it's a bit more work
Yes
In [5]: import stripe
...: from api.payment.integrations.stripe_api import stripe_calls
...: stripe_calls.stripe_request(
...: stripe.Subscription.create,
...: **{
...: "customer": "cus_QxSAvJA50bBGfC",
...: "items": [{"plan": "price_1Q2IfiFgh02vnRc7yQekFeYh", "quantity": 15}],
...: # "trial_period_days": 0,
...: "metadata": {
...: "source": "otter_server",
...: },
...: }
...: )
sub_1Q5te9Fgh02vnRc77juRgWCT
๐ค
I was originally suspecting if it is related allow_incomplete. but this python request above I did not add allow_incomplete and it is still subscription_update
Oh by the way, would it be possible that you can note down my email address somewhere so that when you have the answer to our confusion you can send me an email notif as well? I don't check discord frequently enough so I am slightly worried about missing messages here ๐ข
no worries if that is not something standard to do
I can check back periodically until we have an answer ๐
Give me a minute to double check with my team
tysm!
Okay, it was the API version! We didn't add subscription_create until version 2018-10-31
I see. So how should I access the right api docs to learn about the possible billing_reasons?
the link was helpful, but wanted to make sure I know about all the options it can carry
Unfortunately I don't think our API docs will exactly reflect your API version. I think you will need to keep reviewing the API upgrades doc.
I see. thanks!
I have another related question about subscription invoice can I ask that here as well? or should I create a new thread
it is about how to tell if an invoice is a initial invoice (e.g. via next_payment_attempt) field
Hi there ๐ jumping in as my teammate needs to step away. You're welcome to keep asking questions here.
great thanks!
let me summarize my question so that it is clearer.
upon receiving invoice.payment_failed event, I am trying to figure out if the invoice is tied to an "initial invoice payment attempt", this includes the invoice payment attempt to first time charge a subscription with or without a trial period. do you know what is the best practice in getting this information from an invoice.payment_failed webhook event?
here are my thoughts / scratch at the moemnt: when there is no trial period, I think the payment is only tried once (no dunning period), is this correct? If so, I think I can use condition invoice.next_payment_attempt is None and invoice.attempt_count == 1
If you're on a new enough API version where the billing_reason field gives you that insight, that would be the best way. Otherwise you'll likely want to list Invoices for the Subscription and see if there are more than one:
https://docs.stripe.com/api/invoices/list#list_invoices-subscription
next_payment_attempt and attempt_count are specific to that single Invoice object, they don't give you insight into how it relates to the overarching Subscription.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Oh, I see you updated your message to talk about payment attempts rather than Invoices, one sec to let me recalibrate.
yes, sorry I got my terms a bit confused when writing the message
Yeah, that condition sounds reasonable, or even just attempt_count == 1 would likely be sufficient
I see, so failed + attempt_count == 1
can I also assume that this holds for subscriptions with trial days at the beginning as well?
If I recall correctly an Invoice is still produced for the trial period, but no payment is processed for it because it's a zero-dollar Invoice.