skip to Main Content

I am using Paypal Rest API in website.
The challenge is I am being stuck at "Continue to Review Order" Button. When I am clicking it infinitely directing to same URL

enter image description here

Find the code below:

$postFields = json_encode(array(
        'intent' => 'CAPTURE',
        'purchase_units' => array(
            array(
                'amount' => array(
                    'currency_code' => $currency,
                    'value' => $amount
                ),
                'payee' => array(
                    'email_address' => '[email protected]', //                    
                ),
                'payer' => array(                  
                    'email_address' => '[email protected]' // Payer's email address from session
                ),
                'application_context' => array(                   
                    'user_action' => 'PAY_NOW',
                    'return_url' => 'http://localhost/paypal_success.php?order_id=' . $orderId,
                    'cancel_url' => 'http://localhost/cancel.php'
                )
            )
        )
    ));

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $paypalApiUrl);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    echo '<script>';
    echo 'console.log(' . json_encode($response) . ');';
    echo '</script>';

Its opening a page but not going to next screen to review.I am not even getting anything in $response

2

Answers


  1. Either:

    1. Use the JS SDK for in-context approval. Do not redirect away from your site. (best solution)
    2. Add a return URL in the correct place when creating the order. It does not belong inside purchase_units, and will be ignored there. application_context is also a deprecated parameter anyway.
    Login or Signup to reply.
  2. $postFields = json_encode(array(
            'intent' => 'CAPTURE',
            'purchase_units' => array(
                array(
                    'amount' => array(
                        'currency_code' => $currency,
                        'value' => $amount
                    ),
                    'payee' => array(
                        'email_address' => '[email protected]', //                    
                    ),
                    'payer' => array(                  
                        'email_address' => '[email protected]' // Payer's email address from session
                    ),
                    'application_context' => array(                   
                        'user_action' => 'PAY_NOW',
                        'return_url' => 'http://localhost/paypal_success.php?order_id=' . $orderId,
                        'cancel_url' => 'http://localhost/cancel.php'
                    )
                )
            )
        ));
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $paypalApiUrl);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
        $response = curl_exec($ch);
        echo '<script>';
        echo 'console.log(' . json_encode($response) . ');';
        echo '</script>';
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search