PHP: PayPal支付 API 不返回结果?



我使用以下代码:

$enableSandbox = true;
$paypalConfig = [   'email' => 'test-facilitator@gmail.com',
'return_url' => 'http://test.com/paypal/?back',
'cancel_url' => 'http://test.com/paypal/?cancel',
'notify_url' => 'http://test.com/paypal/?notify'];
$paypalUrl = $enableSandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
$itemName = 'Call';
$itemAmount = 5.00;
$data = [];
foreach ($_POST as $key => $value) {
$data[$key] = stripslashes($value);
}
$data['business'] = $paypalConfig['email'];
$data['return'] = stripslashes($paypalConfig['return_url']);
$data['cancel_return'] = stripslashes($paypalConfig['cancel_url']);
$data['notify_url'] = stripslashes($paypalConfig['notify_url']);
$data['item_name'] = $itemName;
$data['amount'] = $itemAmount;
$data['currency_code'] = 'GBP';
$queryString = http_build_query($data);
header('location:' . $paypalUrl . '?' . $queryString);
exit();

但是使用后,我被重定向到 paypal.com 家,并且没有收到任何错误消息:

我也测试了test-buyer@gmail.com,但它不起作用。

如何解决这个问题?

请更新您的代码

$paypalConfig = [   'email' => 'test-facilitator@gmail.com',
'return_url' => 'http://test.com/paypal/?back',
'cancel_url' => 'http://test.com/paypal/?cancel',
// Added new line
'cmd' => '_xclick',
'notify_url' => 'http://test.com/paypal/?notify'];

循环添加foreach

添加了新行

$data['cmd'] = $paypalConfig['cmd'];

然后尝试希望它会起作用。

因为你失踪了:Buy Now buttons — <INPUT TYPE="hidden" name="cmd" value="_xclick">

请管理它并在您的表单构建器中发送cmd,它应该可以工作。如果不起作用,请告诉我。

最新更新