[PayPal checkout] How to get Transaction ID after complete a transaction

shocklamuk
Contributor
Contributor

I want to track the transaction id after completing a transaction, but the result returning from the API does not include the expected transaction id. Please look at the screenshot below to see my expected transaction id from Payer/Buyer view.

 

I googled and tried with this API but no luck the sale id is not my expectation

Request: https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L37PB5I38U99292GC7810347

Response:

 

{
  "id": "PAYID-L37PB5I38U99292GC7810347",
  "intent": "sale",
  "payer": {
    "payment_method": "paypal",
    "status": "VERIFIED",
    "payer_info": {
      "email": "xxxxx",
      "first_name": "AUS",
      "last_name": "Test",
      "payer_id": "CNKMF2FXWWEPY",
      "phone": "084932091707",
      "country_code": "AU",
      "shipping_address": {
        "line1": "xxxxxxxxxx",
        "city": "xxxxxxxxxx",
        "state": "xxxxxxxxxx",
        "postal_code": "xxxxxxxxxx",
        "country_code": "xxxxxxxxxx",
        "recipient_name": "xxxxxxxxxx"
      }
    }
  },
  "cart": "9WB55052CM143354T",
  "transactions": [
    {
      "amount": {
        "currency": "AUD",
        "total": "9.60",
        "details": {
          "subtotal": "9.60",
          "shipping": "0.00",
          "handling_fee": "0.00",
          "shipping_discount": "0.00",
          "insurance": "0.00"
        }
      },
      "payee": {
        "email": "xxxxxxxxxx",
        "merchant_id": "YDYL6WBW7ZR8G"
      },
      "item_list": {
        "shipping_address": {
          "line1": "xxxxxxxxxx",
          "city": "xxxxxxxxxx",
          "state": "xxxxxxxxxx",
          "postal_code": "xxxxxxxxxx",
          "country_code": "xxxxxxxxxx",
          "recipient_name": "xxxxxxxxxx"
        }
      },
      "related_resources": [
        {
          "sale": {
            "id": "4LG37143WW764552S",
            "amount": {
              "currency": "AUD",
              "total": "9.60",
              "details": {
                "subtotal": "9.60",
                "shipping": "0.00",
                "handling_fee": "0.00",
                "shipping_discount": "0.00",
                "insurance": "0.00"
              }
            },
            "payment_mode": "INSTANT_TRANSFER",
            "state": "completed",
            "protection_eligibility": "ELIGIBLE",
            "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
            "transaction_fee": {
              "currency": "AUD",
              "value": "0.67"
            },
            "parent_payment": "PAYID-L37PB5I38U99292GC7810347",
            "create_time": "2020-07-03T08:49:17Z",
            "update_time": "2020-07-03T08:49:17Z",
            "links": [
              {
                "href": "https://api.sandbox.paypal.com/v1/payments/sale/4LG37143WW764552S",
                "rel": "self",
                "method": "GET"
              },
              {
                "href": "https://api.sandbox.paypal.com/v1/payments/sale/4LG37143WW764552S/refund",
                "rel": "refund",
                "method": "POST"
              },
              {
                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L37PB5I38U99292GC7810347",
                "rel": "parent_payment",
                "method": "GET"
              }
            ]
          }
        }
      ]
    }
  ],
  "state": "approved",
  "create_time": "2020-07-03T08:48:53Z",
  "update_time": "2020-07-03T08:49:17Z",
  "links": [
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L37PB5I38U99292GC7810347",
      "rel": "self",
      "method": "GET"
    }
  ]
}

 

 

Screen Shot 2020-07-03 at 4.08.11 PM.png

 

Please help me on this thanks!

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

shocklamuk
Contributor
Contributor

Thank you very much! After I did a lot of research, I found out that

 

For some reason, PayPal maintains two different ids pointing to the same completed transaction. One is used for Seller/Merchant and the other is used and displayed for Payer. PayPal does not expose Payer’s transaction id in the view of Merchant and even we can not retrieve it by any Rest API from my system.

 

Fortunately, although PayPal does not let us know the transaction ids of Payers but they allow us to search a transaction by both Merchant’s transaction id and Payer’s transaction id pointing to the same transaction.

View solution in original post

Login to Me Too
6 REPLIES 6

Torr17
Contributor
Contributor
Than you
Login to Me Too

JackieDaytona
Contributor
Contributor

Here is how I do it.  The code is from an ORDER.  Also CREATE Two Hidden Fields to store the Vals and to send to the server.

 

onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {

$('#transmsg').html('<b>' + 'AUTHORIZED...' + '</b>');
$('#transmsg').append('<br>'+'Transaction completed by: ' + details.payer.name.given_name +' '+ details.payer.name.surname + '<br>' + "Order Id: " + details.id + '<br>' + 'Status: PAID & APPROVED' + '<br>'+ 'Thank You For Your Order'+ '<br>');
if (details.status === "COMPLETED") {
window.setTimeout(function() {}, 500)
$('#transmsg').append('<b>' + 'Sending Order...Please Wait' + '</b>'+'<br>');  

 

$('#transid').val(details.id);  HERE IS THE ACTUAL VALUE FROM PAYPAL AND THE VAL IS SET TO THE HIDDEN FIELD
$('#orderstat').val('APPROVED');
$('#orderform').submit();
}
});

 

Hope this help you

 

D

Login to Me Too

shocklamuk
Contributor
Contributor

Thank you for your answer, I will try this but my problem is only solved a half. Because I want to correct the old data since I have stored the payment id instead of the transaction id. So I would like to know which Rest API that I can use to get the transaction id by payment id to correct the old values?

 

Thanks!

Login to Me Too

JackieDaytona
Contributor
Contributor

Look into this: you are looking for the "Correlation ID" and it can be found in the return headers by the name of "Paypal-Debug-Id".

 

Hope that helps you, never went down that path... but this may help

Login to Me Too
Solved

shocklamuk
Contributor
Contributor

Thank you very much! After I did a lot of research, I found out that

 

For some reason, PayPal maintains two different ids pointing to the same completed transaction. One is used for Seller/Merchant and the other is used and displayed for Payer. PayPal does not expose Payer’s transaction id in the view of Merchant and even we can not retrieve it by any Rest API from my system.

 

Fortunately, although PayPal does not let us know the transaction ids of Payers but they allow us to search a transaction by both Merchant’s transaction id and Payer’s transaction id pointing to the same transaction.

Login to Me Too

australopythecu
Contributor
Contributor

So what's the best idea to retrieve any ID from the transaction or payment information to validate an input on another form? 

 

I was expecting to pass a hidden parameter with the transaction ID pattern and validate my form on submissions with that.

 

Cheers

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.