【问题标题】:Builing a cart with multiple items and the PayPal button in PHP用 PHP 构建一个包含多个项目和 PayPal 按钮的购物车
【发布时间】:2011-11-03 04:42:11
【问题描述】:

我正在用 PHP 构建一个购物车,并希望允许客户输入每件商品的数量,然后按下一个按钮,将您带到 PayPal 并列出您拥有的产品数量。

在 PayPal 的网站上,我找到的所有信息似乎都让我需要一个购物车。如果这是绝对必要的,我该如何实施?

【问题讨论】:

    标签: php paypal shopping-cart


    【解决方案1】:

    我只需要这样做。

    我在我的 HTML 中使用这个表单:

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="payPalForm" onsubmit="if (verify()) { get_items(); return true; } else return false;">
        <input type="hidden" name="cmd" value="_cart" />
        <input type="hidden" name="upload" value="1">
        <input type="hidden" name="business" value="[PAYPAL EMAIL HERE]" />
        <input type="hidden" name="currency_code" id="currency_code" value="USD" />
        <input type="hidden" name="return" value="http://www.example.com/thank_you_kindly.html" />
        <p style="text-align: center">
            <input type="submit" name="Submit" value="Join (via PayPal)" id="register_button" />
        </p>
    </form>
    

    我制作的特定表格也可以通过设置currency_code隐藏字段值来更改货币。

    这是我用来添加项目的 javascript 函数:

    function add_item(item_number, item_name, amount, qty) {
        // item number
        var inp1 = document.createElement("input");
        inp1.setAttribute("type", "hidden");
        inp1.setAttribute("id", "item_number_"+curitem);
        inp1.setAttribute("name", "item_number_"+curitem);
        inp1.setAttribute("value", item_number);
    
        // item name
        var inp2 = document.createElement("input");
        inp2.setAttribute("type", "hidden");
        inp2.setAttribute("id", "item_name_"+curitem);
        inp2.setAttribute("name", "item_name_"+curitem);
        inp2.setAttribute("value", item_name);
    
        // amount
        var inp3 = document.createElement("input");
        inp3.setAttribute("type", "hidden");
        inp3.setAttribute("id", "amount_"+curitem);
        inp3.setAttribute("name", "amount_"+curitem);
        inp3.setAttribute("value", amount);
    
        // qty
        var inp4 = document.createElement("input");
        inp4.setAttribute("type", "hidden");
        inp4.setAttribute("id", "quantity_"+curitem);
        inp4.setAttribute("name", "quantity_"+curitem);
        inp4.setAttribute("value", qty);
    
        document.getElementById('payPalForm').appendChild(inp1);
        document.getElementById('payPalForm').appendChild(inp2);
        document.getElementById('payPalForm').appendChild(inp3);
        document.getElementById('payPalForm').appendChild(inp4);
        curitem++;
    }
    

    将表单代码粘贴到您的页面并调用添加项目功能:

    add_item('001- 新产品', '新产品', 1, 1);

    您不会看到该产品,但当您将表单实际提交到贝宝时,它就会出现。这真的有点像黑客,它回答了你的问题,但我会研究一下 paypal pro 代码。这应该可以帮助您入门。

    【讨论】:

    • 所以,我们都清楚了:这个 js sn-p 添加新的商品编号、名称、金额(价格)和数量,将这些附加到表单中,一起提交给 paypal ,而贝宝会接受所有这些作为单独的产品吗?此外,很明显,下划线后面的数字将每个单独的项目订单联系在一起。这太棒了,正是我正在寻找的。为什么我在 paypal 的网站上找不到任何相关信息?
    • 尝试使用 google 或 bing 或任何您使用的东西搜索“简单的 paypal 集成”。不要看paypal文档链接,看开发博客链接。
    • 如何使其安全,以便用户不要编辑html5代码或javascript代码,以便他/她可以编辑价格
    猜你喜欢
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 2015-12-21
    • 2011-05-21
    • 1970-01-01
    相关资源
    最近更新 更多