Skip to main content

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.

you should know
For the best practice, we highly recommend that you use the IPN or the call back to get the status of your transactions for more details please checkHow to configure Instant Payment notification (IPN)?solution article.

you should know

Through out the article we will use the transaction types clarified in ourWhat is the "tran_type" (transaction type)?solution article.


\

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
Be Aware Of

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.

https://secure.paytabs.sa/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:

ParameterData TypeRequired
profile_id
INTβœ”
Indicates the profile that created the transaction. check details on [Request Parameters | profileId].
{
"profile_id": "987654"
}
tran_ref
STRINGβœ”
Indicates the Transaction Reference on the PayTabs side check details on [Response Parameters | tran_ref]
{
"tran_ref": "TST2234701408XXX"
}

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:

ParameterData TypeRequired
profile_id
INTβœ”
Indicates the profile that created the transaction. check details on [Request Parameters | profileId].
{
"profile_id": "987654"
}
cart_id
STRINGβœ”
Indicates the cart/order id at the merchant end to easily relate the transaction to. check details on[Response Parameters | cart_id]
{
"cart_id": "CART#10001"
}
caution
Please check the following possible HTTPs error responses:

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"
}



Sample Request/Response Payloads​

The below sample request payload will show you how you can pass the above-mentioned required parameter/s, which are needed to be passed with valid values to perform a request. Along with the response payload received after using this request 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.

{
"profile_id": "126***",
"tran_ref": "TST201670000XXXX"
}



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.

  1. Original Transaction Creation:

    1. The merchant initiates a transaction using any supported payment flow (e.g., Sale, Authorization, Refund, Cancel, etc.).

    2. Each transaction is assigned a unique identifier such astran_ref or cart_id.

    3. The merchant should store these identifiers securely for tracking and reconciliation purposes.

  2. Preparing for a Query:

    1. The Query Transaction API can be used to retrieve transaction details using either the tran_ref or thecart_id.

    2. Query transactions can be performed regardless of the transaction type or status.

    3. Supported all transaction statuses ( Sucessful ( A ), declined ( D ) , cancel ( C ) .. etc)
      and types (Auth, Sale , Refund, Capture, Void , Register ) can be queried

    4. The query request must include the required parameters as defined in theMinimum Required Parameterssection.

  3. Initiating the Query Transaction Request:

    The merchant sends a query transaction request using theQuery API endpoint, passing either the tran_ref or cart_id to retrieve the transaction details.


  4. Successful Query Scenario:

    1. In the normal flow, the query request is processed successfully and the system returns the complete transaction details.


    2. The response reflects the current status of the transaction, along with all available information related to that transaction.


    3. At this point, you will receive the query transaction response as described in the Sample Request/Response Payloads section.


  5. 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.




We are glad to be always in help. We aim to serve you better each time. As such, please spare a minute to share feedback about your recent experience with PayTabs Developers , on Trustpilot, or Google Reviews.