简体   繁体   中英

How to verify PayPal Express Checkout details on the server?

I'm just now trying to get up to speed with PayPal Express Checkout (ie checkout.js), using the client-side REST integration described here . I see that when payment is complete, my onAuthorize function is invoked with a "payment" object.

I can't find any documentation on this object, but some poking at it reveals the following properties (at least today):

  • paymentToken
  • payerID
  • paymentID
  • intent
  • returnUrl

Now I need to redirect the user to the next step on my website, where I show a receipt confirming they've paid, etc. I guess I send the above data to the server, but since that step could be easily spoofed by a malicious user, I will need to verify those details in the PHP code, server side.

How do I do that?

You can make a GET call on your server side to /v1/payments/payment/PAY-XXXXXX with the paymentID and the payerID to get the payment details, and verify those details there.

https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/advanced-payments-api/show-payment-details/

See https://developer.paypal.com/docs/api/overview/#make-your-first-call for some basics on calling the REST api from your server

Assuming you are using PayPal Encrypted Buttons , you don't actually need to verify the amounts sent through server-side. Although a user could indeed manipulate the $_POST data, PayPal's got you covered, and won't allow the transaction to go through. This is because PayPal Encrypted Buttons are generated with your variables such as price built-in to the ID. If the variables don't align with those used to create the button, the transaction is denied.

Alternatively, if you are simply using your own code to make the request, you can secure the payments with PayPal's Instant Payment Notification . Again, this allows any $_POST data to be sent through for the payment. Afterwards, PayPal makes a call to your IPN page in order to validate that the parameters are correct. This is demonstrated in the following workflow:

IPN流量

When communicating with your IPN, if PayPal finds that the values don't match up, the order is cancelled. Assuming that the values match up, you can safely redirect them to your confirmation page.

Hope this helps! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM