我有以下代码(使用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 错误:
此交易无法处理。收费金额为零。
结帐失败。是否有我想要设置的属性并且该过程失败了?
答案 0 :(得分:1)
我发现了问题。我忘了包含交易所需的另一个对象:
$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = $subscription->description;
$itemDetails->Amount = new BasicAmountType('USD', $subscription->price);
$itemDetails->Quantity = 1;
$itemDetails->ItemCategory = 'Digital';
$PaymentDetails->PaymentDetailsItem[0] = $itemDetails;
这一行
$PaymentDetails->ShippingTotal = $PaymentDetails->HandlingTotal
= $PaymentDetails->InsuranceTotal = $PaymentDetails->TaxTotal
= new BasicAmountType('USD', 0);
也应改为
$PaymentDetails->OrderTotal = $PaymentDetails->ItemTotal =
new BasicAmountType('USD', $subscription->price);