How do I get a TransactionId from an OrderId using the V2 REST API?

jlacosse
Contributor
Contributor

Hi, I'm using the V2 REST API (with the PayPalCheckoutSdk) to capture an authorization for an order created with the PayPal Smart Payment Buttons.

 

The problem I'm facing, is that after I capture the authorized Order, I need a way to get the TransactionID so that I can include it in our customer's receipt and record it in our DB. Currently /v2/checkout/orders/{order_id} does NOT return the same TransactionID that can be seen from a client's purchase history in the PayPal sandbox. I have looked through the entire data structure returned from an OrdersGetRequest and cannot find this TransactionId.

 

I found some relevant documentation that says I should be able to find this transactionId on the purchase_unit data structure for this order:

 

image.png
The documentation suggests I need to call /v2/checkout/orders/{order_id}/save to generate this id, but when I attempt this, I get an error stating that the order cannot be saved, and that I need to set the intent to authorize and set processing_instruction to ORDER_SAVED_EXPLICITLY.

 

Does anyone have any insights on how I can properly use the V2 REST API to create Orders and retrieve transaction ids that match the transaction ids that customers will see? 

Login to Me Too
19 REPLIES 19

mx120
Contributor
Contributor

Kardmagic reply:

onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
console.log(JSON.stringify(details.purchase_units[0].payments.captures[0].id));

var transid = JSON.stringify(details.purchase_units[0].payments.captures[0].id)
});
},

 

this is actually the correct answer!

Login to Me Too

deloma
Member
Member

This is a unique capture / sale id yes, but not the transaction-id the buyer sees when he logs into his paypal account.

 

As the thread starter said, this buyer transaction-id cannot be found anywhere. I am facing the same issue at integrating and for future customer support he will ask "my transactioncode is '1245ABCD" and we cannot do anything with this in support.

 

Problem

Further the "invoice-id" is identical for the transaction which can have multiple captures!

 

The buyer can search by this invoice-id and will find multiple "transactoins / captures". Here a screenshot from the sandbox buyer account and those two captures belong to one single payment-id. Its actually a guessing game which "capture-id" is which byuer "transaction".

 

paypal-one-invoiceid-multiple-catpures.png

 

Login to Me Too

DragonSpark
Contributor
Contributor

I ended up with a "solution" based on this post.  What I needed is a way for a user of my application to easily visit paypal and see their transaction from the source.  It's not ideal, but it does seem to work.  Here is the string format template that I am using, make note of the `searchKeyword={0}` which gets replaced with the merchant transaction id when string.Format gets called (below):

 

```

https://www.paypal.com/activities/?fromDate=2000-01-01&toDate=3000-01-01&searchType=ANY&searchKeyword={0}&transactiontype=ALL_TRANSACTIONS&archive=INCLUDE_ARCHIVED_TRANSACTIONS&amount_lower=0&amount_upper=0&currency_value=ALL_TRANSACTIONS_CURRENCY&currency_label=ALL_TRANSACTIONS_CURRENCY

```

 

I then call string.Format(template, Capture.Id) where Capture.Id is the capture id of the merchant transaction (what gets returned in the `details.purchase_units[0].payments.captures[0].id` on the OnApprove event).

 

The transaction does not list anywhere in the actual details, but it gets the user to more details of their purchase, which is what I am aiming for here.

 

There is a security concern, of course, that my merchant transaction ID is being leaked to the payer, but small price for functionality and having to deal with PayPal's overwhelming dysfunction with this issue.

Login to Me Too

DragonSpark
Contributor
Contributor

I have been spending the morning on this overly confusing issue and in my case calling `details.purchase_units[0].payments.captures[0].id` returns the payment information for the merchant, not the payer.  I would like to display the payer's transaction ID so that they can launch a direct browser request from my application and view the transaction details in PayPal.

 

The lack of "support" on this forum is most disturbing.  Especially when PayPal has raised its fees. It is clearly not going towards improving its products, services and said "support."  It's very disappointing to have to browse pages and pages of posts like this where PayPal appears to be non-existent, aloof, apathetic, or worse.

 

This is why everyone is moving to Stripe/Square/etc.

Login to Me Too

yabdab
Contributor
Contributor

How is this a "solution" ? 

Login to Me Too

mx120
Contributor
Contributor

I am passing my invoice id in `invoice_id` and `reference_id` fields calling /orders. but on the transaction details in the paypal UI it cant be found. How would I reconcile PP transaction with my internal order? I dont want to send PATCH. this should be available from get go..

Login to Me Too

yabdab
Contributor
Contributor

It should be noted that PayPal assigns a different Transaction ID to the buyer and seller for the same transaction.

 

No idea why as this just causes more confusion for both parties.

 

More details: https://www.paypal.com/gp/smarthelp/article/why-are-there-different-buyer-and-seller-transaction-ids...

Login to Me Too

andyd2
New Community Member

I am having this same issue that I would like to track the transaction id so that when a customer calls for support, we are able to look up by transaction id in our support database.  Has there been a fix by PayPal on this or are people still creating their own id that they PATCH on the order?

Login to Me Too

DragonSpark
Contributor
Contributor

Did that answer your question? 😛

Login to Me Too

MarkMekhaiel
Contributor
Contributor

Do any employees actually reply here? 2 years later and no official comment..?

I'm trying to generate a URL which allows our internal users to navigate to a payment on Paypal's site, which requires a transaction ID. This doesn't exist on any of the V2 endpoints.

 

If anyone has suggestions for either how to generate a URL from the order_id, or how to get the transaction_id for a given order, that would be greatly appreciated.



Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.