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
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

jlacosse
Contributor
Contributor

Yes, precisely, I perform a PATCH on the order after it is created but before the user authorizes the capture.

View solution in original post

Login to Me Too
19 REPLIES 19

rahul-dighe
PayPal Employee
PayPal Employee

Can you please provide a link to the "id" description that you have pasted below.

Senior Product Manager - PayPal Checkout API Product
Login to Me Too

jlacosse
Contributor
Contributor

Yes, thanks for getting back to me. The id is listed under the purchase_unit data structure you can find here. https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit

 

I have not been able to find the correct way to call save on the order to generate the id. Your assistance is appreciated.

Login to Me Too

rahul-dighe
PayPal Employee
PayPal Employee

Hello,

 

I can help you with /save but it won't solve your problem. 

 

At the moment we don't really return the transaction ID sent to the buyer to the merchant.

 

At the moment your best bet and what I see a lot of our merchants do is to generate their own invoice_id which also shows up in the receipt sent by PayPal and it's a common link between your transaction and the buyers transaction. 

 

Please let me know if you have more questions - happy to help in anyway I can.

Senior Product Manager - PayPal Checkout API Product
Login to Me Too

jlacosse
Contributor
Contributor

Yes, my current workaround for this inconsistency between the two APIs is to take the orderId returned from PayPal and attach it to the order's invoiceId field after order creation. This is necessary in our integration since we don't actually create a purchaseId in our database until the payment is completed, and once a payment is completed, we cannot attach an invoiceId to the order. Please let me know if this is an inadvisable solution.

Login to Me Too

rahul-dighe
PayPal Employee
PayPal Employee

How do you do "PayPal and attach it to the order's invoiceId field after order creation." do you do a PATCH on invoice_id?

Senior Product Manager - PayPal Checkout API Product
Login to Me Too
Solved

jlacosse
Contributor
Contributor

Yes, precisely, I perform a PATCH on the order after it is created but before the user authorizes the capture.

Login to Me Too

rahul-dighe
PayPal Employee
PayPal Employee

What you are doing is correct. 

 

I am presuming that you want to use the "id" that you get back from order rather than generating a random string as presumably you are already storing the Order Id somewhere so it avoid saving twice. I really can't see a way to avoid the PATCH. 

 

I am investigating if we can expose the buyer transaction_id but that might not be that quick so what you have is a good way to do it. 

Senior Product Manager - PayPal Checkout API Product
Login to Me Too

Kardmagic
Contributor
Contributor

I had this issue also, here is the answer to get the transaction id

 

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)
});
},

 

Login to Me Too

yabdab
Contributor
Contributor

That is from version 1 api (deprecated) right, not the new v2 ?

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.