#sahil_api
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/1262823852770332810
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Do you have a Subscription ID I can look at?
I have the invoice ID
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
It looks like the Subscription was canceled on 2024-07-01 07:59:59, and the Invoice was created on 2024-06-10 12:31:05
Yeah so the request to cancel the subscription would have been made on 10th June and it the cancellation would have been effective on 1st July
So we created the invoice on 10th June
Then on 1st July, just edited it by setting auto_advance=true
Setting that doesn't mean you get an hour to finalize. That hour occurs after an Invoice is created. Setting it on an already created invoice will finalize and pay it immediately.
okay, I am comparing this to when an invoice is created at the end of a billing cycle.
That invoice gives us an hour to finalize.
So what does auto_advane=true really does?
Yeah, this isn't being created at the end of the billing cycle. That's why you don't get an hour to finalize.
Auto-advance will automatically advance the Invoice through its various statuses toward completion of a payment. When set on an Invoice that's already created, it will attempt to pay it.
okay what will happen if I create an invoice with auto_advance=true? Will it immediately get finalized?
Yes
ok
Also, is this a recent behavioral change?
As far as I know, that's how it has always worked
What we want to do is: for a subscription that is requested to be cancelled - create an invoice, and at end of billing cycle (when the subscription actually gets cancelled) add some invoice items and let the invoice be finalized
I'm a bit confused, because the customer would have already paid for that billing period, right? If they have a subscription with a billing cycle on June 1st, then they have an Invoice that's paid on June 1st. If they later cancel the Subscription on June 15th, then no new Invoice is created unless you're prorating and issuing them a credit.
Am I missing something about your integration?
So we are manually creating an invoice on June 15th (by listening to a Stripe webhook)
And then at the end of the billing cycle, updating the invoice to set auto_advance=true
Okay, so in that case, just don't use auto-advance
You would create the Invoice, leave it alone until you're ready to update it. Then update, finalize, and pay it yourself
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
the finalize API is also about just setting auto_advance, right?
You can make the API call without setting auto_advance. If you set auto_advance then Stripe will automatically collect payment
Which means you won't have to explicitly make another call to the Invoice Pay API
Well, the thing is our integration works in a way where updating an invoice and other operations like finalizing work in an async way
Got it. Alright, it sounds like you have a good path forward!
hey, sorry, how is that?
Hello
Taking over as two-shoes had to step away
Can you summarize your question as I read through the thread above?
So the question was about the behavior for cancelled subscription
We were setting auto_advance to true for an invoice attached to a cancelled subscription and assuming it would take an hour for the invoice to get finalized.
But the invoice got finalized immediately
This is different for a invoice created at the end of a billing cycle - that is created with auto_advance=true but still takes an hour to finalize
When you say "finalized", do you mean the invoice got paid immediately after you set auto_advance to true ?
Or do you mean it was a draft invoice and it went from draft to open to paid as soon as you updated auto_advance ?
I think the first one. Can you please take a look to verify
This is the invoice: https://dashboard.stripe.com/invoices/in_1PQ7NNLoz3M8FCeuwcPCoLsi
I think that's expected. If the invoice was already open then the next step in the finalization process is to "pay" it
Taking a step back, what are you actually trying to solve? More context would help
We're trying to correctly bill cancelled subscriptions
Here's what we do:
- Using webhooks, we know when a subscription was requested to be cancelled. We created an invoice immediately with auto_advance=false.
- At end of billing cycle, when the subscription is actually cancelled, we updated the invoice and set auto_advance=true.
So setting auto_advance=true and updating the invoice happens in parallel
We expected that we would get an hour before the invoice gets finalized (or changes the status to paid)
But because that didn't happen, the invoice was immediately finalized - updating the invoice failed
hmm I'm not sure I fully follow the flow but also the invoice was for $0, it is possible that we marked it as paid automatically because there was no amount to be charged
It was $0 because we finalized it before we added items to it
Gotcha. I think the recommended way to handle this is by creating a pending invoice item when the cancellation is requested rather than creating an invoice itself.
and then at the end you'd create the invoice for the pending invoice items (if you cancel the sub before it cancels itself)
The invoice items have to be created when the cancellation happens - as we want to bill the users even for the period from cancellation request to cancelled.
Ah are you tracking the usage for that period yourself?
Yes
You said,
So setting auto_advance=true and updating the invoice happens in parallel
Can you do it sequentially instead?
Like you create invoice first -> then create invoice items and add that to the invoice -> once that's done, then you update auto_advance?
yeah we'll have to consider that and think about how we can change our architecture
But I wanted to confirm if setting auto_advance to true will immediately finalize the invoice, right? Unlike in the case of invoice generate at end of billing cycle where we get an hour before the invoice is finalized.
But I wanted to confirm if setting auto_advance to true will immediately finalize the invoice, right?
it would, yes. I would recommend testing it out thoroughly just to be 100% sure
ok
Can I ask why is the behavior different when setting auto_advance vs when it is done by Stripe for the invoice created at end of billing cycle?
I'm not sure, let me check with someone about this
ok