#ykmb_billing-reason

1 messages ยท Page 1 of 1 (latest)

pure tideBOT
#

๐Ÿ‘‹ 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.

bronze crane
#

To add,

frail atlas
#

Hi ๐Ÿ‘‹

I'm taking a look at the Invoice now

bronze crane
#
frail atlas
#

Sorry but we can't use dashboard links

bronze crane
#

Oh

#

sorry

#

evt_1Q5WXDFgh02vnRc7jU5rRUDD
evt_1Q5WXGFgh02vnRc7MY9nURur
evt_1Q5WXGFgh02vnRc7bFTa9ilO
^ these have billing reason subscription update

frail atlas
bronze crane
#

but in_1Q5WX9Fgh02vnRc7F73Xu0kg has subscription creation as the billing reason

frail atlas
#

Okay that is a lot of records, give me a sec

bronze crane
frail atlas
#

I have an idea of why this is happening though

#

In Test mode, can you try making the same request but without the trial_period_days parameter?

bronze crane
#

ok let me try.

frail atlas
#

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

bronze crane
#

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

frail atlas
#

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

bronze crane
#

test mode subscription sub_1Q5tNEFgh02vnRc7C5xf5MgT

#

I am still seeing subscription_update as the billing_reason

frail atlas
#

๐Ÿค”

#

Let me try and replicate

bronze crane
#

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

frail atlas
#

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'

bronze crane
#

๐Ÿ˜ฒ

#

so what am I doing wrong in my req req_AQPZwue1eZE166

frail atlas
#

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)

bronze crane
#

how do I check to make sure I am looking at the right api doc version?

#

I am logged in, so that should suffice?

frail atlas
#

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

bronze crane
#

sure, 1 sec

#

test mode suffices right?

frail atlas
#

Yes

bronze crane
#
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

#

๐Ÿค”

frail atlas
#

I will have to flag this internally.

bronze crane
#

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 ๐Ÿ™‚

frail atlas
#

Give me a minute to double check with my team

bronze crane
#

tysm!

frail atlas
pure tideBOT
#

ykmb_billing-reason

bronze crane
#

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

frail atlas
#

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.

bronze crane
#

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

crisp birch
#

Hi there ๐Ÿ‘‹ jumping in as my teammate needs to step away. You're welcome to keep asking questions here.

bronze crane
#

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

crisp birch
#

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.

#

Oh, I see you updated your message to talk about payment attempts rather than Invoices, one sec to let me recalibrate.

bronze crane
#

yes, sorry I got my terms a bit confused when writing the message

crisp birch
#

Yeah, that condition sounds reasonable, or even just attempt_count == 1 would likely be sufficient

bronze crane
#

I see, so failed + attempt_count == 1

#

can I also assume that this holds for subscriptions with trial days at the beginning as well?

crisp birch
#

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.

bronze crane
#

ok I will experiment to double check. ^ is my understanding as well, which means until after the trial period, no payment is attempted, which means there will be no payment_failed at least until the trial period end timestamp

#

Great, it has been super helpful!!