简体   繁体   English

什么是paypal api的txn_id以及为什么要检查它以及如何检查?

[英]What is txn_id of paypal api and why it should be checked and how?

I'm currently using the paypal's api for checking payments using the IPN checking. 我目前正在使用paypal的api来检查使用IPN检查的付款。 In the method where paypal is checking if the payment is verified , there's a comment saying : 在paypal检查付款是否经过验证的方法中,有评论说:

//check that txn_id has not been previously processed //检查先前没有处理过txn_id

But I can't understand what is ths txn_id , what it does and why do I need to check it and how . 但我无法理解txn_id是什么,它做了什么,为什么我需要检查它以及如何检查它。

Thanks in advance, 提前致谢,

This is a Unique Transaction ID, that is generated by PayPal. 这是由PayPal生成的唯一交易ID。

You connect that with your order, and paypal report that back to you with the results of this order. 您将其与您的订单连接,并将paypal报告给您,并附上此订单的结果。

You use it to prevent fraud , for example what you do, when you verify that your order is OK, you read that number and search your database to see if this is connected to some other order. 您可以使用它来防止欺诈 ,例如您所做的,当您确认订单没问题时,您读取该号码并搜索您的数据库以查看它是否与其他订单相关联。 If you find it again, means that a potential fraud is on progress, some is buy something from you, lets say 5 euro items, and after some months, is try to order from you 100 euro items, and some how is replay to you with an old verify status id - trying to reuse an old complete transaction . 如果你再次发现它,意味着潜在的欺诈正在进行中,有些是从你那里买的东西,比如5欧元的物品,几个月之后,就试着向你订购100欧元的物品,还有一些如何重播给你使用旧的验证状态ID - 尝试重用旧的完整事务 But because that status id is unique you catch him. 但因为那个身份证是唯一的,所以你会抓住他。

To use it, connect that id, with the unique id of your order, and keep that connection for check. 要使用它,请将该ID与订单的唯一ID相关联,并保留该连接以进行检查。

txn_id is the PayPal-assigned unique identifier for the original transaction. txn_id是原始交易的PayPal分配的唯一标识符。

All subsequent IPN messages for that transaction will use that txn_id so that you can tie them to the original message. 该事务的所有后续IPN消息都将使用该txn_id以便您可以将它们绑定到原始消息。 Make sure you save it with the data for the order to which it applies. 确保使用其适用的订单数据进行保存。

The Completed IPN message is the only one you MUST process, as it is THE message that confirms that a payment has been completed. Completed IPN消息是你必须处理的只有一个,因为它是确认支付已完成消息。 Otherwise, why do you need to worry about IPN at all? 否则,为什么你需要担心IPN呢? The POST variables with that message will have enough customer details for you to use to generate an invoice and delivery docket/label. 带有该消息的POST变量将具有足够的客户详细信息,供您用于生成发票和交货凭证/标签。

You may choose to process other IPN messages, but that is up to how much you want to program for. 您可以选择处理其他IPN消息,但这取决于您要编程的程度。 Basically, the bulk of your sales will be smoothly handled by processing just the Completed messages. 基本上,只需处理Completed消息,您的大部分销售将得到顺利处理。 Any other messages will be in parallel with the normal emails you will receive, and you will probably have to manually chase up anything else, like refunds or disputes. 任何其他消息将与您将收到的普通电子邮件并行,您可能需要手动追踪其他任何内容,例如退款或争议。

Why they ask you to check that it has not been previously processed, is not for fraud, but simply to make sure you do not process a Completed IPN message again, as up to five may be sent to you, up to a day later, as part of the resilience of the IPN process. 为什么他们要求您检查以前是否已经处理过, 不是为了欺诈,而是为了确保您不再处理Completed IPN消息,因为最多可能会向您发送五个消息,直到一天之后,作为IPN流程弹性的一部分。

For example, if you send out goods when a Completed IPN message is received, you do not want to send them out again if you get another IPN Completed message with the same txn_id . 例如,如果您在收到Completed IPN消息时发送货物,则如果您获得具有相同txn_id另一个IPN Completed消息,则不希望再将其发送出去。

Basically, when you get a Completed IPN message, you need to check your orders for one using that txn_id , and if found, and if the order is already marked as paid and has been processed, then you can ignore the message, otherwise, process it as the payment for the order, and do what you normally do upon payment. 基本上,当您收到Completed IPN消息时,您需要检查一个使用该txn_id订单,如果找到,并且如果订单已经标记为已付并且已经处理,那么您可以忽略该消息,否则,处理它作为订单付款,并按照您通常在付款时执行的操作。

Refunds and the like will have their own txn_id , but their IPN messages will include parent_txn_id , which holds the txn_id for the original transaction being refunded. 退款等都有自己的txn_id ,但是他们的IPN消息将包括parent_txn_id ,它保存原始交易的txn_id被退款。

Note that PayPal wants you to check other returned values for correctness, and these are for fraud. 请注意,PayPal希望您检查其他返回值的正确性,这些都是为了欺诈。 Some are: 有些是:

  1. receiver_email field matches the main email address you use to access your PayPal account. receiver_email字段与您用于访问PayPal帐户的主电子邮件地址相匹配。 It is not necessarily the one used with the payment button. 它不一定是付款按钮使用的那个。
  2. Make sure that the item cost and other details returned in the message are correct for the item. 确保消息中返回的项目成本和其他详细信息对于项目是正确的。 This prevents the customer giving themselves a discount. 这可以防止客户给自己打折。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM