且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PayPal IPN 唯一标识符

更新时间:2023-02-07 13:36:32

ipn_track_id 不应使用;主要是因为这仅供内部使用,而且对于每个 IPN 消息都是唯一的.
txn_id 对于每个交易都是唯一的,而不是每个 IPN 消息.

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.

这是什么意思;一个事务可以有多个 IPN 消息.例如,eCheck,默认情况下它将进入待处理"状态,并在电子支票清除后完成".
但您也可能会看到撤销、取消的撤销、打开的案例和针对相同 txn_id 的退款.

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.

伪代码:

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 在完成"之前可能会经历多个阶段,因此您需要能够处理这些异常.

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.

关于PayPal在文档中的说明:如果在交付过程中遇到错误,PayPal可能会重新发送单个IPN消息.例如,每当 PayPal POST 向其发送 IPN 数据时,您的脚本都需要返回正确的 HTTP/1.1 200 OK HTTP 状态响应.
如果您不返回 HTTP/1.1 200 OK 响应,PayPal 将重新尝试发送相同数据,每条 IPN 消息最多 16 次.

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.

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

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