PayPal lets you download every transaction in your account, since the account was opened, to a CSV file for you process as you wish.
I wish to determine the actual account balance.
I have imported my entire PayPal into a single SQL database table so I can run queries against it to perform calculations and explore the data. There is too much data for Excel anyway.
The schema of my database table contains all of the fields in the CSV file, but these fields in particular stand-out:
DateTime,
Type,
Status,
Gross,
Fee,
Net,
TransactionId,
ReferenceTransactionId
Unfortunately, PayPal does not provide any specification document that explains the significance of certain values (Transaction CSVs are different to PayPal's IPNs).
My first observation with the data is that PayPal rewrites history!. One would assume PayPal would function like a bank in that transactions are immutable once written to the log: for example, if $50 is added to your bank account but then a few days later the transaction is reversed/refunded, you would expect to see:
Date Amount Description
2016-01-04 50.00 $50 deposit
2016-01-07 -50.00 $50 deposit refunded
If you do a SUM(Amount)
you will get 0.00
- because these two transactions resulted in a net zero.
However, with PayPal the experience is this:
- Step 1: Download transactions CSV for January
Step 2: The CSV file will contain the following (paraphrased):
Date Amount Description Status 2016-01-04 50.00 $50 deposit Completed
Step 3: Re-download the transactions CSV for January a few days later
Step 4: Observe the CSV file will still contain only 1 row, but look like this:
Date Amount Description Status 2016-01-04 50.00 $50 deposit Canceled
...which means you need to always re-download history going back at least a year to catch any rewritten transactions and reimport them into your database table.
You can argue that it isn't a problem - just perform a SUM
where Status <> 'Canceled'
- and that probably is the right solution, except...
I've identified over 47 different unique combinations of
Type
andStatus
values, making it more difficult to determine which of those should be included in theSUM
or not:+-----------------------------------------+-----------+ | Type | Status | +-----------------------------------------+-----------+ | Add Funds from a Bank Account | Completed | | Authorization | Completed | | Cancelled Fee | Completed | | Chargeback Reimbursement | Completed | | Chargeback Settlement | Completed | | Donation Received | Canceled | | Donation Received | Cleared | | Donation Received | Completed | | Donation Received | Refunded | | Donation Received | Reversed | | Donation Received | Uncleared | | Donation Sent | Completed | | eCheck Sent | Cleared | | Express Checkout Payment Sent | Completed | | Mobile Payment Received | Completed | | Payment Received | Completed | | Payment Review | Cleared | | Payment Review | Placed | | Payment Sent | Completed | | Payment Sent | Refunded | | PayPal card confirmation refund | Completed | | Recurring Payment Received | Completed | | Recurring Payment Received | Refunded | | Refund | Completed | | Request Received | Canceled | | Request Received | Pending | | Reversal | Completed | | Shopping Cart Payment Sent | Completed | | Temporary Hold | Placed | | Temporary Hold | Removed | | Update to Add Funds from a Bank Account | Completed | | Update to eCheck Received | Canceled | | Update to eCheck Received | Cleared | | Update to eCheck Received | Updated | | Update to eCheck Sent | Cleared | | Update to Reversal | Canceled | | Web Accept Payment Received | Canceled | | Web Accept Payment Received | Cleared | | Web Accept Payment Received | Completed | | Web Accept Payment Received | Held | | Web Accept Payment Received | Refunded | | Web Accept Payment Received | Reversed | | Web Accept Payment Received | Uncleared | | Web Accept Payment Sent | Completed | | Withdraw Funds to a Bank Account | Completed | | Withdraw Funds to a Bank Account | Pending | | Withdraw Funds to Bank Account | Completed | +-----------------------------------------+-----------+
PayPal will rewrite some transactions, but other times they will append a related transaction to your history (pointing to the original transaction in the
ReferenceTxnId
) - and sometimes they will do both.- And the
ReferenceTxnId
field is used to represent a multi-layer hierarchy of transactions - that is, purchase transaction1
could have a related refund transaction2
, and transaction2
could have a counter-refund transaction3
that reference2
and not1
).- I had to write a recursive CTE query to retrieve the "transaction tree" for a given root transaction.
Other curiosities I've observed include:
- PayPal using the
Name
column (intended for the customer's name) to sometimes store transaction type information, and theFrom Email
column (the customer's email address) to contain PayPal's own email addresses, like[email protected]
. - Unexplained and apparent inconsistent use of:
- "
Canceled
", vs "Refunded
", vs "Reversed
", vs "Removed
" - "
Completed
", vs "Cleared
", vs "Placed
"
- "
- And what is the difference between:
Type: Web Accept Payment Received, Status: Refunded
- ...and...
Type: Refund, Status: Completed
...why is PayPal being so obtuse?
Here's a real-world example of a series of transactions I imported. My question to you, the reader, is that assuming these are the only transactions in an account, what is the final PayPal account balance?
DateTimeUtc Name Type Status Gross Fee Net FromEmail TxnId ReferenceTxnId
------------------ ------------------------- ---------------------------- ---------- ----- ----- ----- -------------------- ---- --------------
2014-06-15 17:47:30 (Customer name) Web Accept Payment Received Completed 20.00 -1.05 18.95 [email protected] 1111
2014-07-02 03:41:22 (Customer name) Temporary Hold Removed -20.00 1.05 -18.95 [email protected] 2222 1111
2014-07-16 21:00:58 Reversal Update to Reversal Canceled 18.95 0.00 18.95 [email protected] 3333 2222
2014-07-16 21:00:59 Chargeback Settlement Chargeback Settlement Completed -20.00 -20.00 -40.00 [email protected] 4444 1111
2014-10-01 13:32:55 Chargeback Reimbursement Chargeback Reimbursement Completed 20.00 0.00 20.00 [email protected] 5555 1111
Depending on how you interpret it, it could be:
- 1.05
17.90
-20.00
...and I have no idea what the right answer is myself!