0

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).

strix
  • 5
  • 1
  • 3

1 Answers1

0

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

Drew Angell
  • 25,968
  • 5
  • 32
  • 51
  • Okay, I see that; does that mean the scenario I gave in Example 1, the three transactions can't be programmatically linked? Or is the answer that I just have to poll transactions with PAYMENTSTATUS = 'pending' periodically to see how they progress? – strix Aug 01 '15 at 17:47
  • I would really recommend you look into using Instant Payment Notification (IPN) instead of pulling transaction details using TransactionSearch and GetTransactionDetails. IPNs happen in real-time and would have any related transaction details you need. – Drew Angell Aug 02 '15 at 01:10
  • I considered IPNs (after all, that's what they're for), however the complication is that there already is an IPN listener configured (belonging to an ecommerce solution) and to add an additional IPN listener would require setting up an IPN demultiplexor or broadcaster. On balance, I concluded that simplicity was the better part of valour, and that polling pending transactions offers less opportunity for mistakes/bugs (and caution is indicated when dealing with financials). Also, this is for feeding accountancy software, so realtime updates aren't required. Thanks for your insights! – strix Aug 02 '15 at 12:15
  • Complicated words don't necessarily mean complicated procedures. All you have to do is forward the IPN data from one script to the next. It takes one line of code. ;) The APIs should give you everything you need, though. Maybe I'm still not fully understanding, but all you should ever need is a transaction ID and a potential parent transaction ID, no..?? – Drew Angell Aug 02 '15 at 19:04
  • It's not complicated in principle, but I take the view that each layer, however thin, adds complexity and with it, the risk that something could go wrong and an extra dimension of testing required. I think financials are a place where the KISS principle is well applied. IOW, I prefer to leave the ecommerce IPN solutions alone if I can solve this problem another way (eg by polling PayPal for Pending/Processing transactions and updating local records as required). – strix Aug 03 '15 at 16:30
  • As to need: as you point out, Refund transactions have a parenttransactionid (which I use); the other cases are described in my OP. Example 2, there's probably not much that can be done about it because there is no way, even in principle, of matching a manual currency conversion to a single, specific transaction (eg, what happens if there are two € txns before the manual conversion is done?). Example 1 is the main issue, and my current impression is that it is not necessary to match the update txns because the original txn itself will be updated, if my code can query PP after a day or two. – strix Aug 03 '15 at 16:35
  • TL;DR- I can probably manage, just not in the way that I expected. I was just taken by surprise, I think, because I expected the API to behave in much the way that the CSV exports behave. It doesn't, but that's okay. (In some ways, the API is actually *easier* to work with than CSV exports: eg automatic currency conversions automatically attach the settlement/converted amount to the txn detail of the original txn.) – strix Aug 03 '15 at 16:39