2014-10-02 95 views
0

我正在使用Django 1.7與django-paypal。django paypal - 如何防止用戶篡改金額

我按照tutorial,一切工作正常。

但是,雖然付款表單是隱藏的,但我發現用戶可以通過簡單地使用瀏覽器檢查元素功能來調節金額。

例如。

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 
<input id="id_business" name="business" type="hidden" value="[email protected]"> 
<input id="id_amount" name="amount" type="hidden" value="10.0"> 
<input id="id_item_name" name="item_name" type="hidden" value="2"> 
<input id="id_notify_url" name="notify_url" type="hidden" value="http://www.example.com/pp/ipn/"> 
<input id="id_cancel_return" name="cancel_return" type="hidden" value="http://www.example.com/order/21/"> 
<input id="id_return_url" name="return" type="hidden" value="http://www.example.com/thank-you"> 
<input id="id_invoice" name="invoice" type="hidden" value="21"><input id="id_cmd" name="cmd" type="hidden" value="_xclick"> 
<input id="id_charset" name="charset" type="hidden" value="utf-8"> 
<input id="id_currency_code" name="currency_code" type="hidden" value="USD"> 
<input id="id_no_shipping" name="no_shipping" type="hidden" value="1"> 
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="Buy it Now"> 
</from> 

這是一個錯誤還是我錯過了什麼?如何防止用戶欺詐付款?我應該在ipn視圖上驗證付款嗎?

回答

0

您創建的按鈕代碼是Clear text按鈕,它不是託管按鈕。 爲了確保按鈕不被篡改,我建議您創建一個託管按鈕。 步驟創建:

1)登錄到www.paypal.com

2)瀏覽到我的簡介 - >我的銷售工具,或者我的銷售偏好

3)單擊 「更新」 旁邊的「貝寶按鈕」

4)新建按鈕,並輸入所有需要的信息,

5)在第2步,選中在貝寶(保存按鈕),然後點擊保存

enter image description here

託管按鈕被存儲在貝。與這種按鈕相關的參數是安全的。 託管按鈕提供了最大的靈活性,因爲您可以指示貝寶動態更改它們,並且貝寶保留有關其狀態的信息,例如與按鈕關聯的庫存級別。

+0

這會起作用,但我有更復雜的銷售項目。所以,它不會更靈活。另外,我想在未來添加其他網關,因此可以用於所有付款的適當驗證更好。任何服務器端驗證? – 2014-10-02 11:16:45

+0

如果您想要動態值,您可以使用明文方法在服務器端填充動態/複雜的銷售項目,並將值傳遞給paypal。這樣您就不會在安全性上妥協並將值暴露給最終用戶。 – Vimalnath 2014-10-02 16:42:46