Is there any way to confirm paypal payemnt in server-side with accessToken getting from frontend?

ArsalRana18
New Community Member

I am trying to integrate paypal payment. I can integrate it in full frontend application. But My question is that, is it secure?

But I want to integrate it in different way. First of all I integrate paypal button in my frontside application. When User click That Button, it redirect to paypal website and user can pay. When user completed the payment, it give a accessToken or Id. Then I have to sent this accessToken or Id to my backend application.

In my backend application receive that accessToken or Id and Confirm the payment with amount, quantity or other secure data.

I think it is not secure to give amount from fronted to paypal.

Can anyone help or give any code example or tutorial. Please help me.

Login to Me Too
1 REPLY 1

malaikacheema
Contributor
Contributor

You should create the payment (order) on your backend, receive payer approval of it on your frontend, and then capture it on your backend.

Follow the Set up standard payments guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. Both routes should return only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.

Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server/site

If the amount is determined by your frontend then send that value as part of the post to get the created order, and have the server use it to create the order. The server should validate the amount and any cart contents before creating the order. You can send item information to PayPal, as detailed within the Set up standard payments guide linked above.

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.