php:paypal定期付款令牌无效

时间:2013-06-18 06:31:43

标签: php paypal

我用paypal php sdk:

https://github.com/paypal/merchant-sdk-php/blob/master/samples/RecurringPayments/CreateRecurringPaymentsProfile.php

快速结帐效果很好,但使用定期付款有问题:令牌无效。 sdk中的152行,就是说

  

带时间戳的令牌,其值在响应中返回       第一次调用SetExpressCheckout。呼叫       为每个结算创建一次CreateRecurringPaymentsProfile       协议包含在SetExpressCheckout请求中并使用相同的       每个电话的令牌。每个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;
}

谢谢。

1 个答案:

答案 0 :(得分:4)

您只需确保在SetExpressCheckout请求中包含结算协议信息。看一下这个sample of set of API calls to complete a recurring payments profile using Express Checkout

您会注意到SEC请求包含L_BILLINGTYPE0和L_BILLINGAGREEMENTDESCRIPTION0的参数。您需要确保包含这些内容,否则您获得的令牌对CreateRecurringPaymentsProfile无效。