Search code examples
paypalpaypal-rest-sdk

Paypal integration, how to use createOrder onApprove?


The paypal documentation here: https://developer.paypal.com/docs/business/checkout/set-up-standard-payments/

States that

Within createOrder and onApprove, call your server-side using the Fetch API to retrieve a token or capture a payment. Within createOrder, return the Order ID (or EC token) generated from your server-side code.

Are there are any examples of how to do this?

Thanks


Solution

  • Yes, they're documented here. These routes should return only JSON data (no HTML or text). The latter one should (on success) store the payment details in your database before it does the return (particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID)

    Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server