2013-01-21 39 views
7

我正在嘗試整合PayPal,並在此過程中使用沙箱。我在下面的問題中遵循接受的答案的步驟。 Setting PayPal return URL and making it auto return?將PayPal返回URL設置爲localhost

但是當我嘗試輸入URL時,Paypal返回下面的錯誤。

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

URL我想要設置的是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="[email protected]" 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> 

如何測試這個對我的開發PC?

回答

12

如果您嘗試指定您的IP地址而不是本地主機,該怎麼辦?

本地主機無法在遠端機器上解析。它只是你本地的DNS,它知道localhost語句,並且是127.0.0.1。

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

您不能使用localhost它不是一個有效的URL,貝寶無法訪問您的本地環境。

最好的方法是上傳表單並返回腳本到網絡上,如果沒有的話,那裏有許多免費的PHP網頁主機。

+0

我有同樣的想法,在首先,但上面的答案幫助我。無論如何感謝 – Techie

+1

此外,這是不正確的。我在本地進行了所有的測試,並且PayPal使用本地主機地址作爲返回URL沒有任何問題。只有在測試IPN時,您需要使用公共Web服務器。 –

+1

問題是'自動返回',這在使用本地主機時不起作用。但是,您可以將返回網址設置爲localhost,並且在貝寶步驟中單擊返回(無論名稱)。它會返回到本地主機url,但是在實際嘗試調試和測試自動返回時,這是一個問題! – leen3o

4

您可以爲您的網站創建一些URL別名並將其添加到您的主機文件(http://en.wikipedia.org/wiki/Hosts_(file))。然後將該URL作爲您的返回網址傳遞給paypal。他們只是觸發在瀏覽器中重定向到該位置,此時您的主機文件將將其解析到本地開發服務器。

例如: 添加一行到您的主機文件像127.0.0.1 local.mywebdomain.com

然後在你的PayPal按鈕,通過同一網址爲回報參數(例如<input type="hidden" name="return" value="http://local.mywebdomain.com/success.php">