'PayPal REST API v2/checkout/orders does not redirect back after approval
I'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:
- Send a request to 3rd party payment
- Get a response containing a checkout link
- Redirect customer to link
- Customer complete payment
- 3rd party send a request containing order and payment detail to a file/path on my server
- My server receives the request and updates the order status/payment in my database
- 3rd party redirect the customer to my webpage
With PayPal, what I got so far is:
- Send request containing order detail to /v2/checkout/orders
- Get a response containing various links
- Redirect my customer to the rel:approve checkout link
- Log in to my sandbox customer account and pay using PayPal balance, click Continue
- A popup message is shown: We're sending you back to xxx's Test Store to complete this purchase
- The popup message is closed and I'm still at the same payment page with the Continue button as seen in the image
Solution 1:[1]
I had this issue too, and I eventually got a solution from the documentation.
You have to add application_context.return_url to your request.
Attached is an example in PHP:
$postData = [
"intent" => "CAPTURE",
"purchase_units" => $purchase_units,
"application_context" => [
"return_url" => "",
"cancel_url" => "",
],
];
You can make a whole lot of customisations to the PayPal Payment page by adding the Application Context option, For a full list of the possible customisations, you can check up the official documentation Application Context Documentation
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ayemileto |

