我正在尝试使用PayPal的自适应支付API实施隐式支付脚本。我正在使用PayPal示例中提供的代码。当我的代码调用'CallPay'(在paypalplatform.php中定义)时,会返回一个空数组。
这是我的功能(大部分与PayPal的示例代码相同):
function ImplicitPayment() {
//-------------------------------------------------
// Following code copied from PayPal Implicit Payment Directions
//-------------------------------------------------
require_once ($_SERVER["DOCUMENT_ROOT"] . "/php/admin/paypalplatform.php");
// ==================================
// PayPal Platform Implicit Payment Module
// Sorry about the lack of a 'm' prefix in front of variable names.
// ==================================
// Request specific required fields
$senderEmail = "***@***.com"; // TODO - The paypal account email address of the sender
// think of it as required for an implicit payment and
// set to the same account that owns the API credentials
$actionType = "PAY";
$cancelUrl = "https://NoOp"; // There is no approval step for implicit payment
$returnUrl = "https://NoOp"; // There is no approval step for implicit payment
$currencyCode = "USD";
// An implicit payment can be a simple or parallel or chained payment
// TODO - specify the receiver emails
// remove or set to an empty string the array entries for receivers that you do not have
// for a simple payment, specify only receiver0email, and remove the other array entries
$mPayeeEmail = $Affiliates->d->EMAIL;
$receiverEmailArray = array(
"test@test.com"
);
// TODO - specify the receiver amounts as the amount of money, for example, '5' or '5.55'
// remove or set to an empty string the array entries for receivers that you do not have
// for a simple payment, specify only receiver0amount, and remove the other array entries
$receiverAmountArray = array(
555.00
);
// TODO - specify values ONLY if you are doing a chained payment
// if you are doing a chained payment,
// then set ONLY 1 receiver in the array to 'true' as the primary receiver, and set the
// other receivers corresponding to those indicated in receiverEmailArray to 'false'
// make sure that you do NOT specify more values in this array than in the receiverEmailArray
//
$receiverPrimaryArray = array('');
// TODO - Set invoiceId to uniquely identify the transaction associated with each receiver
// set the array entries with value for receivers that you have
// each of the array values must be unique
$receiverInvoiceIdArray = array(
'1'
);
// Request specific optional fields
// Provide a value for each field that you want to include in the request, if left as an empty string the field will not be passed in the request
$feesPayer = ""; // For an implicit payment use case, this cannot be "SENDER"
$ipnNotificationUrl = "";
$memo = ""; // maxlength is 1000 characters
$pin = ""; // No pin for an implicit payment use case
$preapprovalKey = ""; // No preapprovalKey for an implicit use case
$reverseAllParallelPaymentsOnError = ""; // Only specify if you are doing a parallel payment as your implicit payment
$trackingId = generateTrackingID(); // generateTrackingID function is found in paypalplatform.php
//-------------------------------------------------
// Make the Pay API call
//
// The CallPay function is defined in the paypalplatform.php file,
// which is included at the top of this file.
//-------------------------------------------------
$resArray = CallPay ($actionType, $cancelUrl, $returnUrl, $currencyCode, $receiverEmailArray,
$receiverAmountArray, $receiverPrimaryArray, $receiverInvoiceIdArray,
$feesPayer, $ipnNotificationUrl, $memo, $pin, $preapprovalKey,
$reverseAllParallelPaymentsOnError, $senderEmail, $trackingId
);
var_dump($resArray); //CallPay() returns an empty array?
$ack = strtoupper($resArray["responseEnvelope.ack"]);
if($ack=="SUCCESS")
{
// payKey is the key that you can use to identify the payment resulting from the Pay call
$payKey = urldecode($resArray["payKey"]);
// paymentExecStatus is the status of the payment
$paymentExecStatus = urldecode($resArray["paymentExecStatus"]);
}
else
{
//Display a user friendly Error on the page using any of the following error information returned by PayPal
//TODO - There can be more than 1 error, so check for "error(1).errorId", then "error(2).errorId", and so on until you find no more errors.
$ErrorCode = urldecode($resArray["error(0).errorId"]);
$ErrorMsg = urldecode($resArray["error(0).message"]);
$ErrorDomain = urldecode($resArray["error(0).domain"]);
$ErrorSeverity = urldecode($resArray["error(0).severity"]);
$ErrorCategory = urldecode($resArray["error(0).category"]);
echo "Preapproval API call failed. ";
echo "Detailed Error Message: " . $ErrorMsg;
echo "Error Code: " . $ErrorCode;
echo "Error Severity: " . $ErrorSeverity;
echo "Error Domain: " . $ErrorDomain;
echo "Error Category: " . $ErrorCategory;
}
}
这是产生的输出:
array(0) { }
Notice: Undefined index: responseEnvelope.ack in C:\wamp\www\realadventures\php\admin\affiliates_pay.htm on line 308
Notice: Undefined index: error(0).errorId in C:\wamp\www\realadventures\php\admin\affiliates_pay.htm on line 320
Notice: Undefined index: error(0).message in C:\wamp\www\realadventures\php\admin\affiliates_pay.htm on line 321
Notice: Undefined index: error(0).domain in C:\wamp\www\realadventures\php\admin\affiliates_pay.htm on line 322
Notice: Undefined index: error(0).severity in C:\wamp\www\realadventures\php\admin\affiliates_pay.htm on line 323
Notice: Undefined index: error(0).category in C:\wamp\www\realadventures\php\admin\affiliates_pay.htm on line 324
Preapproval API call failed. Detailed Error Message: Error Code: Error Severity: Error Domain: Error Category:
我在paypalplatform.php中设置了所有的API凭据,不知道为什么它会返回一个空数组......任何想法?谢谢!