我的代码如下:
$paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$paypal_id = 'payments@business.com';
$str .= "<form method='post' action='".$paypal_url."'>";
$str .= "<input type='hidden' name='business' value='".$paypal_id."'>";
$str .= "<input type='hidden' name='cmd' value='_xclick'>";
$str .= "<input type='hidden' name='item_name' value='Room'>";
$str .= "<input type='hidden' name='item_number' value='".getRoom($id)."'>";
$str .= "<input type='hidden' name='currency_code' value='USD'>";
$str .= "<input type='hidden' name='no_shipping' value='1'>";
$str .= "<input type='hidden' name='amount' id='paypal_cost' value='".getBal($id)."'>";
$str .= "<input name='notify_url' value='http://localhost/tropicana/guests/notify.php' type='hidden'>";
$str .= "<input type='hidden' name='cancel_return' value='http://localhost/tropicana/guests/payments.php'>";
$str .= "<input type='hidden' name='return' value='http://localhost/tropicana/guests/notify.php'>";
$str .= "<button type='submit' name='submit' class='form-control btn-danger'>Pay $".getBal($id)." with <i>PayPal</i>";
$str .= "</form>";
但是在成功付款后,我的返回脚本 notify.php
没有接收到任何变量。
当我尝试 print_r()
$_REQUEST
时,它返回一个空数组。
最佳答案
TL;DR:您的 notify_url
不能是 localhost,因为 PayPal 会向您发送 IPN 消息(从外部),这意味着您的开发机器必须暴露在互联网上。
公开您的计算机的一种方法是使用类似 ngrok 的工具,或类似 serveo 的东西,或类似的。 完成后,将您的 notify_url 设置为该公共(public) URL 以接收 IPN 消息。
但是,请注意:
- 如果您使用免费的 ngrok 选项,您的随机子域(例如 13bf0ee2.ngrok.com)将在每次 ngrok 重新启动时发生变化
- 如果您测试订阅,您之前使用 ngrok notify_url 创建的计划将不再有效,您将不会收到重复的 IPN 消息。
- 因为 PayPal 沙盒是一大垃圾,您可能根本不会收到 IPN 消息,仅仅是因为它们的服务完全损坏。
当然,有时您会摸不着头脑,为什么昨天的事情行得通,今天却不行。最好的选择是抵制他们,并与在该领域真正胜任的人一起继续您的生活和事业。
关于php - Paypal 沙盒不返回任何变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47049890/