贝宝 notify_url 和 return_url。使用 PHP 在没有 IPN 的情况下接收变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13415964/
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
Paypal notify_url and return_url. Receiving variables without IPN using PHP
提问by Bohdi
I am trying to set up a simple payment option to paypal, but am having some trouble/confusion with the return and notify URLS. I am fairly new to php and have accomplished this previously in asp, but I have now become lost.
我正在尝试为 paypal 设置一个简单的付款选项,但是在返回和通知 URLS 时遇到了一些麻烦/困惑。我对 php 还很陌生,以前在 asp 中已经完成了这项工作,但现在我迷路了。
SO my basic paypal form:
所以我的基本贝宝表格:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="PayPalForm" name="PayPalForm" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="amount" value="0.01">
<input type="hidden" name="item_name" value="Composite Door">
<input type="hidden" name="item_number" value="<?php echo $orderID ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="cancel_return" value="http://www.mydomain.co.uk/paypal-notcompleted.php">
<input type="hidden" name="return" value="http://www.mydomain.co.uk/paypal-completed.php">
<input type="hidden" name="notify_url" value="http://www.mydomain.co.uk/paypal-completed.php">
</form>
<script>
document.PayPalForm.submit();
</script>
As you can see the form posts to paypal, and then returns depending on the outcome, if failed/cancelled it goes to paypal-notcompleted.php.
如您所见,表单发布到 paypal,然后根据结果返回,如果失败/取消,它会转到 paypal-notcompleted.php。
If its successful it goes to paypal-completed.php. And this is where I am unable to understand, I haven't set up an IPN, all I want to do is grab some of the variables paypal posts back to me, to run a simple insert query and display some details in a confirmation message to the customer.
如果它成功,它会转到 paypal-completed.php。这是我无法理解的地方,我还没有设置 IPN,我想要做的就是将一些变量 paypal 发回给我,运行一个简单的插入查询并在确认消息中显示一些详细信息给客户。
Am I allowed to have the notify_url and return_url as the same page?
我可以将 notify_url 和 return_url 作为同一页面吗?
Why does paypal not post the full expected (as seen here: Notify url of Paypal) back to the page?
为什么 paypal 没有将预期的全部内容(如下所示:Notify url of Paypal)发布回页面?
I understand there is something to do with XML and such, but I just figured that I would be able to $_GET the variables that paypal sent back. Has anyone done it this way, can they tell me where I am going wrong?
我知道这与 XML 等有关,但我只是想我可以 $_GET 贝宝发回的变量。有没有人这样做过,他们能告诉我哪里出错了吗?
回答by Drew Angell
To return details back to the your return URL you'll need to use PDT. It's very similar to IPNexcept it's intended for use with your return URL, while IPNis intended for use with a 3rd party IPNlistener script on your server.
要将详细信息返回到您的返回 URL,您需要使用PDT。它与IPN非常相似,只是它旨在与您的返回 URL 一起使用,而IPN旨在与您服务器上的第 3 方IPN侦听器脚本一起使用。
PDTis fine for simply displaying transaction to the user on the return URL page, but it's not recommended to do any any post-payment processing with PDT(ie. database updates, sending out email receipts, etc.) because there is no guarantee the user will make it back to this page, even with Auto-Return enabled in your PayPal account.
PDT可以简单地在返回 URL 页面上向用户显示交易,但不建议使用PDT进行任何付款后处理(即数据库更新、发送电子邮件收据等),因为无法保证即使在您的 PayPal 帐户中启用了自动返回,用户也会返回此页面。
IPNwill be triggered every time a transaction occurs regardless of whether or not the user makes it back to your site after completing payment.
每次发生交易时都会触发IPN,无论用户在完成付款后是否返回您的网站。
The notify URL is used for IPN only, and it would override any setting you have in your PayPal profile for IPN. PDT needs to be configured in your PayPal account profile in order to get data returned to your return URL.
通知 URL 仅用于 IPN,它将覆盖您在 PayPal 配置文件中针对 IPN 的任何设置。需要在您的 PayPal 帐户配置文件中配置 PDT 才能将数据返回到您的返回 URL。
You're going to want to use different URL's for return and notify, otherwise that same code would run twice: once when the user returns to your site, and again from the PayPal IPN POST.
您将要使用不同的 URL 进行返回和通知,否则相同的代码将运行两次:一次是在用户返回您的站点时,一次是从 PayPal IPN POST。
回答by Patanjali
Payment Data Transfer (PDT)
支付数据传输 (PDT)
The returnand cancel_returnurls are one-off Payment Data Transfer (PDT) calls primarily so the user completes the transaction on your site. It is only passing information to reasonably help your site fulfil that task. There is no guarantee that a buyer will not quit before returning, so you cannot rely upon being able to do anypost-transaction processing using these.
在return和cancel_returnURL是一次性付款数据传输(PDT)调用主要目的是让用户完成网站上的交易。它只是传递信息以合理地帮助您的站点完成该任务。不能保证买家在退货前不会退出,因此您不能依赖能够使用这些进行任何交易后处理。
Instant Payment Notification (IPN)
即时付款通知 (IPN)
notify_urlis used by the Instant Payment Notification (IPN) process, and called with eachchange in the transaction status. It is meant to be a complete record of allactions taken during the transaction lifecycle, upon which you can rely to drive backend process, like accounting, order fulfilment or cancellation. The IPN process takes measures to ensure the integrity of the process.
notify_url由即时付款通知 ( IPN) 流程使用,并在交易状态的每次更改时调用。它旨在完整记录交易生命周期中采取的所有操作,您可以依靠它来驱动后端流程,例如会计、订单履行或取消。IPN 流程采取措施确保流程的完整性。
Their purposes are different and thus the information and security involved is different. For pros and cons.
它们的目的不同,因此所涉及的信息和安全性也不同。对于利弊。
IPN messages can be severely delayed, so use all three variables
IPN 消息可能会严重延迟,因此请使用所有三个变量
Note that while most IPN messages are sent within a few seconds of the PayPal transaction being completed, I have experienced delays of up to several hours, so they are reliable, but not necessarily timely.
请注意,虽然大多数 IPN 消息是在 PayPal 交易完成后几秒钟内发送的,但我经历了长达几个小时的延迟,因此它们是可靠的,但不一定及时。
I would suggest using all of return, return_canceland notify_url, as the former two will return immediately, so that you can provide immediate feedback to the user, and update backend data/instigate fulfilment processes, but use the latter as a backup if the user quits PayPal before the being returned. Indicate to your buyers to return to your site to ensure timely processing of their order.
我建议使用所有return,return_cancel和notify_url,因为前两者会立即返回,以便您可以立即向用户提供反馈,并更新后端数据/发起履行流程,但如果用户之前退出 PayPal,则使用后者作为备份被退回。指示您的买家返回您的网站,以确保及时处理他们的订单。
Just have to manage order status so that the IPN doesn't trigger fulfilment if the PDT has already done so, which is basically what you have to do to ensure that repeated CompletedIPN messages don't retrigger fulfilment after the first.
只需要管理订单状态,以便在 PDT 已经这样做的情况下 IPN 不会触发履行,这基本上是您必须做的以确保重复的CompletedIPN 消息不会在第一次之后重新触发履行。
Notify_urlcontinues to be used for subsequent messages for the same transaction
Notify_url继续用于同一事务的后续消息
IPN messages for the same transaction continue to go to the same notify_urladdress. I viewed our IPN history, and a RefundIPN message went to the original notify_url.
同一事务的 IPN 消息继续发送到同一notify_url地址。我查看了我们的 IPN 历史记录,一条RefundIPN 消息转到了原始notify_url.
That continues, even if you change IPN preferences, as per https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSetup/:
即使您根据https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSetup/更改 IPN 首选项,情况也会继续:
The IPN message is always sent to your notification URL unless you have disabled the preference to receive IPN messages. Even though you have not enabled receiving IPN messages in your Profile or you have reset your preference by turning off IPN messages, PayPal still sends IPN messages to the notification URL you specify for a specific payment.IPN messages not sent because you disabled the preference in your Profile will appear in the IPN history when you enable receiving IPNs. After they appear in the history, you can choose whether to resend them.
IPN 消息始终发送到您的通知 URL,除非您已禁用接收 IPN 消息的首选项。即使您没有在您的个人资料中启用接收 IPN 消息,或者您已通过关闭 IPN 消息重置您的偏好,PayPal 仍会将 IPN 消息发送到您为特定付款指定的通知 URL。当您启用接收 IPN 时,IPN 消息将出现在 IPN 历史记录中,因为您禁用了配置文件中的首选项而未发送。当它们出现在历史记录中后,您可以选择是否重新发送它们。
I am unsure of whether related transactions, like disputes, or subsequent subscription payments, will still use the original notify_url. Perhaps someone who actually knows can provide an answer.
我不确定相关交易(如争议或后续订阅付款)是否仍会使用原始notify_url. 也许真正知道的人可以提供答案。
回答by user2374680
your notify-url and return url both are different . your return url direct your customer after the successful payment with some return information. by the way notify url is to get the complete transaction details of your customers purchase and which can't be accessed by your customer and this is for your database or storage purpose.
您的通知网址和返回网址都不同。成功付款后,您的退货网址会使用一些退货信息引导您的客户。顺便说一下,通知 url 是为了获取您的客户购买的完整交易详细信息,您的客户无法访问这些详细信息,这是为了您的数据库或存储目的。

