调用DoReferenceTransaction方法给出错误

时间:2015-11-02 10:07:32

标签: php paypal express-checkout

我在SetExpressCheckout之后调用CreateBillingAgreement,两者都是成功的。 BILLINGAGREEMENTID由CreateBillingAgreement返回。

此BILLINGAGREEMENTID作为REFERENCEID传递给DoReferenceTransaction。

NVP的构建如下:

$nvpstr = '&TOKEN=' . $token . '&REFERENCEID=' . $billing_agreement_id . '&PAYMENTACTION=' . $paymentType . '&AMT=' . $FinalPaymentAmt;
    $nvpstr .= '&CURRENCYCODE=' . $currencyCodeType . '&IPADDRESS=' . $serverName .'&L_ITEMCATEGORY0=Digital'.'&DESC='.urlencode("Test Recurring Payment( $" . $_SESSION["Payment_Amount"] . " monthly)");

    $nvpstr.="&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital";
    $nvpstr.="&L_PAYMENTREQUEST_0_QTY0=Digital";
    $nvpstr.="&L_PAYMENTREQUEST_0_NAME0=Test Name";
    $nvpstr.="&L_PAYMENTREQUEST_0_AMT0=".$_SESSION["Payment_Amount"];

    $nvpstr.="&L_NAME0=Test Name";
    $nvpstr.="&L_DESC0=".urlencode("Test Recurring Payment( $" . $_SESSION["Payment_Amount"] . " monthly)");
    $nvpstr.="&L_AMT0=".$_SESSION["Payment_Amount"];
    $nvpstr.="&L_QTY0=1";

调用DoReferenceTransaction方法给出错误:

  Array
(
    [TIMESTAMP] => 2015-11-02T10:20:06Z
    [CORRELATIONID] => 3e60a1baba3b3
    [ACK] => Failure
    [VERSION] => 64
    [BUILD] => 000000
    [L_ERRORCODE0] => 10209
    [L_ERRORCODE1] => 10004
    [L_SHORTMESSAGE0] => Disabled
    [L_SHORTMESSAGE1] => Invalid Data
    [L_LONGMESSAGE0] => Preapproved Payments not enabled.
    [L_LONGMESSAGE1] => This transaction cannot be processed.
    [L_SEVERITYCODE0] => Error
    [L_SEVERITYCODE1] => Error
    [TRANSACTIONTYPE] => None
    [PAYMENTTYPE] => None
    [ORDERTIME] => 1970-01-01T00:00:00Z
    [PAYMENTSTATUS] => None
    [PENDINGREASON] => None
    [REASONCODE] => None
)

注意:使用Sandbox帐户进行测试。

更新

function DoReferenceTransaction(){

    //Format the other parameters that were stored in the session from the previous calls   
    $token = urlencode($_SESSION['TOKEN']);
    $paymentType = urlencode($_SESSION['PaymentType']);
    $currencyCodeType = urlencode($_SESSION['currencyCodeType']);
    //$payerID = urlencode($_SESSION['payer_id']);  $_SESSION['billing_agreement_id']
     $billing_agreement_id = urlencode($_SESSION['billing_agreement_id']);  

$FinalPaymentAmt = urlencode( $_SESSION["Payment_Amount"]);
    $serverName = urlencode($_SERVER['SERVER_NAME']);

    $nvpstr = '&TOKEN=' . $token . '&REFERENCEID=' . $billing_agreement_id . '&PAYMENTACTION=' . $paymentType . '&AMT=' . $FinalPaymentAmt;
    $nvpstr .= '&CURRENCYCODE=' . $currencyCodeType . '&IPADDRESS=' . $serverName .'&L_ITEMCATEGORY0=Digital'.'&DESC='.urlencode("Test Recurring Payment( $" . $_SESSION["Payment_Amount"] . " monthly)");

    $nvpstr.="&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital";
    $nvpstr.="&L_PAYMENTREQUEST_0_QTY0=Digital";
    $nvpstr.="&L_PAYMENTREQUEST_0_NAME0=Test Name";
    $nvpstr.="&L_PAYMENTREQUEST_0_AMT0=".$_SESSION["Payment_Amount"];

    $nvpstr.="&L_NAME0=Test Name";
    $nvpstr.="&L_DESC0=".urlencode("Test Recurring Payment( $" . $_SESSION["Payment_Amount"] . " monthly)");
    $nvpstr.="&L_AMT0=".$_SESSION["Payment_Amount"];
    $nvpstr.="&L_QTY0=1";



    /* Make the call to PayPal to finalize payment
      If an error occured, show the resulting errors
     */

        $resArray = hash_call("DoReferenceTransaction", $nvpstr);  
echo "<pre>";
   print_r($resArray); exit;

    /* Display the API response back to the browser.
      If the response from PayPal was a success, display the response parameters'
      If the response was an error, display the errors received using APIError.php.
     */
    $ack = strtoupper($resArray["ACK"]);

    return $resArray;
}

适用于DoReferenceTransaction的NVP:

&TOKEN=EC-30M31870BS241854X&REFERENCEID=B-81S156104Y376273D&PAYMENTACTION=Sale&AMT=3&CURRENCYCODE=USD&IPADDRESS=paypalrecurring.com&L_ITEMCATEGORY0=Digital&DESC=Test+Recurring+Payment%28+%243+monthly%29&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital&L_PAYMENTREQUEST_0_QTY0=Digital&L_PAYMENTREQUEST_0_NAME0=Test Name&L_PAYMENTREQUEST_0_AMT0=3&L_NAME0=Test Name&L_DESC0=Test+Recurring+Payment%28+%243+monthly%29&L_AMT0=3&L_QTY0=1

1 个答案:

答案 0 :(得分:1)

是实时或沙盒API调用吗?

您需要在PayPal帐户上激活参考交易才能调用此API。

参考交易API并非适用于所有人。我建议您联系您的PayPal代表,要求他们在您的PayPal帐户上激活此功能。

如果您在沙箱上执行此操作,则只需将沙盒帐户升级为专业版帐户即可。这应该激活沙箱帐户上的参考交易。

可以肯定的是,如果您的沙盒帐户启用了参考交易,您应该询问PayPal。

您可以在问题中发送完整的API调用吗?

<强>更新

我在你的代码中看到了一些奇怪的东西:

$nvpstr.="&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital";
$nvpstr.="&L_PAYMENTREQUEST_0_QTY0=Digital";

通过以下方式更改:

$nvpstr.="&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Physical";
$nvpstr.="&L_PAYMENTREQUEST_0_QTY0=1";

更新2

我在API调用中看到了一些错误:

&TOKEN=EC-30M31870BS241854X&
REFERENCEID=B-81S156104Y376273D&
PAYMENTACTION=Sale&
AMT=3&
CURRENCYCODE=USD&
IPADDRESS=paypalrecurring.com&
L_ITEMCATEGORY0=Digital&
DESC=Test+Recurring+Payment%28+%243+monthly%29&
L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital&
L_PAYMENTREQUEST_0_QTY0=Digital&
L_PAYMENTREQUEST_0_NAME0=Test Name&
L_PAYMENTREQUEST_0_AMT0=3&
L_NAME0=Test Name&
L_DESC0=Test+Recurring+Payment%28+%243+monthly%29&
L_AMT0=3&
L_QTY0=1string(606) 

在IP地址变量中提供有效的IP地址。

替换

L_PAYMENTREQUEST_0_QTY0=Digital&

由:

L_PAYMENTREQUEST_0_QTY0=1&

在最后一个参数中有一个错误的参数替换:

L_QTY0=1string(606) 

由:

L_QTY0=1

最终将项目类别从Digital更改为Physical。我知道您需要使用PayPal进行数字商品的特殊权利。

L_ITEMCATEGORY0=Physical&
L_PAYMENTREQUEST_0_ITEMCATEGORY0=Physical&