#sahil-invoice-finalization
1 messages · Page 1 of 1 (latest)
Hi, can you share the request id where you're making this call? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request so I can further look into this.
From the context you shared above, it looks like you'd want to set auto_advance to true when you create the Invoice in the first place. However, I'm not entirely sure what you're exactly doing and why. For this reason, it would also be helpful if you can add bit more context there as well.
i think it is this one req_6Zob6O7LwL3n6m
also i forgot to mention,
it does not work when i call the finalize invoice request during the webhook call,
but it works after sometime when i call the
stripeAPI.invoices.update(stripeInvoice.id, {
auto_advance: true
})
Can you share more details on why and what you're trying to do exactly?
so,
what i want to do when once a invoice is created in stripe , i also store the invoice id into my database
once i know the invoice id is stored into my DB, i immediately finalize the invoice
and all this happens during "invoice.created" event
sahil-invoice-finalization
@carmine phoenix what's the problem though? Finalizing an Invoice doesn't immediately trigger a payment, so what exactly is/isn't working? Also why are you doing this in the invoice.created Event if you are creating the Invoice yourself?
i dont want to setup cron jobs myself, so that's why i am using stripe's invoice events
and yes, i know stripe attempts to pay the invoice extacly after 1 hr after finalization
but in my case, i am passing "auto_advance" : true but stripe still isn't attempting
also i'm creating invoices my own invoice, is there a better way to do without using stripe's invoice ? (for recurrent subscriptions)
I'm sorry I'm really struggling to follow what you're describing as you seem to say opposite things. You said you don't want a cron job. But also say you create Invoices yourself.
Are you actively creating an Invoice using the Create Invoice API https://docs.stripe.com/api/invoices/create or are you using our Billing product and creating a Subscription that renews automatically for you and create the Invoice(s) for you?
I am using your billing product and creating recurrent subscriptions
this subscription automatically creates the invoices and sends me a event
and i said i dont want to setup cron jobs my self is because it's a difficult to manage the subscription's life cycle with stripe
Okay so why are you finalizing the Invoice exactly? What is your goal there?
The request id you gave earlier is about a Subscription creation and the first Invoice is always finalized for a Subscription creation with collection_method: "charge_automatically"
the reason i am finalizing the invoice is because stripe wasn't automatically attempting the payment
so i thought manually finalizing would do the job
Okay let's take 10 steps back. Can you give me an example Invoice id you finalized and it still wasn't attempted?
I am already setting the collection_method to "charge_automatically"
I know, that's why I said what I said
Sorry we're talking a bit past each other. Let's ignore everything for now and give me an exact Invoice id that wasn't paid after you finalized it so I can look at it
that's the first Invoice on the Subscription creation right? That Invoice is already finalized so what you do in your webhook handler won't work. It likely even returned a clear error telling you that
But okay that explains the entire confusion here. You're misunderstanding the state machine of a Subscription at the moment. Your code is explicitly passing payment_behavior: "default_incomplete". What this means is "please don't do anything with that Invoice, I will handle it myself client-side"
Your code is supposed to look at that Invoice's PaymentIntent and confirm it client-side while collecting payment method details. So that Invoice will never "auto-advance" in that specific flow
what I just explained in my paragraph
99% of integrations will create the Subscription like you did, then get that Invoice's PaymentIntent, use its client_secret, to render PaymentElement client-side to collect payment method details and confirm the PaymentIntent.
Is that not what you are doing? If not, what exactly are you doing?
no that's not im currently doing,
instead, i'm using setup intent to collect user's credit / debit card for future use
so at the time of invoice finalization, the customer will have atleast 1 card attached
and there will be a default payment method / card
Okay but that is a fairly discouraged approach.
So what you want is remove the payment_behavior from your code then and it wil automatically attempt the payment upfront.
But really you should flip your integration completely to never use SetupIntents if you are immediately charging their card
i see, i'll try to remove payment behaviour
i used setup intent because i had no choice left, i need customer to have atleast 1 payment method before creating subscription
okay, is it possible to collect card for future use and charge the customer immediatly ?
I mean you don't, there are many ways to integrate Stripe and the way you are using is really discouraged and has been for many years
- Create the Subscription
- Collect payment method details client-side to pay the first Invoice.
No reason to do anything else with a SetupIntent first
Alternatively
- Collect payment method details without a SetupIntent
- Create a Subscription after that step
- Confirm the underlying PaymentIntent
See https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=subscription
i see, so this also sets up the payment method for future use?
ie. will stripe automatically attempt payment for the next invoice of the recurrent subscription ?
yes
Use this specifically for that: https://docs.stripe.com/api/subscriptions/create#create_subscription-payment_settings-save_default_payment_method
even if the payment method was later replaced with other payment method?