简体   繁体   English

设置 PayPal 返回 URL 到本地主机

[英]Setting PayPal return URL to localhost

I'm trying to integrate Paypal and I'm using sandbox in the process.我正在尝试集成 Paypal 并在此过程中使用沙箱。 I follow the step of the accepted answer in the below question.我按照以下问题中接受的答案的步骤进行操作。 Setting PayPal return URL and making it auto return? 设置 PayPal 返回 URL 并使其自动返回?

But when I try to enter the URL, Paypal return the below error.但是当我尝试输入 URL 时,Paypal 返回以下错误。

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

URL I'm trying to set is http://localhost:8888/paypal/success.php . URL 我试图设置为http://localhost:8888/paypal/success.php

Also I tried sending the return url with the form as below.尝试使用以下表格发送退货 url。

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

Both methods does not work for me.这两种方法对我都不起作用。

Full Form完整形式

<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> 

How can I test this on my development pc?我如何在我的开发电脑上测试这个?

What if you try to specify your IP address instead of localhost? 如果您尝试指定IP地址而不是localhost怎么办?

Local host cannot be resolved on distant machines. 无法在远程计算机上解析本地主机。 It's only your local DNS which knows localhost statement and is 127.0.0.1. 它只是知道localhost语句的本地DNS,并且是127.0.0.1。

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

You can create some URL alias for your website and add it to your hosts file ( http://en.wikipedia.org/wiki/Hosts_(file) ). 您可以为您的网站创建一些URL别名,并将其添加到您的主机文件( http://en.wikipedia.org/wiki/Hosts_(file) )。 Then pass that URL as your return URL to paypal. 然后将该URL作为返回URL传递给paypal。 They just trigger a re-direct within the browser to that location at which point your host file will resolve it to your local development server. 它们只是触发浏览器内的重定向到该位置,此时主机文件将其解析到本地开发服务器。

For Example: Add a line to your hosts file like 127.0.0.1 local.mywebdomain.com 例如:在127.0.0.1 local.mywebdomain.com等主机文件中添加一行

Then in your PayPal button, pass that same URL for the return parameter (eg <input type="hidden" name="return" value="http://local.mywebdomain.com/success.php"> ) 然后在您的PayPal按钮中,为返回参数传递相同的URL(例如<input type="hidden" name="return" value="http://local.mywebdomain.com/success.php">

You can't use localhost it's not a valid URL, PayPal can't access your local enviornment. 您不能使用localhost它不是有效的URL,PayPal无法访问您的本地环境。

Best way is to upload the form and return script to the web, there's a number of free PHP web hosts out there if you don't have one. 最好的方法是上传表单并将脚本返回到网页,如果你没有,那里有很多免费的PHP网络主机。

It is worth noting, that when working with the Facebook authorization API's (and probably others if not all) you can put https://localhost:xxxx/my-redirect in as a redirect URL and it will work.值得注意的是,当使用 Facebook 授权 API(如果不是全部,也可能是其他 API)时,您可以将 https://localhost:xxxx/my-redirect 作为重定向 URL 放入,它会起作用。

Thus, the answers here that basically say "duh..... paypal can't reach localhost on your PC" are a little harsh and off base.因此,这里的答案基本上是说“duh ..... paypal 无法访问您 PC 上的本地主机”,这有点苛刻且离题。

A remote API doesn't need to know how localhost resolves on their end, but in the context of a client side redirect they do not care and presume that the client resolves localhost to where the developer intends.远程 API 不需要知道 localhost 是如何解析的,但在客户端重定向的上下文中,他们不关心并假定客户端将 localhost 解析为开发人员想要的位置。

That said, I will be honest.... the first time I worked with Facebook API's I was a little puzzled as to how localhost can work.也就是说,老实说……我第一次使用 Facebook API 时,我对 localhost 如何工作感到有点困惑。 But it was in the process of that that I developed a fuller understanding of how these types of redirects happen and that they are client side.但正是在这个过程中,我对这些类型的重定向如何发生以及它们是客户端有了更全面的了解。

And that makes a lot of sense because in the far majority of cases, an API that provides authentication, or in this case payment, is going to redirect the client to a url with some type of token that proves their indentity/payment.这很有意义,因为在绝大多数情况下,提供身份验证或在本例中为付款的 API 会将客户端重定向到带有某种类型令牌的 url 来证明其身份/付款。

Yes, paypal also has webhooks, but that is a different beast.是的,paypal 也有 webhooks,但那是另一回事。 Webhooks are when the 3rd party service you are working with will have its back end send a POST to your back end, giving you the official result of some transaction. Webhooks 是指您正在使用的第 3 方服务将让其后端向您的后端发送 POST,从而为您提供某些交易的官方结果。

When I develop things of this nature, I put more weight on these server-to-server communications because I can be sure that if paypal's backend is telling me something happened, then it really did in fact happen and isn't possibly a client side hack.当我开发这种性质的东西时,我更加重视这些服务器到服务器的通信,因为我可以确定如果 paypal 的后端告诉我发生了什么事,那么它确实确实发生了并且不可能是客户端破解。

No one working with webhooks is going to try to put 'localhost'in as a webhook URL, because clearly that makes no sense and couldn't work for server-to-server communication.使用 webhooks 的任何人都不会尝试将“localhost”作为 webhook URL 放入,因为显然这没有意义并且不能用于服务器到服务器的通信。

But when a service redirects a web browser client following a transaction, some developers will assume that localhost can work since it should be a client side redirect and isn't a webhook.但是,当服务在事务后重定向 web 浏览器客户端时,一些开发人员会假设 localhost 可以工作,因为它应该是客户端重定向而不是 webhook。

When a developer that is new to any given API is using 'localhost' in what seems to be a client side redirect to land the user back on the merchant's site, it isn't a "stupid" question at all.当对任何给定的 API 不熟悉的开发人员在似乎是客户端重定向的地方使用“本地主机”以将用户带回商家网站时,这根本不是一个“愚蠢”的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM