Skip to main content

Query Transaction Result (queryDr)

This is an API for the merchant system to query the payment result of a transaction at the VNPAY system.

warning
  • queryDr is currently suitable for PAY payments
  • token, installment, periodic are not yet compatible

QueryDR

import { QueryDr, QueryDrResponse, getDateInGMT7, dateFormat } from 'vnpay';

/* ... */

/**
* The date must be in GMT+7 timezone
* And formatted as `yyyyMMddHHmmss`
* Use the `getDateInGMT7` and `dateFormat` functions to convert
*/
const date = dateFormat(getDateInGMT7(new Date('2024/05/21')));

const res: QueryDrResponse = await vnpay.queryDr({
vnp_RequestId: generateRandomString(16),
vnp_IpAddr: '1.1.1.1',
vnp_TxnRef: '1716257871703',
vnp_TransactionNo: 14422574,
vnp_OrderInfo: 'Payment for order',
vnp_TransactionDate: date,
vnp_CreateDate: date,
} as QueryDr);

Properties

QueryDr

PropertyTypeDescription
vnp_RequestIdstringRequest ID for transaction result query. This ID must be unique for each query request.
vnp_IpAddrstringIP address of the client.
vnp_TxnRefstringTransaction code of the merchant system.
vnp_TransactionNonumberTransaction code of the VNPAY system.
vnp_OrderInfostringOrder information.
vnp_TransactionDatenumberTransaction time.
vnp_CreateDatenumberTransaction creation time.

QueryDrResponse

PropertyTypeDescription
isSuccessbooleanResult of the request
isVerifiedbooleanVerification result of data integrity when received from VNPay
messagestringVerification message
......Other parameters that VNPay will return, refer here

See more properties that VNPay will return at VNPay.

tip

The parameters that VNPay returns are also in the QueryDrResponse object.

Usage

With logger

  • To be able to use the logger, you need to initialize VNPay with enableLog set to true.
import { QueryDr, QueryDrResponse, getDateInGMT7, dateFormat } from 'vnpay';

/* ... */

/**
* The date must be in GMT+7 timezone
* And formatted as `yyyyMMddHHmmss`
* Use the `getDateInGMT7` and `dateFormat` functions to convert
*/
const date = dateFormat(getDateInGMT7(new Date('2024/05/21')));

const res: QueryDrResponse = await vnpay.queryDr(
{
vnp_RequestId: generateRandomString(16),
vnp_IpAddr: '1.1.1.1',
vnp_TxnRef: '1716257871703',
vnp_TransactionNo: 14422574,
vnp_OrderInfo: 'Payment for order',
vnp_TransactionDate: date,
vnp_CreateDate: date,
} as QueryDr,
{
logger: {
type: 'all',
loggerFn: (data) => {
console.log(data.message);
// Or send log to server, database, ...
},
},
},
);