PayPal REST API v2/checkout/orders does not redirect back after approval

AditiyaPanday5
Contributor
Contributor

've never used PayPal before, it's not really popular here, and I'm confused by how the order and payment works. Can anyone explain it to me? I've read the documentation and I'm still confused.

To complete payer approval, use the approve link to redirect the payer. The API caller has 3 hours (default setting, this which can be changed by your account manager to 24/48/72 hours to accommodate your use case) from the time the order is created, to redirect your payer. Once redirected, the API caller has 3 hours for the payer to approve the order and either authorize or capture the order.

I have created a working PHP curl call for this API in sandbox env according to the sample https://developer.paypal.com/docs/api/orders/v2/#orders_create

The APIs I created before work like this:

  1. Send a request to 3rd party payment
  2. Get a response containing a checkout link
  3. Redirect customer to link
  4. Customer complete payment
  5. 3rd party send a request containing order and payment detail to a file/path on my server
  6. My server receives the request and updates the order status/payment in my database
  7. 3rd party redirect the customer to my webpage

With PayPal, what I got so far is:

  1. Send request containing order detail to /v2/checkout/orders
  2. Get a response containing various links
  3. Redirect my customer to the rel:approve checkout link
  4. Log in to my sandbox customer account and pay using PayPal balance, click Continue
  5. A popup message is shown: We're sending you back to xxx's Test Store to complete this purchase
  6. The popup message is closed and I'm still at the same payment page with the Continue button as seen in the image

cUDgS.png

Login to Me Too
1 REPLY 1

wasqat
Contributor
Contributor
  1. Send request containing order detail to /v2/checkout/orders
  2. Get a response containing links
  3. Redirect my customer to approve link

Step (3) is an old integration method, for websites using an old redirect-based flow. The preferred way to integrate PayPal uses no redirects. At all. Your website remains loaded in the background. Do the following:

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/servers


If, for some odd and inexplicable reason, you insist on using the legacy flow with a full page redirect instead of what I just described above, you must include a redirect_url in your orders creation request, so that PayPal has somewhere to return to after the order is approved. Once such a return happens, present the customer with a review step on your site where they can give final approval, which should trigger the Capture Order API call to complete the transaction.

Capturing an order will return a v2/payments object which is the completed transaction with its own ID for accounting and refund purposes. (The order ID is only used during payer approval, and unimportant otherwise)

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.