0

有人可以帮忙吗?我不断收到以下错误消息;

SetExpressCheckout API 调用失败。详细的错误消息:如果提供了项目类别,则需要项目名称、金额和数量。简短的错误消息:缺少参数错误代码:10003错误严重性代码:错误“

require_once ("paypalfunctions.php");

$task = $_GET['task'];
$regRef = $_SESSION['regRef'];

if(strcmp($task, "paypal") == 0) {

    $totalAmount = $_SESSION["netAmount"];
    $vatAmount = number_format((floor($totalAmount * 0.20)), 2, '.', '');
    $grossAmount = number_format(($totalAmount + $vatAmount), 2, '.', '');

    $currencyCodeType = "GBP";
    $paymentType = "Sale";

    $returnURL = "https://myurl.com/events/confirm_registration";

    $cancelURL = "http://myurl.com/events/checkout-handle.php?task=cancel";

    $host = "******";
    $dbuser = "******";
    $pass = "******";
    $db = "******";
    $connection = mysql_connect($host, $dbuser, $pass) or die ("Unable to connect!");
    mysql_select_db($db) or die ("Unable to select database!");

    mysql_query("UPDATE registrations SET `status`='paypal' WHERE `regRef`='$regRef'") or die ("Error in query: $query.".mysql_error());

    $queryItems = mysql_query("SELECT `eventName`, `itemPrice`, COUNT(*) FROM orders WHERE `regRef`='$regRef' GROUP BY `itemPrice`") or die ("Error in query: $query.".mysql_error());
    $numItems = mysql_num_rows($queryItems);
    $items = array();
    while($row = mysql_fetch_array($queryItems)) {
        $localVat = $row['itemPrice']*0.2;
        $items[] = array('name' => $row['eventName'], 'amt' => $row['itemPrice'], 'qty' => $row['COUNT(*)'], 'vat' => $localVat);   
    }
    mysql_close($connection);


    $resArray = SetExpressCheckoutDG($grossAmount, $paymentType, $vatAmount, $returnURL, $cancelURL, $currencyCodeType, $items);

这就是 paypalfunctions.php 文件中的内容

$PROXY_HOST = '127.0.0.1';
$PROXY_PORT = '808';

$SandboxFlag = false;

$API_UserName="******";
$API_Password="******";
$API_Signature="******";


// BN Code  is only applicable for partners
$sBNCode = "PP-ECWizard";


if ($SandboxFlag == true) 
{
    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
    $PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
}
else
{
    $API_Endpoint = "https://api-3t.paypal.com/nvp";
    $PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
}

$USE_PROXY = false;
$version="93";

if (session_id() == "") 
    session_start();

function SetExpressCheckoutDG( $grossAmount, $paymentType, $vatAmount, $returnURL, $cancelURL, $currencyCodeType, $items ) 
{
    $itemsTotal = 0;
    $vatTotal = 0;

    foreach($items as $index => $item) 
    {
        $nvpstr .= "&L_PAYMENTREQUEST_0_NAME" . $index . "=" . urlencode($item["name"]);
        $nvpstr .= "&L_PAYMENTREQUEST_0_AMT" . $index . "=" . urlencode($item["amt"]);
        $nvpstr .= "&L_PAYMENTREQUEST_0_QTY" . $index . "=" . urlencode($item["qty"]);
        $nvpstr .= "&L_PAYMENTREQUEST_0_TAXAMT" . $index . "=" . urlencode($item["vat"]);
        $nvpstr .= "&L_PAYMENTREQUEST_0_ITEMCATEGORY" . $index . "=Physical";
        $nvpstr .= "&L_PAYMENTREQUEST_0_DESC" . $index . "=APN Event";
        $itemsTotal = $itemsTotal + ($item["amt"] * $item["qty"]);
        $vatTotal = $vatTotal + ($item["vat"] * $item["qty"]);
    }       
    $nvpstr .= "&PAYMENTREQUEST_0_ITEMAMT=" . $itemsTotal;          
    $nvpstr .= "&PAYMENTREQUEST_0_TAXAMT=" . $vatTotal;             //tax amount
    $nvpstr .= "&PAYMENTREQUEST_0_AMT=". $grossAmount;              //total cost of items inc tax
    $nvpstr .= "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;
    $nvpstr .= "&RETURNURL=" . $returnURL;
    $nvpstr .= "&CANCELURL=" . $cancelURL;
    $nvpstr .= "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;
    $nvpstr .= "&REQCONFIRMSHIPPING=0";
    $nvpstr .= "&NOSHIPPING=1";

    $_SESSION["currencyCodeType"] = $currencyCodeType;    
    $_SESSION["PaymentType"] = $paymentType;


    $resArray=hash_call("SetExpressCheckout", $nvpstr);
    $ack = strtoupper($resArray["ACK"]);
    if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
    {
        $token = urldecode($resArray["TOKEN"]);
        $_SESSION['TOKEN']=$token;
    }

    return $resArray;
}

任何帮助表示赞赏。:)

4

1 回答 1

1

错误是价格为 0 的事件之一导致问题。通过在填充数组之前添加零测试来修复。根据贝宝文档,您不能仅传递 0 正数或负数。

于 2014-01-15T00:19:30.563 回答