无法添加多个项目来表达结帐paypal

时间:2015-09-02 11:08:03

标签: paypal paypal-sandbox

在某人标记为重复之前,我已阅读有关添加多个项目以表示结帐的所有其他帖子,但无法解决我的问题。

我正在使用PayPal提供的工作购物车演示,虽然他们的所有演示或文档仅提供添加到购物车中的单个项目的示例,但在演示中无法添加多个项目。我在哪里可以找到有关如何正确添加多个项目的任何文档。

在下面的代码中(直接来自paypal演示,但我添加了一个额外的产品)它允许交易有效,但当用户登录他们的paypal帐户时,它只显示第一个产品,但也是价格该产品是两种产品的总和。

例如,它显示如下:

  • 数码单反相机$ 20.00 USD
  • 税2.00美元
  • 运费$ 5.00 USD
  • 运费折扣$ -3.00 USD
  • 处理$ 1.00 USD
  • 保险$ 2.00美元
  • 总计$ 27.00 USD

它没有显示第二个产品。有任何想法吗?感谢

代码:

<!--Form containing item parameters and seller credentials needed for SetExpressCheckout Call-->
<form class="form" action="paypal_ec_redirect.php" method="POST">
   <div class="row-fluid">
      <div class="span6 inner-span">
            <!--Demo Product details -->
            <table>
            <tr><h3> DIGITAL SLR CAMERA </h3></tr>
            <tr><img src="img/camera.jpg" width="300" height="250"/></tr>
            <tr><td><p class="lead"> Buyer Credentials:</p></td></tr>
            <tr><td>Email-id:&nbsp;&nbsp;&nbsp;<input type="text" id="buyer_email" name="buyer_email" readonly></input> </td></tr>
            <tr><td>Password:<input type="text" id="buyer_password" name="buyer_password" readonly></input></td></tr>
            </table>
      </div>
      <div class="span6 inner-span">
            <p class="lead"> Item Specifications:</p>
            <table>

            <!-- First item -->
            <tr><td>Item Name:</td><td><input type="text" name="L_PAYMENTREQUEST_0_NAME0" value="DSLR Camera"></input></td></tr>
            <tr><td>Item ID: </td><td><input type="text" name="L_PAYMENTREQUEST_0_NUMBER0" value="A0123"></input></td></tr>
            <tr><td>Description:</td><td><input type="text" name="L_PAYMENTREQUEST_0_DESC0" value="Autofocus Camera"></input></td></tr>
            <tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_QTY0" value="1" readonly></input></td></tr>
            <tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_AMT0" value="10.00" readonly></input></td></tr>


            <!-- Second item -->
            <tr><td>Item Name:</td><td><input type="text" name="L_PAYMENTREQUEST_0_NAME1" value="Item 2"></input></td></tr>
            <tr><td>Item ID: </td><td><input type="text" name="L_PAYMENTREQUEST_0_NUMBER1" value="12345"></input></td></tr>
            <tr><td>Description:</td><td><input type="text" name="L_PAYMENTREQUEST_0_DESC1" value="Description"></input></td></tr>
            <tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_QTY1" value="1" readonly></input></td></tr>
            <tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_AMT1" value="10.00" readonly></input></td></tr>


            <tr><td>Price:</td><td><input type="text" name="PAYMENTREQUEST_0_ITEMAMT" value="20.00" readonly></input></td></tr>
            <tr><td>Tax:</td><td><input type="text" name="PAYMENTREQUEST_0_TAXAMT" value="2" readonly></input></td></tr>
            <tr><td>Shipping Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_SHIPPINGAMT" value="5" readonly></input></td></tr>
            <tr><td>Handling Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_HANDLINGAMT" value="1" readonly></input></td></tr>
            <tr><td>Shipping Discount:</td><td><input type="text" name="PAYMENTREQUEST_0_SHIPDISCAMT" value="-3" readonly></input></td></tr>
            <tr><td>Insurance Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_INSURANCEAMT" value="2" readonly></input></td></tr>
            <tr><td>Total Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_AMT" value="27" readonly></input></td></tr>
            <tr><td><input type="hidden" name="LOGOIMG" value=<?php echo('http://'.$_SERVER['HTTP_HOST'].preg_replace('/index.php/','img/logo.jpg',$_SERVER['SCRIPT_NAME'])); ?>></input></td></tr>
            <tr><td>Currency Code:</td><td><select name="currencyCodeType">
            <option value="AUD">AUD</option>
            <option value="BRL">BRL</option>
            <option value="CAD">CAD</option>
            <option value="CZK">CZK</option>
            <option value="DKK">DKK</option>
            <option value="EUR">EUR</option>
            <option value="HKD">HKD</option>
            <option value="MYR">MYR</option>
            <option value="MXN">MXN</option>
            <option value="NOK">NOK</option>
            <option value="NZD">NZD</option>
            <option value="PHP">PHP</option>
            <option value="PLN">PLN</option>
            <option value="GBP">GBP</option>
            <option value="RUB">RUB</option>
            <option value="SGD">SGD</option>
            <option value="SEK">SEK</option>
            <option value="CHF">CHF</option>
            <option value="THB">THB</option>
            <option value="USD" selected>USD</option><br></td></tr>
            <tr><td>Payment Type: </td><td><select>
                                               <option value="Sale">Sale</option>
                                               <option value="Authorization">Authorization</option>
                                               <option value="Order">Order</option>
                                             </select><br></td></tr>

            <tr><td colspan="2"><br/><br/><div id="myContainer"></div></td></tr>
            <tr><td> -- OR -- </td></tr>
            <tr><td ><input type="Submit" alt="Proceed to Checkout" class="btn btn-primary btn-large" value="Proceed to Checkout" name="checkout"/></td></tr>
            </table>
      </div>
   </div>
</form>

1 个答案:

答案 0 :(得分:0)

我想通了,他们的演示代码只手动检查帖子数据中的一个项目。

POST数据以及返回和取消URL被发送到CallShortcutExpressCheckout函数(paypal_functions.php),该函数仅检查预定参数而不是实际循环遍历任何POST数据。

例如,它只手动检查参数是否为issset(),但仅针对一个项目:

function CallShortcutExpressCheckout( $paramsArray, $returnURL, $cancelURL) {

        //it manually checks for all the paramters, i just have shown one for example
        if(isset($paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"])){
            $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPDISCAMT=" . $paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"];
            $_SESSION['shippingDiscAmt'] = $paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"];
        }

        //And here it only looks for one item
        if(isset($paramsArray["L_PAYMENTREQUEST_0_NAME0"]))
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NAME0=" . $paramsArray["L_PAYMENTREQUEST_0_NAME0"];

        if(isset($paramsArray["L_PAYMENTREQUEST_0_NUMBER0"]))
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NUMBER0=" . $paramsArray["L_PAYMENTREQUEST_0_NUMBER0"];

        if(isset($paramsArray["L_PAYMENTREQUEST_0_DESC0"]))
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_DESC0=" . $paramsArray["L_PAYMENTREQUEST_0_DESC0"];

        if(isset($paramsArray["L_PAYMENTREQUEST_0_AMT0"]))
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_AMT0=" . $paramsArray["L_PAYMENTREQUEST_0_AMT0"];

        if(isset($paramsArray["L_PAYMENTREQUEST_0_QTY0"]))
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_QTY0=" . $paramsArray["L_PAYMENTREQUEST_0_QTY0"];

        if(isset($paramsArray["LOGOIMG"]))
        $nvpstr = $nvpstr . "&LOGOIMG=". $paramsArray["LOGOIMG"];

我刚刚删除了所有代码并输入了一个简单的foreach循环:

function CallShortcutExpressCheckout( $paramsArray, $returnURL, $cancelURL) 
{

    if(isset($returnURL))
    $nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;

    if(isset($cancelURL))
    $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;

    foreach ($paramsArray as $k => $value){
        $nvpstr = $nvpstr . "&" . $k . "=" . $value;
    }

最重要的是,由于某些原因,在paypal_ec_redirect.php中,他们确保将单个产品项目金额更改为所有项目金额的总和,就像确保只发送一个项目一样,否则它会抛出购物车项目金额的总数与订单金额不匹配(错误代码:10413)。

我刚评论出来,现在一切都很好,我可以下多个项目订单。

//$_POST["L_PAYMENTREQUEST_0_AMT0"] = $_POST["PAYMENTREQUEST_0_ITEMAMT"];

我希望这有助于某人,我确实看到了另一个stackofflow问题与exactsame问题。为什么他们会让他们的演示代码故意只接受一个项目超出我的范围。