使用paypal Express Checkout Curls函数获取GetRecurringPaymentsProfileDetails

时间:2016-10-29 13:27:19

标签: php curl paypal

您好我正在获得定期付款资料详细信息,但这不适用于我的所有功能

Echo Profile id(I-9DEF0R5BAGTX)正在显示但无法使用功能

Array ( [TIMESTAMP] => 2016-10-29T13:15:39Z [CORRELATIONID] => 2b31d73fc8140 [ACK] => Failure [VERSION] => 64 [BUILD] => 24616352 [L_ERRORCODE0] => 11551 [L_ERRORCODE1] => 11552 [L_SHORTMESSAGE0] => Profile Id is missing from the request [L_SHORTMESSAGE1] => Invalid profile ID [L_LONGMESSAGE0] => Profile Id is missing from the request [L_LONGMESSAGE1] => The profile ID is invalid [L_SEVERITYCODE0] => Error [L_SEVERITYCODE1] => Error )
GetRecurringPaymentsProfileDetails API call failed. Detailed Error Message: Profile Id is missing from the requestShort Error Message: Profile Id is missing from the requestError Code: 11551Error Severity Code: Error

Paypal库函数

$PROXY_HOST = '127.0.0.1';
$PROXY_PORT = '808';

global $redux_demo; 
$paypal_api_environment = $redux_demo['paypal_api_environment'];
$paypal_success = $redux_demo['paypal_success'];
$paypal_fail = $redux_demo['paypal_fail'];
$paypal_api_username = $redux_demo['paypal_api_username'];
$paypal_api_password = $redux_demo['paypal_api_password'];
$paypal_api_signature = $redux_demo['paypal_api_signature'];

if ( $paypal_api_environment == '1' ){
    $SandboxFlag = true;
}else{
    $SandboxFlag = false;
}

    //'------------------------------------
//' PayPal API Credentials
//' Replace <API_USERNAME> with your API Username
//' Replace <API_PASSWORD> with your API Password
//' Replace <API_SIGNATURE> with your Signature
//'------------------------------------

    $API_UserName=$paypal_api_username;
    $API_Password=$paypal_api_password;
    $API_Signature=$paypal_api_signature;

// BN Code  is only applicable for partners
$sBNCode = "PP-ECWizard";


if ($SandboxFlag == true) 
{
    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
    $PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
}
else
{
    $API_Endpoint = "https://api-3t.paypal.com/nvp";
    $PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
}

$USE_PROXY = false;
$version="64";


function GetProfileRecurring( $profileid )
{
    //Construct the parameter string that describes GetRecurringPaymentsProfileDetails
    $nvpstr = "&PROFILEID=" . $paymentAmount;

    $resArray=hash_calls("GetRecurringPaymentsProfileDetails", $nvpstr);

    return $resArray;
}

function hash_calls($methodName,$nvpStr)
{
    //declaring of global variables
    global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
    global $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
    global $gv_ApiErrorURL;
    global $sBNCode;

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

    //turning off the server and peer verification(TrustManager Concept).
    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);

    //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
   //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php 
    if($USE_PROXY)
        curl_setopt ($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT); 

    //NVPRequest for submitting to server
    $nvpreq="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($version) . "&PWD=" . urlencode($API_Password) . "&USER=" . urlencode($API_UserName) . "&SIGNATURE=" . urlencode($API_Signature) . $nvpStr . "&BUTTONSOURCE=" . urlencode($sBNCode);


    //setting the nvpreq as POST FIELD to curl
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    //getting response from server
    $response = curl_exec($ch);

    //convrting NVPResponse to an Associative Array
    $nvpResArray=deformatNVPs($response);
    $nvpReqArray=deformatNVPs($nvpreq);
    $_SESSION['nvpReqArray']=$nvpReqArray;

    if (curl_errno($ch)) 
    {
        // moving to display page to display curl errors
          $_SESSION['curl_error_no']=curl_errno($ch) ;
          $_SESSION['curl_error_msg']=curl_error($ch);

          //Execute the Error handling module to display errors. 
    } 
    else 
    {
         //closing the curl
        curl_close($ch);
    }

    return $nvpResArray;
}

    function deformatNVPs($nvpstr)
{
    $intial=0;
    $nvpArray = array();

    while(strlen($nvpstr))
    {
        //postion of Key
        $keypos= strpos($nvpstr,'=');
        //position of value
        $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);

        /*getting the Key and Value values and storing in a Associative Array*/
        $keyval=substr($nvpstr,$intial,$keypos);
        $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
        //decoding the respose
        $nvpArray[urldecode($keyval)] =urldecode( $valval);
        $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
     }
    return $nvpArray;
}

这是动作函数RunProfileRecurring

add_action('wp','RunProfileRecurring');
function RunProfileRecurring(){
    global $wpdb;
    $result = $wpdb->get_results( "SELECT * FROM wpcads_paypal ORDER BY main_id DESC" );
        if (!empty($result )){
            foreach ( $result as $key => $row ) {
                if ($row->pay_check == 'recurring' && $row->p_profileid != ''){
                    echo $row->p_profileid;
                    $profileid = $row->p_profileid ;
                    $resArray = GetProfileRecurring($profileid);
                    print_r($resArray);
                    $ack = strtoupper($resArray["ACK"]);
                    if( $ack == "SUCCESS" || $ack == "SUCESSWITHWARNING") 
                    {
                        echo 'Response Ok' ;

                    }else{
                        //Display a user friendly Error on the page using any of the following error information returned by PayPal
                        $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
                        $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
                        $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
                        $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
                        echo "<div>GetRecurringPaymentsProfileDetails API call failed. ";
                        echo "Detailed Error Message: " . $ErrorLongMsg;
                        echo "Short Error Message: " . $ErrorShortMsg;
                        echo "Error Code: " . $ErrorCode;
                        echo "Error Severity Code: " . $ErrorSeverityCode."</div>";
                    }
                }else{
                }
            }
        }
}

的var_dump     这是我回应的配置文件 - &gt; I-GS6BRWYTM2BC,这是var_dump    string(218)“METHOD = GetRecurringPaymentsProfileDetails&amp; VERSION = 64&amp; PWD = mycorrectpassword&amp; USER = pfmmod_1360821006_biz_api1.gmail.com&amp; SIGNATURE = mycorrectsign&amp; PROFILEID =&amp; BUTTONSOURCE = PP-ECWizard”Array([TIMESTAMP] =&gt; 2016-11 -02T08:04:13Z [CORRELATIONID] =&gt; 222af821e510f [ACK] =&gt;失败[VERSION] =&gt; 64 [BUILD] =&gt; 24616352 [L_ERRORCODE0] =&gt; 11551 [L_ERRORCODE1] =&gt; 11552 [L_SHORTMESSAGE0 ] =&gt;请求中缺少配置文件ID [L_SHORTMESSAGE1] =&gt;无效的配置文件ID [L_LONGMESSAGE0] =&gt;请求中缺少配置文件ID [L_LONGMESSAGE1] =&gt;配置文件ID无效[L_SEVERITYCODE0] =&gt;错误[L_SEVERITYCODE1] =&gt;错误)

我找到了之前的错误

function GetProfileRecurring( $profileid )
{

$nvpstr = "&PROFILEID=" . $paymentAmount; // replace with this $profileid

$resArray=hash_calls("GetRecurringPaymentsProfileDetails", $nvpstr);

return $resArray;
}

但现在收到新错误    “METHOD = GetRecurringPaymentsProfileDetails&amp; VERSION = 64&amp; PWD = mycorrectpassword&amp; USER = pfmmod_1360821006_biz_api1.gmail.com&amp; SIGNATURE = mycorrectsign&amp; PROFILEID = I-GS6BRWYTM2BC&amp; BUTTONSOURCE = PP-ECWizard”Array([TIMESTAMP] =&gt; 2016-11-02T08 :14:44Z [CORRELATIONID] =&gt; 31347296c48eb [ACK] =&gt;失败[VERSION] =&gt; 64 [BUILD] =&gt; 24616352 [L_ERRORCODE0] =&gt; 10001 [L_SHORTMESSAGE0] =&gt;内部错误[L_LONGMESSAGE0] =&gt;内部错误[L_SEVERITYCODE0] =&gt;错误) GetRecurringPaymentsProfileDetails API调用失败。详细错误消息:内部ErrorShort错误消息:内部ErrorError代码:10001错误严重性代码:错误

1 个答案:

答案 0 :(得分:0)

如果它说'requestShort&#39;中缺少个人资料ID而不是缺少。

尝试转储要发送的结果数据。我确信它不包含PROFILE ID。