我有以下代码(使用 Yii PHP 框架):
error_reporting(E_ALL ^ E_NOTICE);
$libraryPath = Yii::getPathOfAlias('application.libraries.paypal');
spl_autoload_unregister(array('YiiBase','autoload'));
require_once($libraryPath . '/PPBootStrap.php');
spl_autoload_register(array('YiiBase','autoload'));
$PaymentDetails = new PaymentDetailsType();
$address = new AddressType();
$address->CityName = '';
$address->Name = '';
$address->Street1 = '';
$address->StateOrProvince = '';
$address->PostalCode = '';
$address->Country = '';
$address->Phone = '';
$PaymentDetails->ShipToAddress = $address;
$PaymentDetails->ShippingTotal = $PaymentDetails->HandlingTotal
= $PaymentDetails->InsuranceTotal = $PaymentDetails->TaxTotal
= new BasicAmountType('USD', 0);
$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 = $this->createAbsoluteUrl('adListing/listings');
$setECReqDetails->ReturnURL = $this->createAbsoluteUrl('adReturnFromPaypal');
$setECReqDetails->NoShipping = '0';
$setECReqDetails->AddressOverride = '';
$setECReqDetails->ReqConfirmShipping = '0';
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$paypalService = new PayPalAPIInterfaceServiceService();
$ok = TRUE;
try {
Yii::trace(__METHOD__ . ': Initiating PayPal API...');
// wrap API method calls on the service object with a try catch
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
if($setECResponse && strtoupper($setECResponse->Ack) =='SUCCESS') {
Yii::trace(__METHOD__ . ': Got successful response from PayPal. Redirecting to it...');
$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;
}
if (!$ok) {
Yii::app()->user->setFlash('listings', array(
'msg'=>'There was an error while interacting with PayPal. Please try again later.',
'class'=>'flash-error'));
$this->redirect(array('adListing/listings'));
}
用户被重定向到 Paypal,但是当他们使用沙盒帐户登录并尝试付款时,我从 Paypal 收到10525错误:
无法处理此交易。要收取的金额为零。
并且结帐失败。是否有我缺少设置的属性并且该过程失败?