原始问题

使用paypalplatform.php中的函数,我可以正常运行以下代码:

$resArray = CallPaymentDetails( ... );
// $resArray = CallPay ( ... );


以下内容也可以正常工作:

// $resArray = CallPaymentDetails( ... );
$resArray = CallPay ( ... );


但这不起作用:

$resArray = CallPaymentDetails( ... );
$resArray = CallPay ( ... );


错误发生在第二行,即$resArray = CallPay ( ... );,错误消息为:

'error(0).message' => string 'The trackingId some_string_here is invalid'


我看不到trackingId有什么问题,而且似乎也无法弄清楚为什么如果未使用CallPay的话CallPaymentDetails可以工作的原因。

经过一些调试后,我可以看到paypalplatform.php中的以下行是捕获错误消息的行:

$response = curl_exec($ch);


但我无法单步执行该行,以了解导致错误的原因。有人知道这是怎么回事吗?



更新-全代码

<?php
    error_reporting( E_ALL | E_STRICT );
    ini_set('display_errors', 1);

    require_once ("paypalplatform.php");

    $payKey = "existing payKey goes here";
    $transactionId = "";
    $trackingId = "";

    // if( user has already tried paying where the payment failed, get old $payKey and use in CallPaymentDetails() ) = true {
        $resArray = CallPaymentDetails( $payKey, $transactionId, $trackingId );
    // }

    var_dump($resArray);

    unset($resArray);

    $actionType = "PAY";
    $cancelUrl = "http://" . $_SERVER["SERVER_ADDR"] . "/cancel.php";
    $returnUrl = "http://" . $_SERVER["SERVER_ADDR"] . "/success.php";
    $currencyCode = "GBP";
    $receiverEmailArray = array( 'company email goes here' );
    $receiverAmountArray = array( '2' );
    $receiverPrimaryArray = array();
    $senderEmail = "";
    $feesPayer = "";
    $ipnNotificationUrl = "";
    $memo = "";
    $pin = "";
    $preapprovalKey = "";
    $reverseAllParallelPaymentsOnError = "";
    $trackingId = generateTrackingID();
    $receiverInvoiceIdArray = array( $trackingId );

    $resArray = CallPay ( $actionType, $cancelUrl, $returnUrl, $currencyCode,
        $receiverEmailArray, $receiverAmountArray, $receiverPrimaryArray,
        $receiverInvoiceIdArray, $feesPayer, $ipnNotificationUrl, $memo,
        $pin, $preapprovalKey, $reverseAllParallelPaymentsOnError,
        $senderEmail, $trackingId );

    var_dump($resArray);
?>


顶部的$ payKey变量需要输入,而$ receiverEmailArray也需要输入。

最佳答案

问题在paypalplatform.php中

在hashcall函数中,将$ API_Endpoint声明为global,然后将$ methodname附加到其后。 $ methodname是指示hashcall进行的操作。因为$ API_Endpoint是直接附加的(因为它随后是全局的),所以任何后续对hashcall的调用都将使用修改后的$ API_Endpoint。

在从CallPaymentDetails $ API_Endpoint首次调用hashcall时,是:
https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails

在第二次从CallPay $ API_Endpoint进行的hashcall调用是:
https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails/Pay

这是导致意外结果的原因。

编辑paypalplatform.php删除声明的行并修改声明的行:

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

$API_Endpoint .= "/" . $methodName; //REMOVE THIS LINE

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$API_Endpoint); //MODIFY THIS LINE


因此,hashcall的开始如下:

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

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"$API_Endpoint/$methodName");

关于php - 无法从paypalplatform.php获取CallPay和CallPaymentDetails以便一起工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21915264/

10-11 22:51
查看更多