#sahil_api

1 messages ¡ Page 1 of 1 (latest)

surreal doveBOT
#

👋 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.

wintry trench
#

Do you have a Subscription ID I can look at?

autumn trail
#

I have the invoice ID

wintry trench
#

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

autumn trail
#

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

wintry trench
#

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.

autumn trail
#

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?

wintry trench
#

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.

autumn trail
#

okay what will happen if I create an invoice with auto_advance=true? Will it immediately get finalized?

wintry trench
#

Yes

autumn trail
#

ok
Also, is this a recent behavioral change?

wintry trench
#

As far as I know, that's how it has always worked

autumn trail
#

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

wintry trench
#

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?

autumn trail
#

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

wintry trench
#

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

autumn trail
#

the finalize API is also about just setting auto_advance, right?

wintry trench
#

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

autumn trail
#

Well, the thing is our integration works in a way where updating an invoice and other operations like finalizing work in an async way

wintry trench
#

Got it. Alright, it sounds like you have a good path forward!

surreal doveBOT
autumn trail
#

hey, sorry, how is that?

midnight vigil
#

Hello
Taking over as two-shoes had to step away
Can you summarize your question as I read through the thread above?

autumn trail
#

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

midnight vigil
#

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 ?

autumn trail
midnight vigil
#

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

autumn trail
#

We're trying to correctly bill cancelled subscriptions
Here's what we do:

  1. Using webhooks, we know when a subscription was requested to be cancelled. We created an invoice immediately with auto_advance=false.
  2. 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

midnight vigil
#

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

autumn trail
#

It was $0 because we finalized it before we added items to it

midnight vigil
#

and then at the end you'd create the invoice for the pending invoice items (if you cancel the sub before it cancels itself)

autumn trail
#

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.

midnight vigil
#

Ah are you tracking the usage for that period yourself?

autumn trail
#

Yes

midnight vigil
#

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?

autumn trail
#

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.

midnight vigil
#

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

autumn trail
#

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?

midnight vigil
#

I'm not sure, let me check with someone about this

autumn trail
#

ok

surreal doveBOT