PayPal REST API v2/checkout/orders does not redirect back after approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
'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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Send request containing order detail to /v2/checkout/orders
- Get a response containing links
- 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)

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- subscription_id has disappeared in REST APIs
- Why does PayPal redirect to different pages (login vs credit card form) depending on browser mode? in Braintree Server-side Integration (PHP, Java, .NET, Ruby, Python, NodeJS SDKs)
- webhook payment capture completed issue in Sandbox Environment
- Paypal buttons and redirects in PayPal Payments Standard
- Help Resolving Declined PayPal Log In Application for Seller Authentication in REST APIs