#Mijelz-payment-intent
1 messages ยท Page 1 of 1 (latest)
Hi River
How do you collect payment method details currently?
Hey actually I havent started yet, I've just been watching guide and reading the docs
Im running firebase cloud functions for my backend so thats basically my 'server'
where I create the PI and stuff I assume
Im using elements
react elements
Maybe to make it clearer idk if this is possible but I would like it so that when the customer hits "pay" or w/e, it hits my backend that handles talking to stripe and then if stripe says "ok the card was charged its all good" then I can within that same API function write to the DB (fulfilling the order). Returns response to my frontend that I can deal with, as long as I can confirm the card was charged in my api call.
If it fails I can return to my frontend the error message and handle the UI
We generally don't recommend synchronous fulfilment/post-payment actions like that
Instead, you should rely on webhooks
I can rely on webhooks, I'd just have to setup a cronjob to clear out abandoned purchases
Is it not possible to do synchronous with stripe though?
It makes it a lot easier for me to build out the frontend if I can just hit one endpoint and get a response than wait on a webhook
Well, it is. But there's no guarantee your user stays on-session after payment for the post-payment actions to be completed
I see, but I don't think I have any reason for the user to stay on session. Once the purchase is confirmed within that same function I can write to the DB fulfilling the order. Do you have a guide somewhere I can see how to do it sync?
You mentioned front-end, maybe I misinterpreted what you meant
How do you intend to handle 3DS?
I wanna use the PaymentElement, or if I can't the CardElement
so I think stripe will put the modal for me and handle it
As far as I understand I need to create a PI on my server -> sends that to frontend to stripe elements -> user clicks pay and then ... idk im lost after that
Right, so that's front-end confirmation. I'm confused how your backend is performing confirmation in this instance
Exactly. Which is why you should use webhooks. What is after they're redirected to the bank for 3DS, they close your page before you can fire a backend request to your server to fulfil the payment?
At that point they've paid, but your application has no knowledge of it
Oh I see I thought it was possible to just send the entire request to my backend
Instead you'd rely on payment_intent.succeeded events and action them
Well you can do server-side confirmation: https://stripe.com/docs/payments/finalize-payments-on-the-server
So in that case I have to do webhooks and I would just write like the documentID in the dbase in the metadata field somewhere? I assume the webhook can send that to me so I know which to set "fullyPaid:true"
But I don't think its necessary in your use case
And we still recommend webhooks for fulfilment
Yep, you could use metadata to reconcile the payment with your backend
That works, I'd just have to save the data to the db in an 'unpaid' state. The best idea I have to just run a cron weekly and anything older than X date gets deleted.
Which part do I add the metadata to, the PI right?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
You wouldn't need to really persist any unpaid PIs to your backend
Ahh I should just explain a bit its not the PI its the thing we sell
We sell certificates for like continuing edu etc
so I have to save on that certificate that its unpaid and when the webhook returns 'paid' I flip the state and then can show it to the customer
thats ok tho its nbd
I'd make a call to save the data in the form submit handler for the Elements
Got it
ty I will review this and hopefully get it integrated
np!