【问题标题】:How can I secure the amount field when using paypal IPN?使用 paypal IPN 时如何保护金额字段?
【发布时间】:2015-03-21 04:29:12
【问题描述】:

我创建了一个 wordpress 插件,它创建了 paypal 立即购买按钮并使用 paypal IPN ...这是我的表单代码

$output =   '<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank">
                            <input type="hidden" name="cmd" value="_xclick">
                            <input type="hidden" name="business" value="'.$paypalID.'">
                            <input type="hidden" name="return" value="'.$return_url.'">
                            <input type="hidden" name="currency_code" value="'.$currency.'">
                            <input type="hidden" name="item_name" value="'.$product_name.'">
                            <input type="hidden" name="amount" id="p'.$product_id.'" value="'.$product_price.'">
                            <input type="hidden" name="custom" value="'.$responderID.'">
                            <input name="notify_url" value="'.plugin_dir_url( __FILE__ ).'ipn_sandbox.php" type="hidden">
                            <input type="image" src="'.$upload_image.'" border="0" name="submit" alt="Make payments with PayPal - its fast, free and secure!"> 
                        </form>'; 

问题是......当向贝宝提交信息时,用户可以轻松更改产品的价格并将错误的价格发送到贝宝..例如,如果产品价值 10 美元,用户可以使用检查元素并更改将价格设为 1 美元或用户喜欢的任何内容并将其发送到贝宝。有什么办法可以防止这种情况或保护价格字段.. 谢谢

我找到了一个解决方案...我在表单正下方添加了这个 javascript 代码并且它可以工作...但现在的问题是,如果我在一个页面上放置多个按钮(假设两个按钮一页)两个按钮都停止工作,除非两个按钮的给定值相同例如

$output .= "<script>jQuery(document).ready(function(){var a=".$product_price.";jQuery('form[name=_xclick]').submit(function(c){var b=jQuery('input[id=p".$product_id."]').val();if(b==a){return}else{c.preventDefault()}})});</script>";

如果按钮 1 的价格 = 20 美元,按钮 2 的价格 = 20 美元,那么这两个按钮都可以使用..

但是

如果按钮 1 的价格 = 20 美元,按钮 2 的价格 = 21 美元,那么这两个按钮都不起作用..

任何建议/想法?

【问题讨论】:

  • 嗯?您使用 IPN 返回的价格从您的数据库中检查价格?
  • 鉴于我的情况,我认为应该在使用他们的“立即购买”按钮将其提交到贝宝之前检查价格。有什么办法可以做到吗??

标签: php wordpress paypal


【解决方案1】:

有几种方法可以解决这个问题。如果您对不变的固定产品/服务使用固定价格,您可以在 PayPal 网站上create encrypted payment buttons

或者,在接收 IPN 通知的 PHP 脚本中,您可以检查 $_POST['mc_gross'] 中的金额是否与您期望的金额相符。

【讨论】:

  • 嗯,它是一个创建产品的插件。我的意思是一个产品按钮,所以每个按钮的价格都是固定的......
  • 主要的收获是你不能动态地创建加密按钮,你每次想创建一个都必须去PayPal网站。所以这限制了它在某些情况下的用处。无论如何,要绝对确保在处理订单、运送物品等之前,您应该始终检查 IPN 中的数据。
猜你喜欢
  • 2011-11-03
  • 2012-09-17
  • 1970-01-01
  • 2013-10-17
  • 2011-09-05
  • 2013-02-11
  • 2013-01-02
  • 2019-11-03
  • 1970-01-01
相关资源
最近更新 更多