0

Paypal: Unable to Reauthorize Authorized Payment

Below is my code

$clientId = 'XXXXX';
$secret = 'XXXX';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId . ":" . $secret);
$result = curl_exec($ch);

if (empty($result)) {
    die("Error: No response.");
} else {
    $json = json_decode($result);
    //echo "<pre>";
    //print_r($json);
    //exit;
    $token_type = $json->token_type;
    $access_token = $json->access_token;
    $nonce = $json->nonce;

    //echo "Authorization: " . $token_type . " " . $access_token;

    if (!empty($token_type) && !empty($access_token)) {

        // START REAUTHORIZE PAYMENT
        $authorizationId = 'AF998724VR277443T';
        $currency = 'USD';
        $amount = '20.00';
        $data = '{
                    "amount": {
                    "total": "' . $amount . '",                     
                    "currency": "' . $currency . '"

                    }
                };';


        $ch1 = curl_init();
        curl_setopt($ch1, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/authorization/" . $authorizationId . "/reauthorize");
        curl_setopt($ch1, CURLOPT_POST, true);
        curl_setopt($ch1, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch1, CURLOPT_HTTPHEADER, array(
            "Content-Type: application/json",
            "Authorization: " . $token_type . " " . $access_token,
            "Content-length: " . strlen($data))
        );

        $result1 = curl_exec($ch1);
        if (empty($result1)) {
            die("Error: No response.");
        } else {
            $json1 = json_decode($result1);
            echo "<pre>";
            print_r($json1);
            exit;
            //echo $json1->id;
        }
        // END REAUTHORIZE PAYMENT
    }
}

It gives below error

stdClass Object
(
    [name] => INTERNAL_SERVICE_ERROR
    [message] => An internal service error occurred.
    [information_link] => https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR
    [debug_id] => b220155a9c70e
)

https://developer.paypal.com/docs/api/payments/#authorization_reauthorize

What i'm missing. I'm running above code on WAMP.

As per Paypal :

After the three-day honor period authorization expires, you can reauthorize the payment.

Jackson
  • 1,426
  • 3
  • 27
  • 60

2 Answers2

0

It looks like the authorization id is already reauthorized and still inside the honor period. Hence PayPal is not allowing the Reauthorization. You may try again after the honor period expire.

PP_Punna
  • 426
  • 3
  • 7
  • The authorization id is already reauthorized and the reauthorized id is still inside the honor period. – PP_Punna Apr 25 '17 at 04:25
  • Checked with Paypal it's already Reauthorized. But still issue with above code which is not giving result – Jackson Apr 28 '17 at 03:09
0

Add

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

HTTPS link, could be related to your problem

Anyone_ph
  • 616
  • 6
  • 15
  • Try curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); In both curl_init() – Anyone_ph May 03 '17 at 10:31