我使用了 paypal php sdk:
快速结帐运作良好,但使用定期付款有问题:令牌无效。sdk中的第152行,据说
一个带时间戳的令牌,其值在对 SetExpressCheckout 的第一次调用的响应中返回。为 SetExpressCheckout 请求中包含的每个计费协议调用一次 CreateRecurringPaymentsProfile,并为每个调用使用相同的令牌。每个 CreateRecurringPaymentsProfile 请求都会创建一个定期付款资料。
但我不明白如何“在 SetExpressCheckout 中调用 CreateRecurringPaymentsProfile 一次”,有我的代码:
public function createPayToken($returnUrl, $cancelUrl, $payModeData) {
$itemName = $payModeData['name'];
$order = $payModeData['fee'];
// $category = 'Digital';
$category = 'Physical';
$currencyCode = "USD";
$paymentDetails = new PaymentDetailsType();
$itemAmount = new BasicAmountType($currencyCode, $order);
$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = $itemName;
$itemDetails->Amount = $itemAmount;
$itemDetails->Quantity = 1;
$itemDetails->ItemCategory = $category;
$paymentDetails->OrderTotal = new BasicAmountType($currencyCode, $order);
$paymentDetails->PaymentAction = 'Sale';
$paymentDetails->PaymentDetailsItem[] = $itemDetails;
$setECReqDetails = new SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[] = $paymentDetails;
$setECReqDetails->ReqConfirmShipping = 0;
$setECReqDetails->NoShipping = 1;
$setECReqDetails->AddressOverride = 0;
$setECReqDetails->CancelURL = $cancelUrl;
$setECReqDetails->ReturnURL = $returnUrl;
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$paypalService = new PayPalAPIInterfaceServiceService();
try {
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
exit;
} catch (Exception $ex) {
echo $ex;
exit;
}
if(isset($setECResponse)) {
if($setECResponse->Ack =='Success') {
$token = $setECResponse->Token;
return $token;
}
var_dump($setECResponse);
exit;
}
return false;
}
谢谢你。