Skip to main content

Refund Transaction (refund)

This is an API for the merchant system to send a refund request for a transaction through the VNPAY Payment Gateway.

Note:
  • refund is one of the functions restricted by VNPAY in the sandbox environment, you need to contact VNPAY for support.
  • See more at issue#12

Refund

import { Refund, RefundResponse, dateFormat, getDateInGMT7, VnpTransactionType } from 'vnpay';

/* ... */

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

const result: RefundResponse = await vnpay.refund({
vnp_Amount: 10000,
vnp_CreateBy: 'giang',
vnp_CreateDate: refundRequestDate,
vnp_IpAddr: '127.0.0.1',
vnp_OrderInfo: 'Test order',
vnp_RequestId: '123456',
vnp_TransactionDate: orderCreatedAt,
vnp_TransactionType: VnpTransactionType.FULL_REFUND,
vnp_TxnRef: '123456',
vnp_Locale: VnpLocale.EN,
// vnp_TransactionNo: 123456, // optional
} as Refund);

Properties

Refund

PropertyTypeDescription
vnp_AmountnumberThe amount to be refunded to the customer. This amount is less than or equal to the transaction amount.
vnp_CreateBystringThe person initiating the refund. It could be the username of the merchant who performs the refund.
vnp_CreateDatenumberThe time the refund request is made (Request Date) GMT+7.
vnp_IpAddrstringIP address of the server executing the API call.
vnp_OrderInfostringDescription of the refund request (Request description).
vnp_RequestIdstringThe merchant's system-generated code for each refund request. This code is unique and used to distinguish refund requests. It must not be duplicated within a day.
vnp_TransactionDatenumberThe time the transaction is recorded on the merchant's website, calculated in GMT+7.
vnp_TransactionNonumberThe transaction code recorded in the VNPAY system.
vnp_TransactionTypeVnpTransactionTypeThe type of transaction in the VNPAY system.
vnp_TxnRefstringThe payment transaction code of the merchant's system sent to VNPAY for payment request.

RefundResponse

PropertyTypeDescription
isSuccessbooleanThe result of the request.
isVerifiedbooleanThe result of data integrity verification 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 RefundResponse object.