贝宝 notify_url 和 return_url.使用 PHP 在没有 IPN 的情况下接收变量
我正在尝试为 paypal 设置一个简单的付款选项,但在返回和通知 URLS 时遇到了一些问题/困惑.我对 php 还很陌生,以前在 asp 中已经完成了这项工作,但现在我迷路了.
所以我的基本贝宝表格:
正如您所看到的,表单发布到 paypal,然后根据结果返回,如果失败/取消,它会转到 paypal-notcompleted.php.
如果成功,它会转到 paypal-completed.php.这是我无法理解的地方,我还没有设置 IPN,我想做的就是将一些变量 paypal 发回给我,运行一个简单的插入查询并在确认消息中显示一些详细信息给客户.
我可以将 notify_url 和 return_url 设为同一个页面吗?
为什么 paypal 没有发布完整的预期(如下所示:通知 Paypal 的网址) 回到页面?
我知道这与 XML 等有关,但我只是想我将能够 $_GET 贝宝发回的变量.有没有人这样做过,他们能告诉我我哪里出错了吗?
解决方案要将详细信息返回到您的返回 URL,您需要使用 PDT.它与 IPN 非常相似,只是它用于您的返回 URL,而 IPN 旨在与您服务器上的第 3 方IPN 侦听器脚本一起使用.>
PDT 可以简单地在返回 URL 页面上向用户显示交易,但不建议进行任何发布- 使用 PDT 处理付款(即数据库更新、发送电子邮件收据等),因为无法保证用户会做出即使在您的 PayPal 帐户中启用了自动退货,它也会返回到此页面.
IPN 将在每次交易发生时触发,无论用户在完成付款后是否返回您的网站.
通知 URL 仅用于 IPN,它会覆盖您在 PayPal 个人资料中针对 IPN 的任何设置.需要在您的 PayPal 帐户配置文件中配置 PDT 才能将数据返回到您的返回 URL.
您将要使用不同的 URL 进行返回和通知,否则相同的代码将运行两次:一次是在用户返回您的站点时,一次是从 PayPal IPN POST 中返回.
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.
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@hotmail.com">
<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.
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.
Am I allowed to have the notify_url and return_url as the same page?
Why does paypal not post the full expected (as seen here: Notify url of Paypal ) back to the page?
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?
解决方案To return details back to the your return URL you'll need to use PDT. It's very similar to IPN except it's intended for use with your return URL, while IPN is intended for use with a 3rd party IPN listener script on your server.
PDT is 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.
IPN will be triggered every time a transaction occurs regardless of whether or not the user makes it back to your site after completing payment.
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.
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.
相关文章