2009-12-30 102 views
4

我正在用PHP構建一個購物車,並希望允許客戶輸入每個項目的數量,然後按下一個按鈕,該按鈕將您帶到PayPal並列出多少你有產品。用PHP打包購物車中的多個項目和PayPal按鈕

在PayPal的網站上,我找到的所有信息都似乎導致我需要購物車。如果這是絕對必要的,我怎麼能實現呢?

回答

10

我只是必須這樣做。

我用這種形式在我的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項功能:

方法add_item( '001-新產品',「新產品',1,1);

您不會看到該產品,但實際上將該表單提交給paypal時,該產品將存在於該產品中。這真是一個黑客攻擊,這是你的問題的答案,但我會看看貝寶的專業代碼。這應該讓你開始。

+0

所以,我們都清楚:這個js片段增加了新的項目編號,名稱,數量(價格)和數量,將這些附加到表單中,這些表單一起提交給paypal,paypal將接受所有這些作爲單獨的產品?而且,下劃線之後的數字顯然將每個單獨的商品訂單綁定在一起。這非常好,而且我正在尋找。爲什麼我不能在paypal的網站上找到任何關於此事的信息? – Peter 2010-05-25 14:00:12

+1

嘗試搜索「簡單的PayPal整合」與谷歌或冰或任何你使用。不要看paypal文檔鏈接,看開發博客鏈接。 – shady 2010-06-01 20:47:58

+0

如何使其安全,以便使用不編輯html5代碼或javascript代碼,以便他/她可以編輯價格 – TheCrazyProfessor 2016-12-14 16:10:39