txn_id
is the PayPal-assigned unique identifier for the original transaction.
All subsequent IPN messages for that transaction will use that txn_id
so that you can tie them to the original message. 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. Otherwise, why do you need to worry about IPN at all? The POST variables with that message will have enough customer details for you to use to generate an invoice and delivery docket/label.
You may choose to process other IPN messages, but that is up to how much you want to program for. Basically, the bulk of your sales will be smoothly handled by processing just the Completed
messages. 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.
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
.
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.
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.
Note that PayPal wants you to check other returned values for correctness, and these are for fraud. Some are:
receiver_email
field matches the main email address you use to access your PayPal account. It is not necessarily the one used with the payment button.
- 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.