PHP Paypal header 位置不起作用

标签 php paypal

我有这个 PHP 代码来开始 PayPal 沙盒购买:

$querystring = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$querystring .= "?business=" . urlencode($_PayPalApiUsername) . "&";
$querystring .= "item_name=" . urlencode($premium_item["name"]) . "&";
$querystring .= "item_number=" . urlencode($premium_item["number"]) . "&";
$querystring .= "amount=" . urlencode($premium_item["price"]) . "&";
$querystring .= "currency_code=" . urlencode($_PayPalCurrencyCode) . "&";

$querystring .= "cmd=" . urlencode($_POST["cmd"]) . "&";
$querystring .= "payment_key=" . urlencode(generateRandomString(16)) . "&";

$querystring .= "return=" . urlencode(stripslashes($_PayPalReturnURL)) . "&";
$querystring .= "cancel_return=" . urlencode(stripslashes($_PayPalCancelURL)) . "&";
$querystring .= "notify_url=" . urlencode($_PayPalNotifyURL);

header('location:' . $querystring);
exit();

最后 $querystring 包含:https://www.sandbox.paypal.com/cgi-bin/webscr?business=business%40email.de&item_name=Starter-Kit&item_number= 1000&amount=2.99¤cy_code=EUR&cmd=_xclick&payment_key=7qm5en3B253FPxnu&return=http%3A%2F%2Fexample.com%2Fgame%2Fpremium.php%3Ftask%3Dsuccess&cancel_return=http%3A%2F%2Fexample.com%2Fgame%2Fpremium.php%3 Ftask%3Dcancel¬ify_url =http%3A%2F%2Fexample.com%2Faction%2Fnotify_payment_paypal.php(地址已更改)。

如果我手动将此链接插入浏览器地址行,我将被重定向到 PayPal 结帐页面。所以链接应该是正确的。

但是如果我使用 header location(如代码中所示),我将被重定向到 PayPal Sandbox 的主页 (https://www.sandbox.paypal.com/家).

有人知道哪里出了问题吗?

最佳答案

您必须将数据发布到 Payments Standard。您正试图将它们全部放入查询字符串 (GET)

查看此 example from PayPal

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="herschelgomez@xyzzyu.com">

<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">

<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Hot Sauce-12oz Bottle">
<input type="hidden" name="amount" value="5.95">
<input type="hidden" name="currency_code" value="USD">

<!-- 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 Paypal header 位置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34884554/

相关文章:

php - 用于日程安排和考勤卡系统的最佳 php/mysql 日期格式?

Javascript 验证文件输入名称

php - Mysql子查询多结果

Paypal Rest API 与经典 SDK

php - PayPal Webhook 不发送 POST 数据

magento - Magento 中的 PayPal 订单自动取消

php - Smarty + PHP + mySQL评论系统不显示数据

php - 连接 mysql 表

c# - 如何使用 PayPal 付款预核准

paypal - 使用 paypal checkout,我们可以使用他们的 API 获取哪些信息?