GetExpressCheckoutDetails响应中缺少PayPal TransactionID

时间:2014-12-04 22:53:35

标签: php paypal express-checkout

我正在使用PayPal的GetExpressCheckoutDetails调用带有效令牌来尝试提取已提交交易的详细信息。但是,根据下面URL中列出的文档,返回的值是PayPal应该返回的一小部分。

https://developer.paypal.com/docs/classic/api/merchant/GetExpressCheckoutDetails_API_Operation_NVP/

有人知道为什么PayPal没有返回完整的数据集吗?在这种情况下,我并不在乎大部分内容,但是我们需要在文档中列出的事务ID为 PAYMENTREQUEST_n_TRANSACTIONID ,以便我们可以将数据库中的事务与PayPal匹配&# 39; s交易历史。

paypalfunctions.php(相关功能)

function GetShippingDetails( $token ) {
    $nvpstr="&TOKEN=" . $token;
    $resArray=hash_call("GetExpressCheckoutDetails",$nvpstr);
    $ack = strtoupper($resArray["ACK"]);
    if($ack == "SUCCESS" || $ack=="SUCCESSWITHWARNING") {   
        $_SESSION['payer_id'] = $resArray['PAYERID'];
        } 
    return $resArray;
    }

function hash_call($methodName,$nvpStr) {
    global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
    global $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
    global $gv_ApiErrorURL;
    global $sBNCode;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$API_Endpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    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)
        curl_setopt ($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT); 

    $nvpreq="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($version) . "&PWD=" . urlencode($API_Password) . "&USER=" . urlencode($API_UserName) . "&SIGNATURE=" . urlencode($API_Signature) . $nvpStr . "&BUTTONSOURCE=" . urlencode($sBNCode);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

    $response = curl_exec($ch);

    $nvpResArray=deformatNVP($response);
    $nvpReqArray=deformatNVP($nvpreq);
    $_SESSION['nvpReqArray']=$nvpReqArray;

    if (curl_errno($ch)) {
        $_SESSION['curl_error_no']=curl_errno($ch) ;
        $_SESSION['curl_error_msg']=curl_error($ch);
        } else {
        curl_close($ch);
        }

    return $nvpResArray;
    }

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

    while(strlen($nvpstr)) {
        $keypos= strpos($nvpstr,'=');
        $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);

        $keyval=substr($nvpstr,$intial,$keypos);
        $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
        $nvpArray[urldecode($keyval)] =urldecode( $valval);
        $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
        }
    return $nvpArray;
    }

ExpressCheckoutReceipt.php

session_start();
ini_set( "session.bug_compat_warn", "off" );
require_once("paypalfunctions.php");

if ( isset( $_GET['token'] ) ) {
    $token = $_GET['token'];
    }

if ( $token != "" ) {
    $resArray = GetShippingDetails( $token );
    echo "<pre>";
    var_dump( $resArray );
    echo "</pre>";
    } else {
    echo "Error: Transaction Incomplete";
    }

返回的数组(删除了真实信息)

如您所见,此返回的数组不包含事务ID。事实上,PayPal声称将返回的所有较新的 n 类型变量都将丢失。

    array(21) {
["TOKEN"]=>
  string(20) "EC-XXXXXXXXXXXXXXXXX"
  ["TIMESTAMP"]=>
  string(20) "2014-12-04T22:10:46Z"
  ["CORRELATIONID"]=>
  string(13) "XXXXXXXXXXXXXXX"
  ["ACK"]=>
  string(7) "Success"
  ["VERSION"]=>
  string(3) "2.3"
  ["BUILD"]=>
  string(8) "14086142"
  ["EMAIL"]=>
  string(31) "test@test.com"
  ["PAYERID"]=>
  string(13) "XXXXXXXXXXXXX"
  ["PAYERSTATUS"]=>
  string(8) "verified"
  ["BUSINESS"]=>
  string(25) "TestCo"
  ["FIRSTNAME"]=>
  string(9) "Test"
  ["LASTNAME"]=>
  string(6) "Test"
  ["COUNTRYCODE"]=>
  string(2) "US"
  ["SHIPTONAME"]=>
  string(25) "Test Test"
  ["SHIPTOSTREET"]=>
  string(20) "123 Test St."
  ["SHIPTOCITY"]=>
  string(6) "Test City"
  ["SHIPTOSTATE"]=>
  string(2) "CA"
  ["SHIPTOZIP"]=>
  string(5) "33333"
  ["SHIPTOCOUNTRYCODE"]=>
  string(2) "US"
  ["SHIPTOCOUNTRYNAME"]=>
  string(13) "United States"
  ["ADDRESSSTATUS"]=>
  string(9) "Confirmed"
}

谢谢!

2 个答案:

答案 0 :(得分:1)

如果您可以阅读getShippingDetails()函数中的评论the authorization is not a completed transaction at this state - the buyer still needs an additional step to finalize the transaction

        //'--------------------------------------------------------------
        //' At this point, the buyer has completed authorizing the payment
        //' at PayPal.  The function will call PayPal to obtain the details
        //' of the authorization, incuding any shipping information of the
        //' buyer.  Remember, the authorization is not a completed transaction
        //' at this state - the buyer still needs an additional step to finalize
        //' the transaction
        //'--------------------------------------------------------------

因此,您还需要在此之后调用ConfirmPayment()方法,该方法将在函数中调用DoExpressCheckoutPayment

答案 1 :(得分:0)

您是否通过首先完成DoExpressCheckout操作来完成Express Checkout交易? PayPal中的每笔交易都需要在发出交易ID之前完成。在这种情况下,需要先运行DoExpressCheckout,然后才能在GetExpressCheckout详细信息中获取事务ID。