Query Transaction
PayTabs provides you with a collection of API endpoints which used to process all payments, regardless of if they are through either your own payment pages, the managed payment pages, or if you are using the hosted payment pages.
If you have a transaction that you want to fetch its details and know more about its status, type, etc... you can use the query transaction endpoint, as it will return the details of the requested transaction. In this manual, we walk you through how to use and manage the mentioned endpoint.
Through out the article we will use the transaction types clarified in ourWhat is the "tran_type" (transaction type)?solution article.
\
The Endpoint and Related Postman Collectionβ
In this tutorial, we will rely on the PayTabs Query Transaction API Endpoint, mentioned on the PayTabs API endpoints postman collection, which you can access fromhere. he endpoint will need to be accessed with the mentioned HTTP request via the below URL endpoint:
| POST | {{domain}}/payment/query |
|---|
Please note that not using the proper endpoint URL {domain} will lead to authentication issues within your responses. To find the your proper domain you can read ourWhat is my (Region)/(endpoint URL)?tutorial article.
- KSA
- UAE
- Egypt
- Oman
- Jordan
- Kuwait
- Iraq
- Morocco
- Qatar
- Global
https://secure.paytabs.sa/payment/query
https://secure.paytabs.com/payment/query
https://secure-egypt.paytabs.com/payment/query
https://secure-oman.paytabs.com/payment/query
https://secure-jordan.paytabs.com/payment/query
https://secure-kuwait.paytabs.com/payment/query
https://secure-iraq.paytabs.com/payment/query
https://secure-morocco.paytabs.com/payment/query
https://secure-doha.paytabs.com/payment/query
https://secure-global.paytabs.com/payment/query
The Minimum Required Parametersβ
To initiate a query payment request, there are minimum required parameters that need to be passed with valid information. The specification of these required parameters is clarified below according to the query type:
Query via Transaction Referenceβ
In this type, you can initiate query transaction requests using your profile_id and the requested tran_ref. You will receive a response object of this specific transaction you referred to. Kindly check the request parameters' specifications below:
| Parameter | Data Type | Required | |
|---|---|---|---|
| INT | β | |
| Indicates the profile that created the transaction. check details on [Request Parameters | profileId]. | |||
| |||
| STRING | β | |
| Indicates the Transaction Reference on the PayTabs side check details on [Response Parameters | tran_ref] | |||
| |||
Query via Cart IDβ
As for this type, you can initiate query transaction requests using your profile_id and a cart_id, and you will receive an array of all the transactions that match this specific cart_id. Kindly check the request parameters' specifications below:
| Parameter | Data Type | Required | |
|---|---|---|---|
| INT | β | |
| Indicates the profile that created the transaction. check details on [Request Parameters | profileId]. | |||
| |||
| STRING | β | |
| Indicates the cart/order id at the merchant end to easily relate the transaction to. check details on[Response Parameters | cart_id] | |||
| |||
- 400 Bad Request
- 429 Too Many Requests
You only need to use one of the options listed above; if you provide both parameters cart_id or tran_ref in the Query request, you will receive an error. 400 Bad Request.
{
"code": 2,
"message": "Invalid query. Only one of tranRef or cartId can be set.",
"trace": "PMNT0401.66E1581A.00004763"
}
If you sent 60 request per minute searching by tran_ref, or 20 request per minute searching by cart_id, the error 429 Too Many Requests will occurs.
{
"code": 5,
"message": "Too many requests, try again later.",
"trace": "PMNT0402.66E16EF6.000071AD"
}
Sample Request/Response Payloadsβ
- Sample Request Payload
- Sample Response Payload
The below sample request payload will show you how you can pass the above-mentioned parameters, which are needed to be passed with valid values to perform a request.
- Query via Transaction Reference
- Query via Cart ID
{
"profile_id": "126***",
"tran_ref": "TST201670000XXXX"
}
{
"profile_id": "126***",
"cart_id": CART#10001"
}
tran_ref is a unique value, unlike cart_id, which can be shared across multiple transactions.This means that when using
tran_ref, the response will contain complete details for that specific transaction.However, when using
cart_id, the response will return an array of transactions, and some detailsβsuch as the user_defined Request/Response: User Defined (user_defined). objectβmay not be included for every item. So if you need full detailed, should use tran_ref- Query via Transaction Reference
- Query via Cart ID
{
"tran_ref": "TST201670000XXXX",
"tran_type": "Sale",
"cart_id": "CART#10001",
"cart_description": "Product/Service description",
"cart_currency": "SAR",
"cart_amount": "100",
"customer_details": {
"name": "Technical Support",
"email": "[email protected]",
"phone": "+966 55 xxxxxx6",
"street1": "address street",
"city": "Jeddah",
"state": "Makkah",
"country": "SA",
"ip": "86.111.XXX.X"
},
"payment_result": {
"response_status": "A",
"response_code": "036501",
"response_message": "Authorised",
"acquirer_message": "00:Approved",
"acquirer_rrn": "425509036501",
"transaction_time": "2024-09-11T09:01:51Z"
},
"payment_info": {
"payment_method": "MasterCard",
"card_type": "Credit",
"card_scheme": "MasterCard",
"payment_description": "5500 00## #### 5559",
"expiryMonth": 12,
"expiryYear": 2026
},
"user_defined": {
"udf1": "UDF1 Test",
"udf2": "UDF2 Test",
"udf3": "UDF3 Test",
"udf4": "UDF4 Test",
"udf5": "UDF5 Test",
"udf6": "UDF6 Test",
"udf7": "UDF7 Test",
"udf8": "UDF8 Test",
"udf9": "UDF9 Test"
},
"serviceId": 2,
"token": "2C4654BC67A3EE30C6***0FF638B74B9",
"profileId": 126***,
"merchantId": 68***,
"trace": "PMNT****.6760***.0006****"
}
[
{
"tran_ref": "TST201670000XXXX",
"tran_type": "Sale",
"cart_id": "CART#10001",
"cart_description": "Product/Service description",
"cart_currency": "SAR",
"cart_amount": "100",
"customer_details": {
"name": "Technical Support",
"email": "[email protected]",
"phone": "+966 55 xxxxxx6",
"street1": "address street",
"city": "Jeddah",
"state": "Makkah",
"country": "SA",
"ip": "86.111.XXX.X"
},
"payment_result": {
"response_status": "A",
"response_code": "036501",
"response_message": "Authorised",
"acquirer_message": "00:Approved",
"acquirer_rrn": "425509036501",
"transaction_time": "2024-09-11T09:01:51Z"
},
"payment_info": {
"payment_method": "MasterCard",
"card_type": "Credit",
"card_scheme": "MasterCard",
"payment_description": "5500 00## #### 5559",
"expiryMonth": 12,
"expiryYear": 2026
},
"serviceId": 2
},
{
"tran_ref": "TST201570000XXXX",
"tran_type": "Sale",
"cart_id": "CART#10001",
"cart_description": "Product/Service description",
"cart_currency": "SAR",
"cart_amount": "150",
"customer_details": {
"name": "Technical Support",
"email": "[email protected]",
"phone": "+966 55 xxxxxx6",
"street1": "address street",
"city": "Jeddah",
"state": "Makkah",
"country": "SA",
"ip": "86.111.XXX.X"
},
"payment_result": {
"response_status": "A",
"response_code": "036501",
"response_message": "Authorised",
"acquirer_message": "00:Approved",
"acquirer_rrn": "425509036501",
"transaction_time": "2024-09-11T09:01:51Z"
},
"payment_info": {
"payment_method": "MasterCard",
"card_type": "Credit",
"card_scheme": "MasterCard",
"payment_description": "5500 00## #### 5559",
"expiryMonth": 12,
"expiryYear": 2026
},
"serviceId": 2
}
]
Expected Flow Behaviorβ
Reaching this stage, you are now able to initiate a Query Transaction, which is used to retrieve transaction details and verify the current status of a transaction. The query operation is informational only and does not change the transaction state.
- Original Transaction Creation:
- The merchant initiates a transaction using any supported payment flow (e.g., Sale, Authorization, Refund, Cancel, etc.).
- Each transaction is assigned a unique identifier such as
tran_reforcart_id. - The merchant should store these identifiers securely for tracking and reconciliation purposes.
- Preparing for a Query:
- The Query Transaction API can be used to retrieve transaction details using either the
tran_refor thecart_id. - Query transactions can be performed regardless of the transaction type or status.
- Supported all transaction statuses ( Sucessful ( A ), declined ( D ) , cancel ( C ) .. etc)
and types (Auth, Sale , Refund, Capture, Void , Register ) can be queried - The query request must include the required parameters as defined in theMinimum Required Parameterssection.
- The Query Transaction API can be used to retrieve transaction details using either the
- Initiating the Query Transaction Request:
The merchant sends a query transaction request using theQuery API endpoint, passing either the
tran_reforcart_idto retrieve the transaction details. - Successful Query Scenario:
In the normal flow, the query request is processed successfully and the system returns the complete transaction details.
The response reflects the current status of the transaction, along with all available information related to that transaction.
At this point, you will receive the query transaction response as described in the Sample Request/Response Payloads section.
- Query Limitations and Notes:
The Query Transaction API is read-only and does not trigger any financial operation or status changes. It is intended solely for monitoring, validation, and reconciliation purposes.