PayPal authorization link creates a loop within the same site without redirecting the user

Please note that the domain name has been replaced with the following App Return URL for testing purposes: http://domain.esy.es/index.php/users/paypalidentity. The view and controller for a successful login have been set up, and the user will be redirected to the predetermined URL upon login.
For those experiencing a similar problem, Solution 1 can be found in the documentation provided by PayPal. The link to follow for users in a web browser is:
After authorizing the order, the PayPal website is not redirecting anywhere and is instead looping back to the same form. Please refer to “Reloading Parent Page to a Specific URL” and add the suggested script to both the return and cancel pages.


Question:

My situation remains unsolved despite attempting workarounds. The PayPal website keeps redirecting me to the same form and the button labeled as CONTINUE instead of PAY NOW. Could this be a hint?

Below is an instance of the Postman API request and its corresponding response.

https://api.sandbox.paypal.com/v2/checkout/orders

Payload

    {
  "intent": "AUTHORIZE",
  "purchase_units": [
        {
          "amount": {
            "currency_code": "USD",
            "value": "100",
            "breakdown": {
                   "item_total":{
                                  "currency_code": "USD",
                                  "value": "100"
                   },
                   "shipping":{
                                  "currency_code": "USD",
                                  "value": "0"
                   },
                   "tax_total":{
                                  "currency_code": "USD",
                                "value": "0"
                   },
                   "shipping_discount":{
                                  "currency_code": "USD",
                                  "value": "0"
                   }
            }
          },
         
          "items": [
                   {
                   "name": "Item #1234",
                   "unit_amount":{
                                  "currency_code": "USD",
                                  "value": "100"
                   },
                   "tax": {
                                  "currency_code": "USD",
                                  "value": "0"
                   },
                   "quantity": "1",
                   "description": "Company Name",
                   "sku": "tel:+12065555555",
                   "custom": "My Custom Data"
          }]
        }
      ]
}

RESPONSE (201 – CREATED)

{
    "id": "8W523711V28300745",
    "status": "CREATED",
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v2/checkout/orders/8W523711V28300745",
            "rel": "self",
            "method": "GET"
        },
        {
            "href": "https://www.sandbox.paypal.com/checkoutnow?token=8W523711V28300745",
            "rel": "approve",
            "method": "GET"
        },
        {
            "href": "https://api.sandbox.paypal.com/v2/checkout/orders/8W523711V28300745",
            "rel": "update",
            "method": "PATCH"
        },
        {
            "href": "https://api.sandbox.paypal.com/v2/checkout/orders/8W523711V28300745/authorize",
            "rel": "authorize",
            "method": "POST"
        }
    ]
}

The URL that a user should click on in their browser is:

 https://www.sandbox.paypal.com/checkoutnow?token=8W523711V28300745

After authorizing the order on this link, the PayPal website seems to be stuck in a loop and not redirecting anywhere. Despite that, I still receive a notification confirming the approval. This repetitive loop may cause confusion for the user and hinder their overall experience.


Solution:

Assuming you are leading the user to

approval_url

, your initial API request must have contained

return_url

to inform PayPal where to send the customer upon approval. To successfully capture the order, it is imperative to receive a return after approval, or else no payment will be processed.

Optimal integration methods require zero redirects. Instead of redirecting the browser to the approval URL, simply generate the order and retrieve its

id

value. This value can be used to display a button, providing an in-context checkout experience while maintaining your site’s presence in the background (thus avoiding any redirection). Upon receiving buyer approval, an API call can be made to capture the order. A demo code is available at: https://developer.paypal.com/demo/checkout/#/pattern/server.

The process is straightforward and easy to follow. The concluding part primarily consists of tips related to handling errors after capturing.

Frequently Asked Questions

Posted in Uncategorized