简体   繁体   English

将PayPal IPN集成到网站中

[英]Integrating PayPal IPN into website

I am working on a donations page which allows a user to enter a donation amount and then pay with PayPal. 我正在捐赠页面上工作,该页面允许用户输入捐赠金额,然后使用PayPal付款。 I have successfully created a sandbox account with PayPal. 我已经使用PayPal成功创建了一个沙箱帐户。 Once this has been done, I created a business account in order to receive payments and a personal account to make payments. 完成此操作后,我创建了一个业务帐户以便接收付款,并创建了一个个人帐户进行付款。

What I am trying to do is to make use of the Instant Payment Notification feature, which allows the developer to verify that the user actually made the transaction on PayPal's payment page (so that I can record it in the database). 我要做的是利用即时付款通知功能,该功能使开发人员可以验证用户是否确实在PayPal的付款页面上进行了交易(以便可以将其记录在数据库中)。

I tried posting the URL of my IPN page on the business account. 我尝试将IPN页面的URL发布到企业帐户上。 The problem is that it is not accepting the URL. 问题在于它不接受URL。 This is the URL I am providing: 这是我提供的URL:

http://localhost:54866/Default.aspx HTTP://本地主机:54866 / Default.aspx的

The website is not hosted online. 该网站不是在线托管的。 How can this be done please? 请问该怎么做? How should I provide the URL? 我应该如何提供URL? Thanks :) 谢谢 :)

PS I am using C# and ASP.NET PS我正在使用C#和ASP.NET

Yup you are right you can't give localhost (it would try to resolve to paypals own server then...) so you have to do some trickery. 是的,您是对的,您不能给localhost(它会尝试解析为Paypals自己的服务器...),因此您必须进行一些欺骗。

What you need to do is: 您需要做的是:

Lets say your shop is going to be www.mynewshop.com 假设您的商店将是www.mynewshop.com

1) set that up in paypal as the IPN redirect 1)在paypal中将其设置为IPN重定向

2) Change your HOST file to redirect www.mynewshop.com to 127.0.0.1 (eg localhost) 2) 更改您的HOST文件,以将www.mynewshop.com重定向到127.0.0.1(例如localhost)

You can test step 2 is working by trying to type eg www.mynewshop.com in the browser - If you have a server on port 80 it will resolve to localhost:80 or say you have devweb server running on :1234 type www.mynewshop.com:1234 in browser address bar and check resolves 您可以通过尝试在浏览器中键入例如www.mynewshop.com来测试第2步是否正常工作-如果端口80上有服务器,它将解析为localhost:80或说您有devweb服务器在:1234上运行键入www.mynewshop .com:1234在浏览器地址栏中并检查解析

3) set your port on the project to be :80 (as you cannot specify anything other than :80 in paypal either I think). 3)将项目上的端口设置为:80(因为我认为您不能在paypal中指定除:80以外的任何值)。 You can set the project test server port via project.properties - set it to NOT dynamic port and then you can set the fixed :80 您可以通过project.properties设置项目测试服务器端口-将其设置为NOT动态端口,然后可以设置固定的:80

What will happen is Paypal tries to redirect you back to www.mynewshop.com which your pc tries to access but behind the scenes you end up at localhost. 将会发生的事情是Paypal尝试将您重定向回www.mynewshop.com,您的PC尝试访问该网站,但在后台您最终进入了localhost。

From memory you can also set project properies to start the browser at eg www.mynewshop.com which means even in development you appear to be using live URL. 您还可以从内存中设置项目属性,以从www.mynewshop.com启动浏览器,这意味着即使在开发中,您似乎仍在使用实时URL。 This can have its advantages eg it will help you spot incorrect URL/deployment differences due to localhost vs live host URL. 这可能有其优点,例如,它将帮助您发现由于本地主机和实时主机URL导致的URL /部署错误。

Have fun! 玩得开心! :) (and mark this as answer - I know it works because I solved this myself a long time ago) :)(并将其标记为答案-我知道它是有效的,因为很久以前我自己解决了这个问题)

You will have to set up a port forward on your router. 您将必须在路由器上设置端口转发。 "localhost" is not publically routable so PayPal cannot reach it. “本地主机”不可公开路由,因此PayPal无法访问。

If you forward a port on your router (public IP) to the local PC, you can use an IP address and port combination as your IPN url for testing. 如果将路由器(公用IP)上的端口转发到本地PC,则可以使用IP地址和端口组合作为IPN url进行测试。 Eg 1.2.3.4:8080 which would forward to your test server's internal IP address. 例如1.2.3.4:8080 ,它将转发到测试服务器的内部IP地址。

PayPal IPN works by contacting your server after the transaction has taken place or when information about the transaction changes so PayPal MUST be able to reach your IPN URL. 交易发生后或有关交易的信息发生更改时,贝宝IPN会通过与您的服务器联系来工作,因此贝宝必须能够访问您的IPN URL。 It is independent of your hosts file or any of your visitors. 它独立于您的主机文件或任何访问者。

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

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