php - 如何验证 PayPal 返回数据?

标签 php validation paypal payment-gateway paypal-sandbox

我正在集成 paypal,而且我已经正确地完成了。我已经设置了返回 URL,所以它在 url $_GET 中给出了下面的结果集。

Array ( [tx] => 7XV08083GT683520Y [st] => Completed [amt] => 22.16 [cc] => USD [cm] => [item_number] => item_number )

我担心的是无法验证从 Paypal 返回的数据。我有使用其他支付网关的经验。其他支付网关允许您执行 hashMatch,以确保表单提交的数据未被编辑。

我的表格如下。

<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" value="dasun_1358759028_biz@archmage.lk" name="business">
<!-- Specify a Buy Now button. -->
<input type="hidden" value="_xclick" name="cmd">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" value="AM Test Item" name="item_name">
<input type="hidden" value="22.16" name="amount">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" value="item_number" name="item_number">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form> 

我的php代码输出

 <input type="hidden" value="50.16" name="amount">

但是我使用了 Firebug 并将其编辑到下面并付款了。

<input type="hidden" value="22.16" name="amount">

我仍然得到结果,因为它是 Completed 付款,但它不应该是因为我手动进行了更改。任何有知识的人都可以编辑它们。我如何确定这是一笔有效的付款?我怎样才能确保表单数据没有像我一样被编辑?

最佳答案

任何重要的和需要数据库交互的东西都应该使用 Paypals IPN 来处理必须验证的数据。基本上 Paypal 会在您的网站上发布包含数据的 URL,您的脚本将必须回发准确的数据以及一条命令来验证数据是否确实正确。在 Paypal 给出“已验证”响应后,您将更新您的数据。

另一种选择是使用 Paypal 的快速结帐,本质上你得到一个“确定”以向客户收取“x”金额,一旦客户同意支付金额,你将数据发布到 Paypal 并获得客户“同意”如果交易完成与否,您将收到回复。

https://www.paypal.com/ipn

https://www.x.com/developers/paypal/documentation-tools/express-checkout/integration-guide/ECGettingStarted

关于php - 如何验证 PayPal 返回数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14451917/

相关文章:

php - 如何在 zend 框架中访问数据文件夹中的文件?

javascript - 即使表单值未更改,如何强制 jquery 验证器触发验证方法

Paypal 网站支付专业版 : Express Checkout: How to Hide "Purchase Details" in Paypal?

Jquery 表单验证自定义错误放置在 <div> 容器中

forms - 单独呈现的 Paypal 下拉菜单

paypal - payflow 透明重定向总是采取错误 url

javascript - 使用 php、javascript 在 Web 应用程序中使用连接到 PC 的扫描仪

php - WordPress : Need to change text color from a PHP file

php - CakePHP 3 : Empty result set returned while database has rows for same query

c# - IValidatableObject.Validate() 中的本地化