[英]Builing a cart with multiple items and the PayPal button in PHP
我正在用PHP構建購物車,希望允許客戶輸入每件商品的數量,然后按一個按鈕,該按鈕會將您帶到PayPal,並列出您有多少種產品。
在PayPal的網站上,我發現的所有信息似乎都導致我需要購物車。 如果這是絕對必要的,我該如何實施?
我只需要這樣做。
我在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時,它就會在那里。 這確實有點hack,它回答了您的問題,但是我會研究paypal專業代碼。 這應該使您入門。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.