我正在使用 Yii 构建一个需要通过 PayPal 付款的应用程序。经过大量挖掘,我发现ExpressCheckout是使用的方法。下面的代码使用 PHP SDK 的 1.2.95 版本在一段时间前运行良好(一些(?)几周前,我想在 PayPal 推出他们的新开发者平台之前)。现在,使用最新版本 v.2.2.98,代码失败。
require_once(Yii::getPathOfAlias('application.libraries.paypal') . '/PPBootStrap.php');
$logger = new PPLoggingManager('SetExpressCheckout');
$PaymentDetails = new PaymentDetailsType();
$PaymentDetails->OrderTotal = $PaymentDetails->ItemTotal =
new BasicAmountType('USD', $subscription->price);
$PaymentDetails->PaymentAction = "Sale";
$PaymentDetails->OrderDescription = $subscription->description;
$setECReqDetails = new SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $PaymentDetails;
$setECReqDetails->CancelURL = 'someCancelUrl';
$setECReqDetails->ReturnURL = 'someReturnUrl';
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$paypalService = new PayPalAPIInterfaceServiceService();
$ok = TRUE;
try {
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
if($setECResponse && strtoupper($setECResponse->Ack) =='SUCCESS') {
$token = $setECResponse->Token;
// Redirect to paypal.com here
$this->redirect(
'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . $token);
}
}
catch (Exception $ex) {
Yii::trace(__METHOD__ . ': Exception while interacting with PayPal API, error: '
. $ex->getMessage());
$ok = FALSE;
}
违规行是:
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
在 PayPalAPIInterfaceServiceService::SetExpressCheckout() 中,这两行:
$resp = $this->call('PayPalAPIAA', 'SetExpressCheckout', $setExpressCheckoutReq, $apiCredential);
$ret->init(PPUtils::xmlToArray($resp));
是问题。$resp
为空,因此下一行在PPUtils::xmlToArray($resp)
方法调用时失败。
显然,要么我在这里遗漏了一些东西,要么 PayPal 做错了什么。
有什么帮助吗?