php - Sandbox PayPal approval link leads to dashboard instead of payment after logging in


I am using PayPal REST API in sandbox mode to test payments.

I create the approval link, then redirect user to said link.

PayPal then asks for credentials which I insert as a sandbox test buyer. But after logging in, PayPal does not redirect me to complete the approval of payment, and instead straight to My Account summary from where I cannot approve the payment. However if the user was already logged in, the payment approval proceeds as expected.

Is it the problem with how was the link created or is it a bug?

This is the code used to create the link

use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;

class PaypalFactory
private const CLIENT_ID = 'yyy';
private const CLIENT_SECRET = 'xxx';

private function __construct()

public static final function getContext()
    return new ApiContext(
        new OAuthTokenCredential(

public static final function createPaymentLink(
    int $orderId,
    string $currency,
    float $totalPrice,
    float $deliveryPrice,
    string $returnUrl,
    string $cancelUrl): string
    $payer = new Payer();

    $details = new Details();

    $item = new Item();
        ->setName('products and shipping')

    $itemList = new ItemList();

    $amount = new Amount();
        ->setTotal($totalPrice + $deliveryPrice)

    $transaction = new Transaction();
        ->setDescription("Products from ")

    $redirectUrls = new RedirectUrls();

    $payment = new Payment();

    try {
    } catch (Exception $ex) {
        print $ex;

    return $payment->getApprovalLink();




Purging all browser cookies for paypal domains is good advice, and may help. The problem you're experiencing is probably a general sandbox issue (that won't happen in live mode), and not a problem with your code.

However, seeing your code/solution, I do have suggestions for trying some newer/better things:

  1. Instead of the old PayPal-PHP-SDK for v1/payments, use the new Checkout-PHP-SDK for v2/orders
  2. Instead of redirecting the buyer to the approval URL, give the approval token to the Javascript code of Smart Payment Buttons, which will display an in-context window that keeps your site loaded in the background. Here's a demo pattern

People are also looking for solutions to the problem: php - FacadeIgnitionExceptionsViewException?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.