PayPal DoExpressCheckout API in sandbox always returns 10422 or 10486 error

good-one
Contributor
Contributor

In sandbox, DoExpressCheckout API via PHP always returns 10422 or 10486 error codes when only paying by a credit card. This means it works correctly when sandbox account's PayPal balance is enough to pay for an item.

I suspect there are problems in my sandbox account setting or my php code.

Is there anyone have clues to a solution to this problem?


My PHP code here.

<?php

/** DoExpressCheckoutPayment NVP example; last modified 08MAY23.
 *
 *  Complete an Express Checkout transaction. 
*/require_once('paypal_configure.php'); // API settings

// Set request-specific fields.$environment = ENVIRONMENT;  // sandbox$paymentType = urlencode("Authorization"); // or 'Sale' or 'Order'$currencyID  = urlencode(CURRENCY);

// Set parameter$token         = urlencode($argv[1]);$payerID       = urlencode($argv[2]);$paymentAmount = urlencode($argv[3]);$invNum        = urlencode($argv[4]);

/**
 * Send HTTP POST Request
 *
 * @param   string  The API method name
 * @param   string  The POST Message fields in &name=value pair format
 * @return  array   Parsed HTTP Response body
 */
function PPHttpPost($methodName_, $nvpStr_) {
    global $environment;

    // Set up your API credentials, PayPal end point, and API version.    $API_UserName  = urlencode(API_USERNAME);    $API_Password  = urlencode(API_PASSWORD);    $API_Signature = urlencode(API_SIGNATURE);    $API_Endpoint  = "https://api-3t.paypal.com/nvp";
    if("sandbox" === $environment || "beta-sandbox" === $environment) {        $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
    }    $version = urlencode('51.0');

    // setting the curl parameters.    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $API_Endpoint);    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    // Set the curl parameters.    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_POST, 1);

    // Set the API operation, version, and API signature in the request.    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

    // Set the request as a POST FIELD for curl.    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    // Get response from the server.    $httpResponse = curl_exec($ch);

    if(!$httpResponse) {
        exit('$methodName_ failed: '.curl_error($ch).'('.curl_errno($ch).')');
    }

    // Extract the response details.    $httpResponseAr = explode("&", $httpResponse);    $httpParsedResponseAr = array();
    foreach ($httpResponseAr as $i => $value) {        $tmpAr = explode("=", $value);
        if(sizeof($tmpAr) > 1) {            $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
        }
    }

    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
        exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
    }

    return $httpParsedResponseAr;
}

/**
 * This example assumes that a token was obtained from the SetExpressCheckout API call.
 * This example also assumes that a payerID was obtained from the SetExpressCheckout API call
 * or from the GetExpressCheckoutDetails API call.
 */

// Add request-specific fields to the request string.$nvpStr  = "&TOKEN=$token&PAYERID=$payerID&PAYMENTACTION=$paymentType&AMT=$paymentAmount&CURRENCYCODE=$currencyID";$nvpStr .= "&INVNUM=$invNum";
// Execute the API operation; see the PPHttpPost function above.$httpParsedResponseAr = PPHttpPost('DoExpressCheckoutPayment', $nvpStr);

// result$resAck  = strtoupper($httpParsedResponseAr["ACK"]);$resTime = urldecode($httpParsedResponseAr["TIMESTAMP"]);

if( $resAck == "SUCCESS" || $resAck == "SUCCESSWITHWARNING" ) {
        // get result        $resCode   = "10000";        $resMsg    = "_";        $resTranid = urldecode($httpParsedResponseAr["TRANSACTIONID"]);        $resAmount = urldecode($httpParsedResponseAr["AMT"]);
}
else {
        // get result        $resCode   = $httpParsedResponseAr["L_ERRORCODE0"];        $resMsg    = mb_ereg_replace(" ","###SPACE###",urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]));        $resTranid = "_";        $resAmount = "_";
}

// return text$rtnText  = "";$rtnText  =     $resAck;$rtnText .= " ".$resCode;$rtnText .= " ".$resMsg;$rtnText .= " ".$resTranid;$rtnText .= " ".$resAmount;$rtnText .= " ".$token;$rtnText .= " ".$payerID;$rtnText .= " ".$invNum;$rtnText .= " ".$resTime;$rtnText .= "\n";echo $rtnText;
exit(0);

?>

 

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.