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
Property | Type | Description |
---|---|---|
vnp_Amount | number | The amount to be refunded to the customer. This amount is less than or equal to the transaction amount. |
vnp_CreateBy | string | The person initiating the refund. It could be the username of the merchant who performs the refund. |
vnp_CreateDate | number | The time the refund request is made (Request Date) GMT+7. |
vnp_IpAddr | string | IP address of the server executing the API call. |
vnp_OrderInfo | string | Description of the refund request (Request description). |
vnp_RequestId | string | The 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_TransactionDate | number | The time the transaction is recorded on the merchant's website, calculated in GMT+7. |
vnp_TransactionNo | number | The transaction code recorded in the VNPAY system. |
vnp_TransactionType | VnpTransactionType | The type of transaction in the VNPAY system. |
vnp_TxnRef | string | The payment transaction code of the merchant's system sent to VNPAY for payment request. |
RefundResponse
Property | Type | Description |
---|---|---|
isSuccess | boolean | The result of the request. |
isVerified | boolean | The result of data integrity verification when received from VNPay. |
message | string | Verification 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.