2014-10-02 41 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