将PayPal返回URL设置为localhost

时间:2013-01-21 10:19:08

标签: php paypal payment-gateway sandbox paypal-sandbox

我正在尝试整合Paypal,我正在使用沙盒。我按照下面问题中接受的答案的步骤。 Setting PayPal return URL and making it auto return?

但是当我尝试输入网址时,Paypal会返回以下错误。

We were unable to validate the URL you have entered. Please check your entry and try again.

我要设置的网址是http://localhost:8888/paypal/success.php

我尝试使用下面的表单发送返回网址。

<input type="hidden" name="return" value="http://localhost:8888/paypal/success.php">

这两种方法对我都不起作用。

完整表格

<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">
<input type="hidden" name="return" value="http://localhost:8888/paypal/success.php">
<!-- 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> 

如何在我的开发电脑上测试?

3 个答案:

答案 0 :(得分:14)

如果您尝试指定IP地址而不是localhost,该怎么办?

无法在远程计算机上解析本地主机。它只是知道localhost语句的本地DNS,并且是127.0.0.1。

http://your-IP-address:8888/paypal/success.php

答案 1 :(得分:5)

您可以为您的网站创建一些网址别名,并将其添加到您的主机文件(http://en.wikipedia.org/wiki/Hosts_(file))。然后将该URL作为返回URL传递给paypal。它们只是在浏览器中触发重定向到该位置,此时主机文件将把它解析到本地开发服务器。

例如: 在您的主机文件中添加一行,例如127.0.0.1 local.mywebdomain.com

然后在您的PayPal按钮中,为返回参数传递相同的网址(例如<input type="hidden" name="return" value="http://local.mywebdomain.com/success.php">

答案 2 :(得分:1)

您无法使用localhost,因为它不是有效的网址,PayPal无法访问您当地的环境。

最好的方法是上传表单并将脚本返回到网络,如果你没有,那么有很多免费的PHP网络主机。