【问题标题】:PayPal passing multiple orders贝宝传递多个订单
【发布时间】:2012-03-31 04:24:44
【问题描述】:

嘿,我有一个问题。我的页面上有一个购物车,它工作正常,它将信息存储在会话中并使用此表单将其传递给贝宝....

<?php $items = unserialize($_SESSION['items']); ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="no_note" value="1">  
<input type="hidden" name="business" value="email@yahoo.ca">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="return" value="http://www.mysite.com/">   
<input type="hidden" name="item_name" value="<?php echo $items['1_']['name']; ?>"> 
<input type="hidden" name="amount" value="<?php echo $items['1_']['price']; ?>"> 
<input type="submit" name="paypal" id="paypal" value="Checkout" />
</form>

但是当我的会话有多个项目时,贝宝只拿两个项目只有一个。

所以我的问题是如何使用此表单将多个项目传递给贝宝?

如果有人能指出我正确的方向,那就太好了!

非常感谢,

  • J

【问题讨论】:

    标签: php session-cookies paypal


    【解决方案1】:

    使用 _cart 的 cmd 值而不是 _xclick,还包括一个 upload=1 值:

    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="upload" value="1">
    

    您需要为购物车中的每件商品重复输入 item_nameamount,但使用计数器作为后缀,例如item_name_xamount_xx 对于第一项应该是 1,并且对于购物车中的每个其他项目都递增。所以第一项是item_name_1item_amount_1

    完整文档 - 向下滚动到 Method 2. Passing Individual Items to PayPalhttps://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/howto_checkout-outside

    所以你的代码可能看起来像:

    <?php $items = unserialize($_SESSION['items']); ?>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="upload" value="1">
    <input type="hidden" name="no_note" value="1">  
    <input type="hidden" name="business" value="email@yahoo.ca">
    <input type="hidden" name="currency_code" value="CAD">
    <input type="hidden" name="return" value="http://www.mysite.com/">   
    
    <?php
        $suffix = 1;
        foreach($items as $item):
    ?>
    <input type="hidden" name="item_name_<?php echo $suffix; ?>" value="<?php echo $item['name']; ?>"> 
    <input type="hidden" name="amount_<?php echo $suffix; ?>" value="<?php echo $item['price']; ?>"> 
    <?php
        $suffix++;
        endforeach;
    ?>
    
    <input type="submit" name="paypal" id="paypal" value="Checkout" />
    </form>
    

    【讨论】:

    • 我在 paypal 页面上收到错误提示“您的购物车是空的。”
    • 我已经用一些示例代码编辑了答案。尝试一下,但更改业务并返回您的电子邮件和网站。
    【解决方案2】:

    先把_xclick改成_cart,然后添加一个新的隐藏字段:

    <input type="hidden" name="upload" value="1">
    

    然后使用 item_name_1, item_amount_1, item_name_2, item_amount_2 ... item_name_N, item_amount_N 将您的多个项目传递给 PayPal。

    【讨论】:

    • 这样
    【解决方案3】:

    万一其他人将来偶然发现此问题,请确保您关注@strkol 的帖子。 我一直在努力解决这个问题,直到我将 _xclick 更改为 _cart 并添加了 &lt;input type="hidden" name="upload" value="1"&gt;

    【讨论】:

      猜你喜欢
      • 2015-11-04
      • 2014-04-20
      • 2021-10-10
      • 1970-01-01
      • 2013-09-08
      • 2019-08-04
      • 1970-01-01
      相关资源
      最近更新 更多