如何向PayPal发送多个项目

时间:2011-01-25 07:35:41

标签: paypal paypal-sandbox

我想向PayPal发送多个商品名称和商品价格,但我无法使用以下代码发布商品名称和价格,您可以帮助我吗?

<form method="post"  name="cart" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="navive_1295939206_biz@gmail.com">
    <input type="hidden" name="lc" value="US">

    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="button_subtype" value="services">
    <input type="hidden" name="notify_url" value="http://newzonemedia.com/henry/ipn.php" />
    <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
    <input type="hidden" name="return" value="http://www.example.com/thank_you_kindly.html" />


    <?php
    //select items for table
    $srowcart_dtl = mysql_num_rows($srscart_dtl);
    if($srowcart_dtl > 0) {
        $cnt=1;
        while($srscart_dtl1 = mysql_fetch_assoc($srscart_dtl)) {
            ?>  
            <input type="hidden" name="item_name[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iname']; ?>">

            <input type="hidden" name="amount[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iprc']; ?>">
            <?php
            $cnt++;
        }
    }
    ?>
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

2 个答案:

答案 0 :(得分:13)

像这样创建你的代码:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart">  <!-- change _xclick to _cart -->
    <input type="hidden" name="upload" value="1">  <!-- add this line in your code -->
    <input type="hidden" name="business" value="your_seller_account">
    <input type="hidden" name="item_name_1" value="Item Name 1">
    <input type="hidden" name="amount_1" value="1.00">
    <input type="hidden" name="item_name_2" value="Item Name 2">
    <input type="hidden" name="amount_2" value="2.00">
    <input type="submit" value="PayPal">
</form>

答案 1 :(得分:1)

除了devilprince建议的更改之外,订单项输入标记的名称属性中缺少下划线,而且标记也不是正确的自关闭标记,因为缺少结束/。正确如此:

<form method="post" name="cart" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
  <input type="hidden" name="cmd" value="_cart">
  <input type="hidden" name="upload" value="1">
  <input type="hidden" name="business" value="navive_1295939206_biz@gmail.com">
  <input type="hidden" name="lc" value="US">
  <input type="hidden" name="currency_code" value="USD">
  <input type="hidden" name="button_subtype" value="services">
  <input type="hidden" name="notify_url" value="http://newzonemedia.com/henry/ipn.php" />
  <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
  <input type="hidden" name="return" value="http://www.mysite.org/thank_you_kindly.html" />

  <?php
    // select items for table
    $srowcart_dtl = mysql_num_rows($srscart_dtl);
    if($srowcart_dtl > 0)
    {
       $cnt=1;
       while($srscart_dtl1 = mysql_fetch_assoc($srscart_dtl))
       {
  ?>    
         <input type="hidden" name="item_name_[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iname']; ?>"/>
         <input type="hidden" name="amount_[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iprc']; ?>"/>
  <?php
         $cnt++;
       }
    }
  ?>
  <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
  <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

(您可能还希望转义值属性中的特殊字符,至少对于"字符,以防它出现在您的项目名称数据中。)

今天必须为客户解决这个问题。除了item_name_Namount_N之外,我还使用了quantity_Ntax_Nshipping_N(其中N是行项目编号,从1开始)。

此页面包含所有参数的列表:PayPal HTML Form Variables,但问题&amp;这里给出的答案是一个比PayPal网站上的简单例子更好的现实世界的例子。