#bspluca97-paymentintent-invoice

1 messages ยท Page 1 of 1 (latest)

clear folioBOT
keen nebula
#

Hi ๐Ÿ‘‹

spare hazel
#

Hi! THank you!

#

Can I create a payment intent starting from an invoice?

keen nebula
#

When an Invoices is finalized it creates a Payment Intent that you can then use to collect payment.

spare hazel
keen nebula
#

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

clear folioBOT
indigo kettle
#

bspluca97-paymentintent-invoice

spare hazel
#

Thank you! But when I finalize an invoice, is the payment intent also confirmed?

indigo kettle
#

@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

spare hazel
#

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
indigo kettle
spare hazel
#

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?

indigo kettle
#

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

spare hazel
#

But how do you usually suggest to implement the asynchronous flow?

indigo kettle
#

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?

spare hazel
#

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?

indigo kettle
#

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

spare hazel
#

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

indigo kettle
#

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

spare hazel
#

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! ๐Ÿ™

indigo kettle
#

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

spare hazel
#

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

indigo kettle
#

that is perfect

spare hazel
#

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

indigo kettle
#

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

spare hazel
#

Thank you again! I hope to have been 1/100 as helpful as you were to our team!