php 简单的 Paypal IPN 示例?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/683332/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:29:14  来源:igfitidea点击:

Simple Paypal IPN examples?

phppaypalpaypal-ipn

提问by dot

I would like to have a text input form with a submit button that goes to paypal, upon payment the contents of the form should go in a mysql database..

我想要一个带有提交按钮的文本输入表单,该表单可以转到贝宝,付款后表单的内容应该进入 mysql 数据库..

This sounds trivial, but I'm having such a hard time with paypal's IPN.

这听起来微不足道,但我在使用 paypal 的 IPN 时遇到了困难。

Can anyone point in me in the right direction?

任何人都可以指出我正确的方向吗?

Thanks!

谢谢!

采纳答案by u7867

PayPal has some sample code on their website. However the bigger problem you'll face is that the user will probably want a real-time response. This is usually done by processing the PDT data that is submitted to your site when the user clicks the link to return to your site. At some point later PayPal will post to your IPN url similar data. You need to avoid processing the data twice.

PayPal 在他们的网站上有一些示例代码。然而,您将面临的更大问题是用户可能需要实时响应。这通常是通过处理当用户单击链接返回到您的站点时提交到您的站点的 PDT 数据来完成的。稍后,PayPal 会将类似数据发布到您的 IPN 网址。您需要避免两次处理数据。

Also the data in question is only PayPal's data about the transaction. It does not contain arbitrary data. You should probably record the customer's order before sending them to paypal, or else look for a pass-through variable. For example, when creating a billing agreement, there is a variable called customwhich is passed back to you as you created it. You can store an order id or whatever you want in that variable. Be careful to validate its contents to make sure it's still correct for the transaction details.

此外,有问题的数据只是贝宝有关交易的数据。它不包含任意数据。您可能应该在将客户的订单发送到贝宝之前记录他们的订单,或者寻找传递变量。例如,在创建计费协议时,有一个称为变量的变量custom,它会在您创建时传回给您。您可以在该变量中存储订单 ID 或任何您想要的内容。请小心验证其内容,以确保它对于交易详细信息仍然正确。

回答by chaos

You don't, and can't, get the entire contents of the form back from Paypal. What you will get is a postback to the address you sent in the "return" field. The best way to pass arbitrary information through the process from your form to the postback is in the "item_number" field (preferably by using it as an ID in your database linked to whatever information you want to track).

您不能,也不能从 Paypal 取回表单的全部内容。您将收到回发到您在“退货”字段中发送的地址。在整个过程中将任意信息从表单传递到回发的最佳方法是在“item_number”字段中(最好将其用作数据库中链接到您要跟踪的任何信息的 ID)。

回答by Josh1billion

I know this question was already answered years ago, but for those who stumble upon it in the future...

我知道这个问题早在几年前就已经回答过了,但对于那些在未来偶然发现它的人......

I found this class + example to be particularly useful, so much so that I've re-used it for countless projects: http://www.micahcarrick.com/php-paypal-ipn-integration-class.html

我发现这个类 + 示例特别有用,以至于我将它重新用于无数项目:http: //www.micahcarrick.com/php-paypal-ipn-integration-class.html

Update:The page is offline now, but there's an archived version here which still has a working download link: https://web.archive.org/web/20140210202247/http://www.micahcarrick.com/php-paypal-ipn-integration-class.html

更新:该页面现在离线,但这里有一个存档版本,它仍然有一个有效的下载链接:https: //web.archive.org/web/20140210202247/http: //www.micahcarrick.com/php-paypal- ipn-integration-class.html

And here's a direct link to the archived download: https://web.archive.org/web/20140210202247/http://www.micahcarrick.com/files/paypal-1.3.0.zip

这是存档下载的直接链接:https: //web.archive.org/web/20140210202247/http: //www.micahcarrick.com/files/paypal-1.3.0.zip

From the archived page, the author also links to a new version of his library, which is probably the better option now: https://github.com/Quixotix/PHP-PayPal-IPN

从存档页面,作者还链接到他的库的新版本,这可能是现在更好的选择:https: //github.com/Quixotix/PHP-PayPal-IPN

回答by Sire

This PHP sampleshould help you get started with IPN.

这个 PHP 示例应该可以帮助您开始使用 IPN。

Here you can find the PHP API for PayPal, which might be useful even though it doesn't include sample that deals with IPN.

在这里您可以找到PayPal的 PHP API,即使它不包含处理 IPN 的示例,它也可能很有用。

回答by Jazz009

You will find some examples of IPN Script if you follow this link

如果您点击此链接,您将找到一些 IPN 脚本示例

https://paypaltech.com/SG2/

https://paypaltech.com/SG2/

Just select your programming language and the type of script that you are loonking for.

只需选择您的编程语言和您正在寻找的脚本类型。

回答by SoftwareDev

Am guessing what you want is to make a form that when the user clicks the submit button is taken to paypal and then back to your site where you can get YOUR form's content?

我猜你想要的是制作一个表单,当用户点击提交按钮时,它会被带到贝宝,然后回到你的网站,在那里你可以获得表单的内容?

I haven't see people do this, what I've seen people do is that when the user submits the form they are taken to a script to process the form and in that script they are redirected to paypal which is where they pay, you can then use IPN to process paypal's response.

我没有看到人们这样做,我看到人们做的是,当用户提交表单时,他们被带到一个脚本来处理表单,在该脚本中,他们被重定向到他们支付的贝宝,你然后可以使用 IPN 处理贝宝的响应。