PayPal IPN 唯一标识符

发布于 2025-01-04 14:23:37 字数 815 浏览 0 评论 0原文

我一直假设通过 IPN 消息发送的 txn_id 是唯一的。 PayPal 指南似乎支持这个想法 - https://cms.paypal .com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro

避免重复的 IPN 消息。检查您是否尚未处理由 IPN 消息中返回的事务 ID 标识的事务。您可能需要将 IPN 消息返回的事务 ID 存储在文件或数据库中,以便检查重复项。如果 PayPal 发送的交易 ID 重复,您不应再次处理。

但是我发现 PayPal 的电子支票付款 IPN 使用相同的交易 ID 发送了两次。首次付款期间,payment_status 为“待处理”;几天后,当电子支票实际处理时,payment_status 为“已完成”。

我想存储这两个交易,但仍然想避免存储重复项。 IPN 中还有一个名为 ipn_track_id 的字段,它对于两个事务来说都是不同的,但我找不到它的文档,除了这个模糊的描述:

内部;仅供 MTS 和 DTS 使用

还有其他人在使用 ipn_track_id 来唯一标识 IPN 消息吗?

I always assumed that txn_id sent with IPN message is unique. PayPal guidelines seem to support this idea - https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro

Avoid duplicate IPN messages. Check that you have not already processed the transaction identified by the transaction ID returned in the IPN message. You may need to store transaction IDs returned by IPN messages in a file or database so that you can check for duplicates. If the transaction ID sent by PayPal is a duplicate, you should not process it again.

However I found that PayPal's eCheck payment IPN is sent twice with the same transaction ID. Once during initial payment with payment_status as "Pending" and again after couple days when eCheck is actually processes with payment_status as "Completed".

I want to store both transactions, but still would like to avoid storing duplicates. There is another field in IPN called ipn_track_id and it's different for both transactions, but I can't find documentation for it, except this vague description:

Internal; only for use by MTS and DTS

Anyone else is using ipn_track_id to uniquely identify IPN messages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

过期情话 2025-01-11 14:23:37

不应使用 ipn_track_id;主要是因为如上所述,这仅供内部使用,并且因为它对于每个 IPN 消息都是唯一的。
txn_id 对于每笔交易都是唯一的,而不是每条 IPN 消息。

这意味着什么;一笔交易可以有多个 IPN 消息。例如,eCheck,默认情况下它将处于“待处理”状态,一旦 eCheck 清除,它将处于“完成”状态。
但您也可能会看到针对同一 txn_id 的撤销、取消的撤销、打开的案例和退款。

伪代码:

If not empty txn_id and txn_type = web_accept and payment_status = Completed  
    // New payment received; completed. May have been a transaction which was pending earlier.
    Update database set payment_status = Completed and txn_id = $_POST['txn_id']  

If not empty txn_id and txn_type = web_accept and payment_status = Pending  
    // New payment received; completed  
    Update database set payment_status = Pending and payment_reason = $_POST['pending_reason'] and txn_id = $_POST['txn_id']

您可以在 https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables#id08CTB0S055Z

基本上; PayPal 将生成一个唯一的卖家交易 ID。此交易 ID 在“完成”之前可能会经历各个阶段,因此您需要能够处理这些异常。

至于PayPal在文档中的注释:如果在传送过程中遇到错误,PayPal可能会重新发送个别IPN消息。例如,只要 PayPal POST 向其发送 IPN 数据,您的脚本就需要返回正确的 HTTP/1.1 200 OK HTTP 状态响应。
如果您不返回 HTTP/1.1 200 OK 响应,PayPal 将针对每条 IPN 消息重新尝试发送相同数据最多 16 次。

注意:卖方的交易 ID 与买方的交易 ID 不同,因为它们是两种不同的操作(一项借方,一项贷方)。

ipn_track_id shouldn't be used; mainly because this is for internal use only as stated, and because it's unique for every IPN message.
The txn_id is unique for each transaction, not each IPN message.

What this means is; one transaction can have multiple IPN messages. eCheck, for example, where it will go in a 'Pending' state by default, and 'Complete' once the eCheck has cleared.
But you may also see reversals, canceled reversals, cases opened and refunds against the same txn_id.

Pseudo code:

If not empty txn_id and txn_type = web_accept and payment_status = Completed  
    // New payment received; completed. May have been a transaction which was pending earlier.
    Update database set payment_status = Completed and txn_id = $_POST['txn_id']  

If not empty txn_id and txn_type = web_accept and payment_status = Pending  
    // New payment received; completed  
    Update database set payment_status = Pending and payment_reason = $_POST['pending_reason'] and txn_id = $_POST['txn_id']

You can find a lot more IPN variables listed on https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables#id08CTB0S055Z

Basically; PayPal will generate a unique seller transaction ID. This tranaction ID may go through various stages before it's 'Completed', so you'll need to be able to handle these exceptions.

As for PayPal's note in the documentation: PayPal may resend individual IPN mesages if it encounters errors during delivery. For example, it's required for your script to return a proper HTTP/1.1 200 OK HTTP status response whenever PayPal POST's the IPN data to it.
If you don't return a HTTP/1.1 200 OK response, PayPal will reattempt sending the same data up to 16 times per indiviudal IPN message.

Note: A seller's transaction ID is different from a buyer's transction ID, since they're two different actions (one debit, one credit).

给妤﹃绝世温柔 2025-01-11 14:23:37

ipn_track_id 对于定期付款不是唯一的。至少对于分期付款计划来说不是。
当客户创建分期付款计划时,如果您的计划在结帐时进行首次付款,您将收到 2 条具有相同 ipn_track_id 的 IPN 消息(示例如下)。

首次通知“recurring_ payment_profile_created” 首次付款“recurring_ payment”

计划创建 IPN

 [txn_type] => recurring_payment_profile_created
 [recurring_payment_id] => I-57UAPHFJ3SBY
 [product_name] => Risk-Free Trial
 [time_created] => 06:24:39 Aug 15, 2013 PDT
 [ipn_track_id] => bdd94fdee935a

首次付款 IPN

 [txn_type] => recurring_payment
 [mc_gross] => 10.95
 [shipping] => 0.00
 [product_type] => 1
 [time_created] => 06:24:39 Aug 15, 2013 PDT
 [ipn_track_id] => bdd94fdee935a

ipn_track_id is not unique for recurring payments. At least for installment plan it's not.
When customer create the installment plan and if your plan have a first payment at checkout you will receive 2 IPN messages with the same ipn_track_id (Example bellow).

First notification "recurring_payment_profile_created" the the first payment "recurring_payment"

Plan created IPN

 [txn_type] => recurring_payment_profile_created
 [recurring_payment_id] => I-57UAPHFJ3SBY
 [product_name] => Risk-Free Trial
 [time_created] => 06:24:39 Aug 15, 2013 PDT
 [ipn_track_id] => bdd94fdee935a

First Payment IPN

 [txn_type] => recurring_payment
 [mc_gross] => 10.95
 [shipping] => 0.00
 [product_type] => 1
 [time_created] => 06:24:39 Aug 15, 2013 PDT
 [ipn_track_id] => bdd94fdee935a
╰ゝ天使的微笑 2025-01-11 14:23:37

并非所有 IPN 消息都包含 $_POST['txn_id'],因此如果您仅检查 txn_id,则可能会间歇性地不记录不包含此密钥的 IPN 消息。

Not all IPN messages contain a $_POST['txn_id'], so if you solely check for a txn_id, you may intermittently not log IPN messages where they don't contain this key.

爱人如己 2025-01-11 14:23:37

在我的 PHP API 调用中,我使用这些字段并将它们存储在我的数据库中:(

custom=xxxx  

invoice=ZZZZZZ),

然后,当您的页面收到 IPN 时,它应该(从数据库)检查 custom=xxxx 或等等...

In my PHP API call, i use these fields and store them in my database:

custom=xxxx  

(or invoice=ZZZZZZ)

then, when your page receives IPN, it should check (from database) if the custom=xxxx or etc...

掐死时间 2025-01-11 14:23:37

IPN交易是唯一的,并且改变支付方式的交易将生成新的txn_id。例如退款,因此最好存储与单次购买相关的所有 txn_id。到目前为止,我不知道除了退款之外还有哪些交易会生成新的 txn_id,可能逆转也会生成新的 txn_id。

IPN transactions are unique, also and transactions that change the payment will generate a new txn_id. For example refunds, so its a good idea to store all txn_id related to a single purchase. As of yet I don't know what transactions other than refunds generate a new txn_id, possibly reversals do too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文