php 我可以从本地主机测试paypal api吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5510995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I test paypal api's from localhost
提问by oshirowanen
UPDATE 1:
更新1:
According to this tutorial on Using PayPal's Instant Payment Notification with PHP, PayPal cannot access locally hosted websites unless certain router ports are opened. Is this because the website is about IPN
or is this true for all PayPal APIs?
根据使用 PHP 的 PayPal 即时付款通知教程,除非打开某些路由器端口,否则 PayPal 无法访问本地托管的网站。这是因为该网站IPN
适用于所有 PayPal API 还是适用于所有 PayPal API?
ORIGINAL QUESTION:
原问题:
On my laptop, I have a LAMP
environment setup, when I use the http://localhost
to create website before going live.
在我的笔记本电脑上,我有一个LAMP
环境设置,当我在http://localhost
上线之前使用来创建网站时。
For a new project, I need to use the PayPal APIs. Will I be able to use the localhost to test the PayPal APIs if I connect my laptop to the internet? Or will I have to upload my website to a LAMP host elsewhere?
对于新项目,我需要使用 PayPal API。如果我将笔记本电脑连接到互联网,是否可以使用本地主机来测试 PayPal API?或者我是否必须将我的网站上传到其他地方的 LAMP 主机?
You're probably thinking, what a stupid question, just try it to see if it works. I have tried it and it's not working and I wanted to rule out this question before going onto the next step.
你可能在想,多么愚蠢的问题,试试看是否有效。我已经试过了,但它不起作用,我想在进入下一步之前排除这个问题。
采纳答案by Mihai Frentiu
It should work. I have made a payment integration with paypal last year, and it worked on localhost without problems.
它应该工作。去年我已经与贝宝进行了支付集成,它在本地主机上运行没有问题。
Are you using the paypal sandbox for development? https://developer.paypal.com/
您是否使用贝宝沙箱进行开发? https://developer.paypal.com/
回答by Brad Parks
If you want to debug your IPN code, you'll need to make your server publicly available in some way. This is so PayPal can asynchronously post back to your server at a later time after you've submitted your request. Usually this is pretty quick I think (within 15 seconds) but it could be longer.
如果您想调试您的 IPN 代码,您需要以某种方式公开您的服务器。这样 PayPal 就可以在您提交请求后异步回发到您的服务器。我认为这通常很快(在 15 秒内),但可能会更长。
One easy way I've found to make a development server available publicly is to use ngrok, or forwardhq.com. This allows you to continue to develop in your IDE like normal, running your code in debug mode. When PayPal posts back to your endpoint, you can debug it right there in your IDE. These services wrap this up for you, so it's very easy to do without any technical know how.
我发现使开发服务器公开可用的一种简单方法是使用ngrok或forwardhq.com。这允许您像往常一样继续在您的 IDE 中进行开发,在调试模式下运行您的代码。当 PayPal 回发到您的端点时,您可以直接在您的 IDE 中对其进行调试。这些服务为您完成了这些,因此无需任何技术知识即可轻松完成。
From my understanding, this is done using a "reverse SSH tunnel" which allows your site to be made public by proxying it through a server that's already publicly available. Note that before you do this, you have to consider that not just PayPal can hit your site once it's made public, but anyonecan, so please take that into consideration first.
根据我的理解,这是使用“反向 SSH 隧道”完成的,该隧道允许您的站点通过已经公开可用的服务器代理来公开。请注意,在您执行此操作之前,您必须考虑到,一旦您的网站公开,不仅 PayPal 可以访问您的网站,任何人都可以,因此请先考虑这一点。
Also, if you've got your own public facing domain and don't mind playing around in a terminal with SSH, you can supposedly do something like this shell script (copied from this gist)
此外,如果您有自己的面向公众的域并且不介意在终端中使用 SSH,那么您应该可以执行类似此 shell 脚本的操作(从该 gist 复制)
# Usage: show <local-port> <subdomain>
function show() {
DOMAIN=".yourdomain.com"
REMOTE="$DOMAIN"
ssh -tR 1080:127.0.0.1: vps "sudo ssh -Nl $USER -L $REMOTE:80:127.0.0.1:1080 localhost"
}
To get this to work as above, you'd need to put the following in your ~/.ssh/config file:
要使其按上述方式工作,您需要将以下内容放入 ~/.ssh/config 文件中:
Host vps
HostName <server address>
User <server username>
If you don't want to (or can't) do this, then the following will work:
如果您不想(或不能)这样做,那么以下方法将起作用:
SERVERUSER="<server username>"
ssh -l $SERVERUSER -tR 1080:127.0.0.1: <server address> "sudo ssh -Nl $SERVERUSER -L $REMOTE:80:127.0.0.1:1080 localhost"
回答by Mauro Mascia
One simple solution is described in the official developers page of PayPal:
PayPal 的官方开发人员页面中描述了一种简单的解决方案:
developer.paypal.com - Local IPN Testing
developer.paypal.com - 本地 IPN 测试
The trick consists on writing a small HTML file with this content:
诀窍在于使用以下内容编写一个小的 HTML 文件:
<form target="_new" method="post" action="https://www.YourDomain.com/Path/YourIPNHandler.php">
<!-- start example variables: -->
<input type="hidden" name="SomePayPalVar" value="SomeValue1"/>
<input type="hidden" name="SomeOtherPPVar" value="SomeValue2"/>
<!-- /end example variables -->
<input type="submit"/>
</form>
To get the real results you need to copy all of the IPN variables which PayPal sends. These real variables can be found into the PayPal account, under IPN History:
要获得真实结果,您需要复制 PayPal 发送的所有 IPN 变量。这些真实变量可以在 PayPal 账户的 IPN 历史记录下找到:
You need to click on the relative Message ID and then copy the "IPN Message" content (it will be something like mc_gross=27.00&invoice=Test-1&protection_eligibility=Ineligible&...) which must be converted into HTML hidden input fields. For example:
您需要单击相关的消息 ID,然后复制必须转换为 HTML 隐藏输入字段的“IPN 消息”内容(类似于 mc_gross=27.00&invoice=Test-1&protection_eligibility=Ineligible&...)。例如:
<input type="hidden" name="mc_gross" value="27.00"/>
<input type="hidden" name="invoice" value="Test-1"/>
<input type="hidden" name="protection_eligibility" value="Ineligible"/>
....
After setting up all of these variables and changing the action URL, you can open the file with a browser and then submit this form.
设置所有这些变量并更改操作 URL 后,您可以使用浏览器打开文件,然后提交此表单。
回答by Mark Gia Bao Nguyen
If http://localhostdoesn't validate use http://127.0.0.1
回答by jishi
It should work without a problem, however it might get picky if you send in "invalid URLs" for return urls and IPN message urls. Meaning, sending in http://localhost/cancelpaypal.phpas cancelURL might tell you that it is an invalid url.
它应该可以正常工作,但是如果您为返回 url 和 IPN 消息 url 发送“无效的 URL”,它可能会变得挑剔。意思是,将http://localhost/cancelpaypal.php作为 cancelURL发送可能会告诉您这是一个无效的 url。
I do however don't think it should.
但是我认为不应该。
Having to open up router ports would only be needed for IPN, because the redirect in the normal flow is a regular "Location:" header hence it is your browser that needs to be able to access the site (localhost)
只有 IPN 才需要打开路由器端口,因为正常流中的重定向是常规的“位置:”标头,因此您的浏览器需要能够访问站点(本地主机)
回答by jamesjara
Well, it most works, but also, you can setup a temporary local dns entry. All you have to do is:
嗯,它最有效,而且,您还可以设置一个临时的本地 dns 条目。您所要做的就是:
- open your /etc/hosts
- add a new entry: yourwebsite.com 127.0.0.1
- 打开你的 /etc/hosts
- 添加新条目:yourwebsite.com 127.0.0.1
So when your browser query for the website will be fetched from your 127.0.0.1, somethings your need to flush dns( /etc/init.d/nscd restart).
因此,当您的浏览器查询将从您的 127.0.0.1 获取时,您需要刷新 dns(/etc/init.d/nscd restart)。
and that is it all, but remember to remove the entry when you are ready for production.
就是这样,但是请记住在准备好进行生产时删除该条目。
回答by axroth
To use IPN your localhost has to be accessed from the web. One solution that definitly works is to use a virtual Machine, install VPN-Server, connect your Clinet via VPN and manage virtual host to redirect to your local IP-adress. That way, if you turn on VPN your server can be accessed from outside and IPN can be sent.
要使用 IPN,必须从 Web 访问您的本地主机。一种绝对有效的解决方案是使用虚拟机,安装 VPN 服务器,通过 VPN 连接您的 Clinet 并管理虚拟主机以重定向到您的本地 IP 地址。这样,如果您打开 VPN,您的服务器可以从外部访问,并且可以发送 IPN。