gpt4 book ai didi

Paypal IPN 唯一标识符

转载 作者:太空宇宙 更新时间:2023-11-03 15:38:42 24 4
gpt4 key购买 nike

我一直假设用 IPN 消息发送的 txn_id 是唯一的。 Paypal 指南似乎支持这个想法 - 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.

但是我发现 PayPal 的 eCheck 付款 IPN 使用相同的交易 ID 发送了两次。一次在初始付款期间,payment_status 为“待定”,几天后 eCheck 实际处理时再次为 payment_status 为“已完成”。

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

Internal; only for use by MTS and DTS

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

最佳答案

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 上找到更多列出的 IPN 变量

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

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

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

关于 Paypal IPN 唯一标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9240235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com