Stripe and validate payments synchronously - stripe-payments

I am integrating Stripe in my site and I have the following question. I have read in the official documentation that is needed to use Payment Intents / Checkout to accomplish with 3d secure payments but my doubt is: How can I validate a payment made through this methods in a synchronous way to allow customers to instant download a product without waiting to the webhook call?
I am using Symfony to build the front and the back of the system.
thanks

You don't need to wait for a webhook to get confirmation that a payment was successful. stripe.handleCardPayment will immediately tell you if the payment was successful or not. See the then promise fulfillment here.
If you're using new Checkouts, users will be directed to your payment success page on completion of payment. A webhook is sent to inform you of the payment completion in case the user closes the browser or tab before the redirect can happen.

Related

How do I know if a payment is successfull in stripe

I have integrated the stripe Api in my website to process payments and It is working fine. The only problem is that after the a successfull payment, i don't get any response or an object to know if the payment is successful or not.
Stripe does process the payment and everything is fine but the question is how would I know that it is successful after stripe redirects the client to the success url ?
You can implement webhook in your application. After a payment is completed stripe will call webhook/callback of your application with the payment_status and other details. Have a look at documentation here Triggering actions with webhooks
Using webhooks and events is definitely the right way to go. You can listen for successful payments, failed payments, and other event types, then add some server code to take some action based on those events.
There's a mention of webhooks in Stripe's custom payments quickstart guide: https://stripe.com/docs/payments/quickstart#use-webhook
They also have a standalone webhooks guide: https://stripe.com/docs/webhooks/quickstart

Trying to link a stripe payment page to passion.io via webhooks

So I have a stripe payment page that allows customers to subscribe to a membership platform I use called passion.io.
I am trying to trigger on zapier that when the customer checks out using the stripe payment page, it fills an order on passion.io as a new customer and goes through the new customer process.
Currently Zapier doesnt let the check out of a specific payment page be its own unique trigger so they suggested I use webhooks as a work around but I know nothing about webhooks and am so confused on which event to use and how to set this up.
Any insight?

How to process payment on the backend side using Stripe?

I am new to Stripe and payments in general. I've found few articles on the internet with the examples and guidelines eg. this one. As i noticed the algorithm for creating the payment looks like this:
Client app fetches the publishable Stripe key from the server
Server application creates the checkout session, client app fetches the checkout session id using retrieved publishable key
Client app redirects to checkout
User finishes the payment and being redirect back to client app
Please correct me if i'm wrong. In general i don't understand one thing - how the server application knows that the payment is completed successfully or not? Should i redirect the flow from stripe checkout to backend first, process the result and the from the backend call the frontend again? Or should i somehow use the checkout session to check has it been completed? Shall i use some kind of cron then to process pending checkout sessions? Thanks in advance for any help. Regards
Basically, what you lay out is viable. You can check the Session status when the client is directed back to your server, but you will want to check this status at least one other way, either via a webhook or the cron job you mention.
Should i redirect the flow from stripe checkout to backend first, process the result and the from the backend call the frontend again?
This is possible. Stripe allows you to add the {CHECKOUT_SESSION_ID} template parameter to your Checkout's success URL, when the user is redirected after their checkout, that template will be replaced with the actual Checkout Session ID which you can use to retrieve the Session and its status.
That being said, it is possible for a Customer to make a payment but have their connection cut out before navigating back to your page. So, if you rely on that redirect the customer will be charged but you will never know to fulfill their order. That leads to unhappy customers so Stripe typically recommends setting up a webhook endpoint on your server[2] so that they can send you a checkout.session.completed event to notify you that the customer has finished their Checkout Session. That way, even if a customer never gets to your success page, you will know to fulfill their order.
[1] https://stripe.com/docs/payments/checkout/custom-success-page#modify-success-url
[2] https://stripe.com/docs/payments/checkout/fulfill-orders

How does a Checkout Page take the user input information and pass it to Stripe?

So far I've created a product modal and upon proceeding to checkout, Stripe popup appears and the user can proceed with the payment.
https://streamable.com/30p4eh
Although, I have to change the checkout button to popup a checkout page first so the user can enter his delivery address and so on. How does a checkout page deliver the information the user has input, into Stripe? How does the whole process work? Do I have to add all my products into Stripe product page? Can Stripes checkout page be used like in this Firebase video? Firebase
The Checkout payments guide now includes a nice diagram that I think should help understand what you're asking about.
You create a Checkout Session with the payment information and then redirect your customer to Stripe. Stripe displays the information about the purchase and collects payment information from your customer, then redirects them back to the URL you specify. In the background, you're notified about the success of the payment and you can manage order fulfillment.
If you need more information about a particular piece of this, please feel free to ask with more details!
Update: on a second review, I see that I missed that your video is showing the Legacy Checkout integration. Stripe has a new Checkout integration that supports a wide range of payment methods and supports SCA-compliant authentication challenges. Take a look at the migration guide to update your integration.

SaaS application using stripe - charge customers card before completing signup?

We are using Stripe subscriptions to handle payment for a SaaS application we are building
Currently, our development team has implemented the following logic:
User enters card details into Stripe elements UI as the final step of signup to our app.
If the credit card is deemed valid by Stripe Elements, the signup process to our app completes successfully.
A stripe customer & subscription is created.
Our server processes the webhook from stripe to confirm if the initial payment succeeds/fails
The problem we have is that the customers card isn't being charged until after the signup process to our app is complete. In some cases this results in a poor user experience, where the user is told by our signup process that they have signed up successfully, then they receive a 'payment failed' email from our software if the stripe charge doesn't succeed.
What is the best way to handle this signup flow? Since we are relying on the stripe webhook to tell us if the charge has succeeded - a suggestion has been made that we could monitor for the webhook response (eg. every 1 second, in a loop) and confirm payment has succeeded before completing the user signup for our app. The flow would then become:
User enters card details into Stripe elements UI as the final step of signup to our app.
If the credit card is deemed valid by Stripe Elements, we create the stripe customer / subscription
Monitor (in a loop) for a response from the Stripe webhook to confirm if payment was successful
The signup process to our app completes successfully (if charge is successful), or fails if the charge is unsuccessful.
This also seems like a bandaid solution - what is the best way to handle our issue?
I have noticed there is an option to use 'pre-authorisation' of a card, but I'd prefer not to go down this road if it leads to extra items on a customers bank statement.
This seems like something that would be very common - we would greatly appreciate any advice
Thanks
The most straightforward solution seems to be that your integration isn't waiting for the payment to complete.
With Subscription, you can wait synchronously on your backend for a status: active on your backend, before returning a response to your frontend. You don't even need to poll for the webhook response, cause your backend creates a Customer, creates a Subscription, and returns that response to your frontend, to show an error or success.
(waiting for webhooks is good but when your integration is manually starting the Subscription, you don't necessarily need webhooks)
From the frontend perspective, your user sees a loading spinner, until your backend is able to say "payment successful, you are signed up!"

Resources