Search code examples
paypalpaypal-nvp

How to link related transactions obtained by TransactionSearch and GetTransactionDetails?


TL;DR- How do I know if I really did get paid, via the PayPal NVP API?

Longer version

I'm writing code to automagically process and classify transactions from our PP business account. I have code that calls NVP methods TransactionSearch and GetTransactionDetails and fills a few database tables with the results that are returned. This happens every day for the previous 24 hours' worth of transactions. So far, so good.

I began from the assumption that the same information available via manual CSV export via the PayPal web interface would be available via the API, but I'm now discovering that either this is not the case, or there is another API call I should be making to get the rest of the information I need.

In particular, GetTransactionDetails doesn't seem to return the equivalent of CSV field "Reference Txn ID" and, in a few cases, I can't see how to connect related transactions.

So, my question is how can I obtain the reference transaction ID, or how do I otherwise connect these associated transactions?

Example 1

This is (probably) the most common sort of situation where the reference transaction ID is needed.

Depending on the buyer's funding source, you may either see a purchase complete instantly or, if the transaction must be cleared, complete across three separate transactions:

  • The original payment, detail of which gives buyer's name, email, address, invoice number, item ID, gross, fee and net amounts etc.
  • followed immediately by a debit of the net amount
  • followed, in a few days, by a credit of the net amount.

It is crucial to match the three transactions because you don't know whether the payment will succeed or be declined (and therefore whether you've actually got the money) unless you do.

In the data I have available to me at the moment, there is only one such example of this situation, and calls to GetTransactionDetails for the settlement transactions fail completely ("The transaction could not be loaded") — possibly because, in that one instance, I know that the payment was made with a credit card by somebody who doesn't have a PayPal account.

This might be an anomaly, or it might be the common case. I have seen this triplet of transactions quite frequently in other PayPal accounts, but not this one, so I can't be sure.

Example 2

A payment in a foreign currency will typically generate three transactions, rather like in Example 1:

  • The original payment (eg in €), the detail of which gives the sender's name and email address etc;
  • this is then followed by an immediate debit of the (probably net) amount in €
  • and then an immediate credit in USD.

From the point of view of the NVP API, GetTransactionDetails usually returns values labelled SETTLEAMT and SETTLEAMTCURRENCYCODE for the original payment. No further processing is required.

However, a recent such transaction (for reasons that even PayPal could not adequately explain) did not auto-convert, and the GetTransactionDetails call lacks the settlement values even after the conversion was performed manually.

The transactions are all there — but I cannot see any programmatic way to associate them because an attempt to call GetTransactionDetails on currency conversion transactions returns the error "You can not get the details for this type of transaction".

Any advice or experience relating to automatic processing of PayPal transactions? Is there any way to duplicate, programmatically, the same data included in the CSV export?

If necessary, I'd be happy to process the CSV export if there were some way to generate it programmatically, but I don't even know of a way to do that (short of a Selenium-driven solution full of pitfalls).


Solution

  • GetTransactionDetails will include a PARENTTRANSACTIONID if there is a related transaction. For example, a refund transaction would have a parent transaction ID.