#bspluca97-paymentintent-invoice
1 messages ยท Page 1 of 1 (latest)
Hi ๐
You cannot generate an Invoice after the fact, You would need to start by generating an Invoice and then collecting payment.
https://stripe.com/docs/invoicing/overview
When an Invoices is finalized it creates a Payment Intent that you can then use to collect payment.
It's a property of the Invoice object.
https://stripe.com/docs/api/invoices/object#invoice_object-payment_intent
We have a quickstart sample integration you can get started tinkering with here: https://stripe.com/docs/invoicing/integration/quickstart
After the invoice step, can I follow the tutorial here https://stripe.com/docs/payments/accept-a-payment-synchronously ?
Yes, you would need to expand the payment_intent property when you create the Invoice so you can return the payment_intent.client_secret.
https://stripe.com/docs/expand
bspluca97-paymentintent-invoice
Thank you! But when I finalize an invoice, is the payment intent also confirmed?
@spare hazel no it's not on finalization. It can be confirmed later. Ultimately the Invoice API is not compatible with that "synchronous" flow so you would be able to do this
What do you mean is NOT compatible?
Can't I:
- Create invoice
- Finalize
- Try to confirm payment intent
- If error, send to the client the client_secret to do stuff
- If success, happy
https://stripe.com/docs/payments/accept-a-payment-synchronously specifically uses confirmation_method: 'manual' on PaymentIntent. This is not going to work with Invoices, that's impossible.
As long as you're okay with that, it's fine.
ouch! As a feedback, it would have been great to specify if in the documentation before implementing the flow ๐
What do you suggest as an alternative? The client confirms the payment intent? But how can I know of the result without a webhook?
This flow is extremely discouraged, it's not listen in the sidebar, it's an advanced flow usually for old integrations that want to move from /v1/charges to /v1/payment_intents without re-designing their entire flow.
My advice is to completely move away for the "synchronous flow" as it's almost always a bad choice
But how do you usually suggest to implement the asynchronous flow?
And you have to use webhooks. Really the assumption that you don't is mostly wrong. Even with the synchronous flow you have to
Like what if your code literally crashed right after the call to confirm?
Yeah yeah but we have the flow wrapped in a retried worker
we wouldn't lose the message
But I agree with you
Thank you!
In the asynchronous flow basically we have to have a sort-of polling mechanism to let the client know when the invoice went through, right?
the goal of the asynchronous flow is mostly to get you started on PaymentIntent and then to quickly realize "omg there are so many things I wish I could do byt I can't use this flow" but by then most of your integration is ready
So my advice is to switch off of that, implement webhooks, and you can always have the client tell you about success, you don't have to wait for the webhook
What do you mean with you can always have the client tell you about success ?
Ah you mean the client contacts me telling everything is okay, if something fails I still have webhook
Most developers (and people at Stripe) misunderstand how this works
everyone thinks Webhooks are the only way
But they aren't. They are required to avoid missing payments. But most of the integrations don't need them in the normal flow
1/ (server-side) Create a PaymentIntent
2/ (client-side) Confirm the PaymentIntent
3/ After the confirmation, have it redirect to your server where you look at the state/payment and then do fulfillment
4/ Additionally, listen to webhooks so that if #3 failed (closed the browser, network error, crash) you don't miss the payment and can still do fulfillment
If you use our newer PaymentElement UI element https://stripe.com/docs/payments/payment-element it has a built-in "redirect" logic that makes this a lot more obvious (though people are still often confused and think the code has to "wait for the webhook delivery")
does that make a bit more sense? It's definitely a "shift" from the old world of "my PHP code confirms the PaymentIntent and I know for sure synchronously if money moved" but it opens up so much value like new payment methods
You are an angel!
You literally made it so much more clear. Makes a lot of sense, I don't think it will be too bad to implement either
Thank you and have a great easter! ๐
Do you have a few minutes to chat?
Basically I have been explaining this idea for years at this point but I don't really understand what part of our docs don't make it obvious that this is how you build that integration. I'd love to understand what I said explicitly than made you go ๐ก
I so want our docs to convey this idea ๐
For sure!
Let me take a look so I can point it out
First of all this image - I know what you said makes a lot of sense and on hindsight seems the only way, but from this image, it seems like the communication of succeeded payments (from client to server) should happen through webhooks. This made me think "Oh, so I need polling! Let's look somewhere else for a super-quick prototype"
Even in the guide, it seems that the fullfillment should be "accepted" thorugh webhooks, when after you said it it's obvious that the system using polling works way better
What about adding an intermediate step where the client communicates to the server "ehy, the payment succeeded" and the server checks on Stripe the authenticity of this? (This is what I'd do). This avoid to rely on webhooks for accepting payment, but still we will have webhooks for failed attempts
that is perfect
I get though that this increases the complexity of the doc, even if I think it's going to be ultimately what most devs are gonna do
I can share that conversations with our Docs team to mull over now, thank you so much for taking the time
but yeah, the "webhooks required" part turns off most devs, even if they are familiar with webhooks. We just haven't found the right "wording/diagram" to make it click the way I explain it
Thank you again! I hope to have been 1/100 as helpful as you were to our team!