如何使用 PHP 脚本捕获PayPal付款的响应


How to capture response from PayPal payment using PHP script?

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <input type="hidden" name="cmd" value="_s-xclick">
        <input type="hidden" name="hosted_button_id" value="Y43MR9C35KS88">
        <input class="btn btn-success btn-block" type="submit" value="Recharge via PayPal or Credit Card">
</form>

上面的代码是从PayPal企业帐户生成的。这将买家带到PayPal网站,在那里他可以完成付款过程。在生成代码期间,付款金额固定为 20 美元。我需要捕获付款金额和付款确认,以便我可以更新本地数据库表以记录付款。

我该怎么做?

要接收有关已完成/待处理/已取消付款的信息,您应该使用PayPal的即时付款通知(IPN)。您可以在表单中添加一个notify_url,其中包含付款过程后信息应转到的 URL。

有关 IPN 的更多信息(包括字段):https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/

有关可能的表单域的详细信息https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/

要保存/捕获值,您需要读出相关的 $_REQUEST 或 $_GET 变量,例如
$amount = $_REQUEST["mc_gross"];$amount = $_GET["mc_gross"];

希望对您有所帮助,萨沙

您可以将 GET 方法与来自PayPal的响应一起使用。

$amount = $_GET['amt']; 
$currency = $_GET['cc'];
$check_amount = '20.00';
$check_currency='USD';
if($amount==$check_amount && $currency==$check_currency)
{
// Do stuff for correct value
}
else
{
// Do stuff if failed
}