Paypal 中的 IPN 与 PDT

我有一些麻烦选择贝宝的即时支付通知(IPN)和支付数据传输(PDT)。

基本上,用户在我的网站上购买一次性产品,在 PayPal 上支付,然后返回到我的网站。我知道 IPN 是如何工作的,但是我现在看到我可能能够触发各种各样的动作,这些动作在成功购买 PDT 之后更容易发生,因为数据会在那里和那时返回(而不是需要一个单独的监听器)。

然而,PayPal 的 PDT 文档包含这样一句隐晦的话: “ PDT 不适用于信用卡或 Express Checkout 交易。”但我找不到任何关于这个话题的进一步资料。

  1. 信用卡真的不应该与 PDT 一起使用吗? 我想要的不仅仅是一个句子。

  2. 这是否意味着用户必须拥有/创建一个 PayPal 帐户才能支付?

  3. 这是否意味着,如果我想让用户支付与他们的贝宝帐户和/或与信用卡直接,我必须实施 IPN?

经历过这种事的人能说点什么吗?

29685 次浏览

The APIs for PDT and IPN are similar. The main difference is when you receive the notification. For that reason I would recommend implementing both.

  • With PDT you get the notification instantly and can do any additional processing required and show the user a confirmation page.
  • With IPN you are guaranteed to be notified that the payment was received even if the user's computer explodes before it can send you the PDT.

Implement both and get the best of both worlds. But if you're only doing one, IPN is the reliable one.

One catch: if you implement both then there's a chance your payments could be processed twice. Take care to ensure that doesn't happen. The application I wrote handles the PDT and IPN almost identically (the backend part is the same) and that code acquires a per-web-user lock in the database, so that if the same user tries to submit the exact same payment multiple times it can only be processed once. Once processed the result of that process is re-used for any subsequent attempts to process it.

Edit One more thing: IPN carries more information than PDT. There are lots of different messages that you can receive from IPN, such as chargeback notification, etc, and thus you really should implement it.


PayPal's PDT system sends order confirmations to merchant sites that use PayPal Payments Standard and lets them authenticate this information. Such sites can then display this data locally in an "order confirmation" page.

When to Use PDT?

IPN provides the same capabilities described above. So, when should you choose PDT instead of IPN?

With PDT, your site is notified immediately when a customer completes payment. With IPN, however, there is a material lag between the time a customer completes payment and the time your site receives notification of this event.

So, use PDT if your site includes a feature that requires immediate payment notification.

For example, consider a digital music store. With PDT, this store can let customers download their purchases right away since PDT sends order confirmations immediately. With IPN, such immediate order fulfillment is not possible.

Advantages of IPN

PDT has a a major weakness: it sends order confirmations once and only once. As a result, when PDT sends a confirmation, your site must be running; otherwise, it will never receive the message.

With IPN, in contrast, delivery of order confirmations is virtually guaranteed since IPN resends a confirmation until your site acknowledges receipt. For this reason, PayPal recommends that you implement IPN rather than PDT.

Another advantage of IPN is that it sends many types of notifications, while PDT sends just order confirmations. So, using IPN, your site can receive, for example, chargeback notifications as well as order confirmations. Note: If your site must be notified of payments immediately, you can implement both IPN and PDT. However, if you do, your site will receive two order confirmations for each sale. As a result, you must be careful to take action (say, ship a product) on just one copy of a given confirmation message.

Documentation Here

Re 1. PDT is meant to use with Auto Return for Website Payments feature. Auto Return redirects to PDT site after paying money to seller. Unfortunately it's not possible to use that feature along with PayPal Account Optional - used to enable Credit Card payment. Here is note from PayPal: 'If you have turned on Auto Return and have chosen to turn on PayPal Account Optional for new users, a new user will not be automatically directed back to your website, but will be given the option to return.'. User will have an option to go back to your site(PDT step) or stay on PayPal site. To sum it up when paying by Credit Card user can skip PDT step if user will not click 'return to store link'.

Re 2. It is up to you what paying options do you want to allow. If you want to allow paying without a PayPal Account you can enable Account Optional. If you want to allow only users with PayPal accounts disable that feature. There might be more options.

Re 3. In your case you need to trigger action after successful purchase. Recommended way would be to implement IPN. PDT doesn't work for all cases and doesn't guarantee message delivery. Here is link to doc covering that topic PDT vs IPN.

This is an old question, but my simple answer would be - Why not use both PDT and IPN? They will work fine for card transactions.

PDT can provide the immediate transaction status to your website, where you can quickly check the payment success or failure status and provide the user with appropriate message.

Meanwhile, you can await the full verification from IPN in the background. Once received, you can use this to further update your DB and process the order.

You can follow this step-by-step guide which I found to be very clear and helpful - and it's still valid in 2018.

https://www.codexworld.com/paypal-standard-payment-gateway-integration-php/