在 PHP 中构建包含多个商品和 PayPal 按钮的购物车

发布于 12-01 09:52 字数 131 浏览 2 评论 0原文

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

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

I'm building a shopping cart in PHP and want to allow customers to enter the quantity for each item and then press a button which brings you to PayPal and lists how many products you have.

On PayPal's website, all the info I found seems to lead to me needing a shopping cart. If this is absolutely necessary, how could I implement that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼泪2024-12-08 09:52:04

我只得这么做。

我在 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- New Product', 'New Product', 1, 1);

您不会看到该产品,但当您实际向 PayPal 提交表单时,它就会出现。这确实是一个黑客,它回答了你的问题,但我会研究贝宝专业代码。这应该可以帮助您开始。

I just had to do this.

I use this form in my 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>

The particular form I made can also change the currency by setting the currency_code hidden field value.

Here's the javascript function I used to add an item:

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++;
}

Paste the form code into your page and call the add item function:

add_item('001- New Product', 'New Product', 1, 1);

You won't see the product, but it will be there when you actually submit the form to paypal. This is really a bit of a hack, it's answers your question, but I would look into the paypal pro code. This should get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文