paypal

Get Transaction Data via PayPal REST API V2


I am implementing a PayPal Donate button into a project for a charity. That is working great, and I am grabbing the JS response object which includes the Transaction ID. I store that for future API calls. With consent, we need to store donor name and email. So I am trying to use the PayPal API with the transaction ID to get these. It seems straightforward.

Per the PayPal REST API V2 docs, the relevant endpoint seemed to be /checkout/orders with the Order ID which admittedly I assumed was the Transaction ID, but having delved deeper appears not.

I am using Postman to test (auth is working fine), and the /checkout/orders endpoint returns Resource Not Found with a valid Transaction ID. It is the same account, correct API credentials etc.

I think that is now the wrong endpoint and I would need an Order ID. BUT the Donate buttons do not return Order ID, they return Transaction ID, as it is a 'sale' not an 'order'. I now understand the difference, though frankly I would like to have a talk with PayPal developers on meanings and documentation.

So I just cannot find the correct REST V2 endpoint to use for these 'sales' with Transaction IDs - can anyone help please?

I saw an older SO question with an answer here which said the v1/payments/sale endpoint worked - but this endpoint does not exist in V2!

I have looked at transaction search, but that grabs a list by date, not with an existing transaction ID. I know the transaction I want.

I really have tried to go over the documentation, find guidance, and have tested with Postman, but I'm getting nowhere for what seems a basic API usage!


Solution

  • Thank you to Preston PHX for pointing me in the right direction.

    Whilst /v2/payments/captures works with the Transaction ID returned from a hosted Donate button, it only shows transaction info like dates, values, fees etc. No payer info which was what was requested.

    For that, you have to use the /v1/reporting/transactions endpoint and supply transaction_id along with start_date and end_date - these are required, but can be grabbed from the previous captures call if not objectively known.

    Note that v1/payments/sale as mentioned in Preston's answer is fully deprecated so cannot be used as a one-stop call.

    In short, for the original question, two API calls are needed as above. However I have decided to simply grab consent and name/email on the website directly, rather than use the PayPal API. I will use the /v2/payments/captures endpoint however to verify a transaction was sent to and processed by this PayPal account rather than the button ID being modified somehow.