【问题标题】:Passing variable values over to paypal's cart to carry out payment将变量值传递到贝宝的购物车以进行付款
【发布时间】:2012-03-17 22:16:48
【问题描述】:

我创建了一个购物篮,客户可以在其中添加和更新等。产品本身是从数据库中抓取的,并显示在购物篮中的表格中。我如何从这里使用 Paypal?我现在想要一个名为“支付”的按钮,用户可以单击该按钮,然后将他们带到 Paypal 进行支付。但我希望在 Paypal 收据中回复物品的详细信息。

我已注册 paypals 网络标准付款。我想我只需要购买按钮,但如前所述,我不确定如何将产品转移到 Paypal。我注意到第三方购物车的步骤类似,但提供的代码是这样的:

<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="business" value="seller@dezignerfotos.com"> 
<input type="hidden" name="item_name_1" value="Item Name 1"> 
<input type="hidden" name="amount_1" value="1.00"> 
<input type="hidden" name="shipping_1" value="1.75"> 
<input type="hidden" name="item_name_2" value="Item Name 2"> 
<input type="hidden" name="amount_2" value="2.00"> 
<input type="hidden" name="shipping_2" value="2.50"> 
<input type="submit" value="PayPal"> 

但我不明白这与我的购物车有什么关系。这表明购物车有 2 件商品(item_name_1 和 item_name_2),但如果客户有 3 件呢?我怎么知道客户添加了多少项目?

金额也有同样的问题 - 我怎么知道一件商品的价格是 1.00 英镑还是 2.00 英镑?

这似乎不是动态的,取决于客户的选择?谁能解释一下

【问题讨论】:

  • 从这里开始:cms.paypal.com/us/cgi-bin/…。如果您仍然无法弄清楚,请回到这里并提出更具体的问题。
  • 提供更多信息以使其更具体

标签: php paypal


【解决方案1】:

您只需连接到数据库并将值从数据库循环到表单的输入类型。

SELECT * from customer where customer_id = $customer_id

【讨论】:

    【解决方案2】:

    你说你已经创建了他们的购物车?我不确定你是如何存储它的,但是循环遍历它,为每个项目添加这些隐藏的输入。例如,如果您的购物车位于 PHP 数组中:

    $i = 0;
    foreach($cart as $item) {
        ?>
        <input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $item['name']; ?>">
        <input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $item['cost']; ?>"> 
        <input type="hidden" name="shipping_<?php echo $i; ?>" value="<?php echo $item['shipping']; ?>">
        <?php
        $i++;
    }
    unset($i);
    

    显然,您需要重命名变量以匹配您在购物车中存储值的方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 2013-08-04
      • 2015-10-27
      • 1970-01-01
      • 2017-11-18
      • 2011-07-25
      • 2013-08-28
      相关资源
      最近更新 更多