原始问题
使用 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 被声明为全局的,然后将 $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/