2012-03-17 211 views
1

我已经创建了一个顾客可以添加和更新等的购物篮。产品本身从数据库中抓取并显示在购物篮中的表格中。我如何从这里使用PayPal?我现在想要一个名为“付款”的按钮,用户可以点击它,然后它将他们带到Paypal付款。但我想要在PayPal收据中反映这些物品的细节。将变量值传递到PayPal的购物车进行支付

我已注册paypal网站标准付款。我想我只需要购买按钮,但如前所述,我不知道如何将产品转到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="[email protected]"> 
<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"> 

但是,我看不出这可能涉及到我的车。这表明购物车有两个项目(item_name_1 & item_name_2),但如果客户有3个项目呢?我想如何知道客户添加了多少项目?

与金额相同的问题 - 我怎么知道一件物品要花费£1.00或£2.00?

这看起来不是动态的,取决于客户选择什么?有人可以解释一下

+0

从这里开始:https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_overview。如果你仍然无法弄清楚,请回到这里,问一个更具体的问题。 – 2012-03-19 05:46:36

+0

提供了更多的信息,使其更具体 – user1227124 2012-03-19 13:37:12

回答

1

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

SELECT * from customer where customer_id = $customer_id 
1

你说你已经创建了自己的购物车?我不确定你是如何存储这个的,但是通过它循环,为每个项目添加这些隐藏的输入。例如,如果您的车是在一个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); 

很明显,你将需要重命名变量来匹配你是如何保存在您的购物车中的值。