Home > Software design >  server side code for payment gateway integration with flutter
server side code for payment gateway integration with flutter

Time:09-21

I'm trying to integrate a payment gateway like razorpay or stripe in my flutter app, and for any payment provider we need to generate a token using their API in the backend , but none of these payment providers have mentioned the code for the server side to generate tokens and how/where to deploy that server side code. Essentially I'm creating an ecommerce app and to process payments I can't find resources to implement the server side code for each cart order. Can anyone tell how to implement the server side code or some resource which could be useful?

Docs I have read:

https://pub.dev/packages/razorpay_flutter

https://razorpay.com/docs/payments/payment-gateway/flutter-integration/standard/build-integration#16-create-an-order-in-server

CodePudding user response:

but none of these payment providers have mentioned the code for the server side to generate tokens and how/where to deploy that server side code

This is by design. Payment providers help you lower your PCI compliance burden by not touching raw card details. If you use frontend SDKs (like Stripe's Stripe.js Elements UI library), they are an iframe that collects your end customer card details directly to their servers meaning your integration does not touch card details and does not have to do tons of paperwork on your own PCI compliance.

https://stripe.com/docs/security/guide

https://stripe.com/guides/pci-compliance

So you absolutely need to use their frontend SDKs to directly create a token from your webpage.

I can't find resources to implement the server side code for each cart order.

Once you have your token, you then send that to your server to create an order and (in Stripe's case) create and confirm a PaymentIntent. Though Stripe's recommended flow is a bit different - you create the PaymentIntent first and "confirm" it on your frontend: https://stripe.com/docs/payments/accept-a-payment

CodePudding user response:

I don't not much idea about Razorpay integration but for Stripe you can use Payment Intent API.

You can divide the process in 3 steps:

  1. Send card details from Front-end, if it's a Stripe Customer then you can even use their default card.
  2. Create a payment Intent in Backend, this will return a payment intent object with client_secret. You also might wanna save the payment intent id in DB.
  3. Send this client_secret to Frontend, where you can use this client secret in Stripe.confirmCardPayment(client_secret).
  4. Listen to webhook events to check on the payment status/progress. It's basically an open endpoint where stripe will make REST calls and provide you with details about your payment progress.

Here's a link to the docs mentioning this process. There was an even better doc/github link that I can't seem to find, it had the entire end-to-end happy process.

If this seems a bit complicated then you go with checkout API of Stripe. I've also attached a few youtube videos that might help ya in getting started.

Checkout API YT link
Payment Intent YT link

  • Related