我将 ipn 脚本改编为“立即购买”按钮,之后我添加了“添加到购物车”按钮。
This is the buy now button:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="return" value="http://www.company.develway.com/company_user?id= <?php echo $id; ?>">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="custom" value="<?php echo $id; ?>"/>
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="item_name" value="<?php echo 'Premium Content for ' . $name; ?>">
<input type="hidden" name="hosted_button_id" value="TV4SWL86EHYYQ">
<input type="image" src="https://www.paypalobjects.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.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
This is add to cart button:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" border="0" name="submit" alt="Make payments with PayPal - it'sfast, free and secure!">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="finciucsergiu@gmail.com">
<input type="hidden" name="custom" value="<?php echo $id; ?>"/>
<input type="hidden" name="item_name" value="<?php echo 'Premium Content for ' . $name; ?>">
<input name="notify_url" value="http://www.company.develway.com/ipn.php" type="hidden">
<input type="hidden" name="item_number" value="Wid-001">
<input type="hidden" name="amount" value="0.01">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input name="notify_url" value="http://www.company.develway.com/ipn.php" type="hidden">
</form>
这是 ipn 文件的主要部分:
if (strcmp ($res, "VERIFIED") == 0) {
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$custom = $_POST['custom'];
$txn_type = $_POST['txn_type'];
$number_of_items = $_POST['num_cart_items'];
$connection = mysql_connect("hhh", "fff", "lll");
$db_select = mysql_select_db("company", $connection);
mysql_query("INSERT INTO paid_companies(users_email, companies_id)
VALUES('$payer_email', '$custom') ") or die(mysql_error());
}
AL 适用于立即购买和添加到购物车(如果它是一件商品),但如果我在数据库中插入多个商品,则仅包含最后一件商品。我做错了什么?