我已经开发了自己的购物车,现在我想集成 Paypal,以便在客户点击“立即购买”按钮后进行付款流程。
如何才能在左侧的 Paypal 中交互项目详细信息?我需要根据客户添加到购物车的商品将商品详细信息传递给 Paypal。
经过研究,我注意到您可以在单个商品上设置“立即购买”按钮并按此方式操作 - 但我有自己的购物车,可以容纳多个商品。那么我如何才能将这些动态地传递给 Paypal?
我的尝试如下,但在测试时 - 单击“立即购买”按钮时没有任何反应。
<?php
$checkout = "<form action='https://www.paypal.com/cgi-bin/webscr' method='post'>";
$checkout .= "<input type='hidden' name='cmd' value='_cart'><input type='hidden' name='upload' value='1'>";
$checkout .= "<input type='hidden' name='business' value='derrysnurseries@hotmail.co.uk'>";
$count = 1;
$checkout .= "<input type='hidden' name='item_name_" + $count + "' value='" + $product['common_name']+ "'>";
$checkout .= "<input type='hidden' name='item_number_" + $count + "' value='" + $count + "'>";
$checkout .= "<input type='hidden' name='quantity_" + $count + "' value='" + $item['quantity'] + "'>";
$checkout .= "<input type='hidden' name='amount_" + $count + "' value='" + $product['price'] + "'>";
$count = $count + 1;
?>
<input type='hidden' name='currency_code' value='GBP'>
<input type='hidden' name='lc' value='GB'>
<input type='hidden' name='return' value='http://www.derrysnurseries.co.uk/checkout?confirm=Confirm&confirmTerms=on'>
<input type='hidden' name='cancel_return' value='http://www.derrysnurseries.co.uk/checkout'>
<input type='hidden' name='notify_url' value='http://www.derrysnurseries.co.uk/checkout?confirm=Confirm&confirmTerms=on'>
<div class='securePayment'>Click <input class='securePaymentButton' type='submit' value='here'> to continue to secure payment site</div>
<?php $checkout .= "</form>"; ?>
最佳答案
您没有回显具有打开表单标签的字符串,或者您在这段代码示例之后输出它($checkout),所以在提交标签之后。 (非 php 部分会立即输出;您可以在输出中查看源代码以了解我的意思)。
因此,您的提交按钮不是表单的一部分,不会执行您指定的操作。
关于php - Paypal 整合到现有的购物车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9769886/