vnpay
Version:
An open-source nodejs library support to payment with VNPay
802 lines (796 loc) • 29.1 kB
JavaScript
import { VNP_VERSION, QUERY_DR_REFUND_ENDPOINT, numberRegex, GET_BANK_LIST_ENDPOINT, PAYMENT_ENDPOINT, VNPAY_GATEWAY_SANDBOX_HOST, VNP_DEFAULT_COMMAND } from './chunk-H63MYJ5O.js';
import { ignoreLogger, consoleLogger, getResponseByStatusCode, isValidVnpayDateFormat, getDateInGMT7, dateFormat, createPaymentUrl, calculateSecureHash, resolveUrlString, hash, buildPaymentUrlSearchParams, verifySecureHash } from './chunk-5IZHYZ2T.js';
import { RESPONSE_MAP, QUERY_DR_RESPONSE_MAP, WRONG_CHECKSUM_KEY, REFUND_RESPONSE_MAP } from './chunk-3RXL4RP4.js';
import { __name } from './chunk-DHKAIZT6.js';
// src/services/logger.service.ts
var _LoggerService = class _LoggerService {
/**
* Khởi tạo dịch vụ logger
* @en Initialize logger service
*
* @param isEnabled - Cho phép log hay không
* @en @param isEnabled - Enable logging or not
*
* @param customLoggerFn - Hàm logger tùy chỉnh
* @en @param customLoggerFn - Custom logger function
*/
constructor(isEnabled = false, customLoggerFn) {
this.isEnabled = false;
this.loggerFn = ignoreLogger;
this.isEnabled = isEnabled;
this.loggerFn = customLoggerFn || (isEnabled ? consoleLogger : ignoreLogger);
}
/**
* Ghi log dữ liệu
* @en Log data
*
* @param data - Dữ liệu cần log
* @en @param data - Data to log
*
* @param options - Tùy chọn log
* @en @param options - Logging options
*
* @param methodName - Tên phương thức gọi log
* @en @param methodName - Method name that calls the log
*/
log(data, options, methodName) {
if (!this.isEnabled) return;
const logData = { ...data };
if (methodName) {
Object.assign(logData, { method: methodName, createdAt: /* @__PURE__ */ new Date() });
}
if (options?.logger && "fields" in options.logger) {
const { type, fields } = options.logger;
for (const key of Object.keys(logData)) {
const keyAssert = key;
if (type === "omit" && fields.includes(keyAssert) || type === "pick" && !fields.includes(keyAssert)) {
delete logData[keyAssert];
}
}
}
(options?.logger?.loggerFn || this.loggerFn)(logData);
}
};
__name(_LoggerService, "LoggerService");
var LoggerService = _LoggerService;
// src/services/payment.service.ts
var _PaymentService = class _PaymentService {
/**
* Khởi tạo dịch vụ thanh toán
* @en Initialize payment service
*
* @param config - Cấu hình VNPay
* @en @param config - VNPay configuration
*
* @param logger - Dịch vụ logger
* @en @param logger - Logger service
*
* @param hashAlgorithm - Thuật toán băm
* @en @param hashAlgorithm - Hash algorithm
*/
constructor(config, logger, hashAlgorithm) {
this.bufferEncode = "utf-8";
this.config = config;
this.hashAlgorithm = hashAlgorithm;
this.logger = logger;
this.defaultConfig = {
vnp_TmnCode: config.tmnCode,
vnp_Version: config.vnp_Version,
vnp_CurrCode: config.vnp_CurrCode,
vnp_Locale: config.vnp_Locale,
vnp_Command: config.vnp_Command,
vnp_OrderType: config.vnp_OrderType
};
}
/**
* Phương thức xây dựng, tạo thành url thanh toán của VNPay
* @en Build the payment url
*
* @param {BuildPaymentUrl} data - Thông tin thanh toán
* @en @param {BuildPaymentUrl} data - Payment information
*
* @param {BuildPaymentUrlOptions<LoggerFields>} options - Tùy chọn
* @en @param {BuildPaymentUrlOptions<LoggerFields>} options - Options
*
* @returns {string} - URL thanh toán
* @en @returns {string} - Payment URL
*/
buildPaymentUrl(data, options) {
const { url, dataToBuild } = this.buildVnpayUrlInternal(data);
const buildPaymentUrlLogPayload = {
createdAt: /* @__PURE__ */ new Date(),
method: "buildPaymentUrl",
paymentUrl: options?.withHash ? url.toString() : (() => {
const cloneUrl = new URL(url.toString());
cloneUrl.searchParams.delete("vnp_SecureHash");
return cloneUrl.toString();
})(),
...dataToBuild
};
this.logger.log(buildPaymentUrlLogPayload, options, "buildPaymentUrl");
return url.toString();
}
/**
* Phương thức xây dựng, tạo thành qr thanh toán của VNPay
* @en Build the qr payment
*
* @param {BuildPaymentUrl} data - Thông tin thanh toán
* @en @param {BuildPaymentUrl} data - Payment information
*
* @param {GenerateQrResponseOptions<LoggerFields>} options - Tùy chọn
* @en @param {GenerateQrResponseOptions<LoggerFields>} options - Options
*
* @returns {Promise<GenerateQrResponse>} - Kết quả QR Pay
* @en @returns {Promise<GenerateQrResponse>} - QR Pay result
*/
async generateQr(data, options) {
const { url } = this.buildVnpayUrlInternal(data, { vnp_Command: "genqr" });
const response = await fetch(url.toString());
if (!response.ok) {
throw new Error(`Failed to generate QR: HTTP ${response.status}`);
}
const result = await response.json();
if (!result || typeof result !== "object" || typeof result.code !== "string") {
throw new Error("Invalid response from VNPay: Missing or malformed data");
}
if (result.code !== "00") {
const locale = data.vnp_Locale || this.defaultConfig.vnp_Locale;
result.message = getResponseByStatusCode(result.code, locale, RESPONSE_MAP);
}
const { qrcontent, ...rest } = result;
const generateQrLogPayload = {
createdAt: /* @__PURE__ */ new Date(),
method: "generateQr",
qrcontentLength: qrcontent?.length ?? 0,
...rest
};
this.logger.log(generateQrLogPayload, options, "generateQr");
return result;
}
buildVnpayUrlInternal(data, overrides) {
const dataToBuild = {
...this.defaultConfig,
...data,
...overrides,
// Multiply by 100 to follow VNPay standard
vnp_Amount: data.vnp_Amount * 100
};
if (dataToBuild?.vnp_ExpireDate && !isValidVnpayDateFormat(dataToBuild.vnp_ExpireDate)) {
throw new Error(
"Invalid vnp_ExpireDate format. Use `dateFormat` utility function to format it"
);
}
if (!isValidVnpayDateFormat(dataToBuild?.vnp_CreateDate ?? 0)) {
const timeGMT7 = getDateInGMT7();
dataToBuild.vnp_CreateDate = dateFormat(timeGMT7, "yyyyMMddHHmmss");
}
const redirectUrl = createPaymentUrl({
config: this.config,
data: dataToBuild
});
const signed = calculateSecureHash({
secureSecret: this.config.secureSecret,
data: redirectUrl.search.slice(1).toString(),
hashAlgorithm: this.hashAlgorithm,
bufferEncode: this.bufferEncode
});
redirectUrl.searchParams.append("vnp_SecureHash", signed);
return {
url: redirectUrl,
dataToBuild
};
}
};
__name(_PaymentService, "PaymentService");
var PaymentService = _PaymentService;
// src/services/query.service.ts
var _QueryService = class _QueryService {
/**
* Khởi tạo dịch vụ truy vấn
* @en Initialize query service
*
* @param config - Cấu hình VNPay
* @en @param config - VNPay configuration
*
* @param logger - Dịch vụ logger
* @en @param logger - Logger service
*
* @param hashAlgorithm - Thuật toán băm
* @en @param hashAlgorithm - Hash algorithm
*/
constructor(config, logger, hashAlgorithm) {
this.bufferEncode = "utf-8";
this.config = config;
this.logger = logger;
this.hashAlgorithm = hashAlgorithm;
}
/**
* Đây là API để hệ thống merchant truy vấn kết quả thanh toán của giao dịch tại hệ thống VNPAY.
* @en This is the API for the merchant system to query the payment result of the transaction at the VNPAY system.
*
* @param {QueryDr} query - Dữ liệu truy vấn kết quả thanh toán
* @en @param {QueryDr} query - The data to query payment result
*
* @param {QueryDrResponseOptions<LoggerFields>} options - Tùy chọn
* @en @param {QueryDrResponseOptions<LoggerFields>} options - Options
*
* @returns {Promise<QueryDrResponse>} Kết quả truy vấn
* @en @returns {Promise<QueryDrResponse>} The query result
*/
async queryDr(query, options) {
const command = "querydr";
const dataQuery = {
vnp_Version: this.config.vnp_Version ?? VNP_VERSION,
...query
};
const queryEndpoint = this.config.endpoints.queryDrRefundEndpoint || QUERY_DR_REFUND_ENDPOINT;
const url = new URL(
resolveUrlString(
this.config.queryDrAndRefundHost || this.config.vnpayHost,
queryEndpoint
)
);
const stringToCreateHash = [
dataQuery.vnp_RequestId,
dataQuery.vnp_Version,
command,
this.config.tmnCode,
dataQuery.vnp_TxnRef,
dataQuery.vnp_TransactionDate,
dataQuery.vnp_CreateDate,
dataQuery.vnp_IpAddr,
dataQuery.vnp_OrderInfo
].map(String).join("|").replace(/undefined/g, "");
const requestHashed = hash(
this.config.secureSecret,
Buffer.from(stringToCreateHash, this.bufferEncode),
this.hashAlgorithm
);
const body = {
...dataQuery,
vnp_Command: command,
vnp_TmnCode: this.config.tmnCode,
vnp_SecureHash: requestHashed
};
const response = await fetch(url.toString(), {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const responseData = await response.json();
const message = getResponseByStatusCode(
responseData.vnp_ResponseCode?.toString() ?? "",
this.config.vnp_Locale,
QUERY_DR_RESPONSE_MAP
);
let outputResults = {
isVerified: true,
isSuccess: responseData.vnp_ResponseCode === "00" || responseData.vnp_ResponseCode === 0,
message,
...responseData,
vnp_Message: message
};
const stringToCreateHashOfResponse = [
responseData.vnp_ResponseId,
responseData.vnp_Command,
responseData.vnp_ResponseCode,
responseData.vnp_Message,
this.config.tmnCode,
responseData.vnp_TxnRef,
responseData.vnp_Amount,
responseData.vnp_BankCode,
responseData.vnp_PayDate,
responseData.vnp_TransactionNo,
responseData.vnp_TransactionType,
responseData.vnp_TransactionStatus,
responseData.vnp_OrderInfo,
responseData.vnp_PromotionCode,
responseData.vnp_PromotionAmount
].map(String).join("|").replace(/undefined/g, "");
const responseHashed = hash(
this.config.secureSecret,
Buffer.from(stringToCreateHashOfResponse, this.bufferEncode),
this.hashAlgorithm
);
if (responseData?.vnp_SecureHash && responseHashed !== responseData.vnp_SecureHash) {
outputResults = {
...outputResults,
isVerified: false,
message: getResponseByStatusCode(
WRONG_CHECKSUM_KEY,
this.config.vnp_Locale,
QUERY_DR_RESPONSE_MAP
)
};
}
const data2Log = {
createdAt: /* @__PURE__ */ new Date(),
method: "queryDr",
...outputResults
};
this.logger.log(data2Log, options, "queryDr");
return outputResults;
}
/**
* Đây là API để hệ thống merchant gửi yêu cầu hoàn tiền cho giao dịch qua hệ thống Cổng thanh toán VNPAY.
* @en This is the API for the merchant system to refund the transaction at the VNPAY system.
*
* @param {Refund} data - Dữ liệu yêu cầu hoàn tiền
* @en @param {Refund} data - The data to request refund
*
* @param {RefundOptions<LoggerFields>} options - Tùy chọn
* @en @param {RefundOptions<LoggerFields>} options - Options
*
* @returns {Promise<RefundResponse>} Kết quả hoàn tiền
* @en @returns {Promise<RefundResponse>} The refund result
*/
async refund(data, options) {
const vnp_Command = "refund";
const DEFAULT_TRANSACTION_NO_IF_NOT_EXIST = "0";
const dataQuery = {
...data,
vnp_Command,
vnp_Version: this.config.vnp_Version ?? VNP_VERSION,
vnp_TmnCode: this.config.tmnCode,
vnp_Amount: data.vnp_Amount * 100
};
const {
vnp_Version,
vnp_TmnCode,
vnp_RequestId,
vnp_TransactionType,
vnp_TxnRef,
vnp_TransactionNo = DEFAULT_TRANSACTION_NO_IF_NOT_EXIST,
vnp_TransactionDate,
vnp_CreateBy,
vnp_CreateDate,
vnp_IpAddr,
vnp_OrderInfo
} = dataQuery;
const refundEndpoint = this.config.endpoints.queryDrRefundEndpoint || QUERY_DR_REFUND_ENDPOINT;
const url = new URL(
resolveUrlString(
this.config.queryDrAndRefundHost || this.config.vnpayHost,
refundEndpoint
)
);
const stringToHashOfRequest = [
vnp_RequestId,
vnp_Version,
vnp_Command,
vnp_TmnCode,
vnp_TransactionType,
vnp_TxnRef,
dataQuery.vnp_Amount,
vnp_TransactionNo,
vnp_TransactionDate,
vnp_CreateBy,
vnp_CreateDate,
vnp_IpAddr,
vnp_OrderInfo
].map(String).join("|").replace(/undefined/g, "");
const requestHashed = hash(
this.config.secureSecret,
Buffer.from(stringToHashOfRequest, this.bufferEncode),
this.hashAlgorithm
);
const body = {
...dataQuery,
vnp_SecureHash: requestHashed
};
const response = await fetch(url.toString(), {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const responseData = await response.json();
if (responseData?.vnp_Amount) {
responseData.vnp_Amount = responseData.vnp_Amount / 100;
}
const message = getResponseByStatusCode(
responseData.vnp_ResponseCode?.toString() ?? "",
data?.vnp_Locale ?? this.config.vnp_Locale,
REFUND_RESPONSE_MAP
);
let outputResults = {
isVerified: true,
isSuccess: responseData.vnp_ResponseCode === "00" || responseData.vnp_ResponseCode === 0,
message,
...responseData,
vnp_Message: message
};
const stringToCreateHashOfResponse = [
responseData.vnp_ResponseId,
responseData.vnp_Command,
responseData.vnp_ResponseCode,
responseData.vnp_Message,
responseData.vnp_TmnCode,
responseData.vnp_TxnRef,
responseData.vnp_Amount,
responseData.vnp_BankCode,
responseData.vnp_PayDate,
responseData.vnp_TransactionNo,
responseData.vnp_TransactionType,
responseData.vnp_TransactionStatus,
responseData.vnp_OrderInfo
].map(String).join("|").replace(/undefined/g, "");
const responseHashed = hash(
this.config.secureSecret,
Buffer.from(stringToCreateHashOfResponse, this.bufferEncode),
this.hashAlgorithm
);
if (responseData?.vnp_SecureHash && responseHashed !== responseData.vnp_SecureHash) {
outputResults = {
...outputResults,
isVerified: false,
message: getResponseByStatusCode(
WRONG_CHECKSUM_KEY,
this.config.vnp_Locale,
REFUND_RESPONSE_MAP
)
};
}
const data2Log = {
createdAt: /* @__PURE__ */ new Date(),
method: "refund",
...outputResults
};
this.logger.log(data2Log, options, "refund");
return outputResults;
}
};
__name(_QueryService, "QueryService");
var QueryService = _QueryService;
// src/services/verification.service.ts
var _VerificationService = class _VerificationService {
/**
* Khởi tạo dịch vụ xác thực
* @en Initialize verification service
*
* @param config - Cấu hình VNPay
* @en @param config - VNPay configuration
*
* @param logger - Dịch vụ logger
* @en @param logger - Logger service
*
* @param hashAlgorithm - Thuật toán băm
* @en @param hashAlgorithm - Hash algorithm
*/
constructor(config, logger, hashAlgorithm) {
this.config = config;
this.logger = logger;
this.hashAlgorithm = hashAlgorithm;
}
/**
* Phương thức xác thực tính đúng đắn của các tham số trả về từ VNPay
* @en Method to verify the return url from VNPay
*
* @param {ReturnQueryFromVNPay} query - Đối tượng dữ liệu trả về từ VNPay
* @en @param {ReturnQueryFromVNPay} query - The object of data return from VNPay
*
* @param {VerifyReturnUrlOptions<LoggerFields>} options - Tùy chọn
* @en @param {VerifyReturnUrlOptions<LoggerFields>} options - Options
*
* @returns {VerifyReturnUrl} Kết quả xác thực
* @en @returns {VerifyReturnUrl} The verification result
*/
verifyReturnUrl(query, options) {
const { vnp_SecureHash = "", vnp_SecureHashType, ...cloneQuery } = query;
if (typeof cloneQuery?.vnp_Amount !== "number") {
const isValidAmount = numberRegex.test(cloneQuery?.vnp_Amount ?? "");
if (!isValidAmount) {
throw new Error("Invalid amount");
}
cloneQuery.vnp_Amount = Number(cloneQuery.vnp_Amount);
}
const searchParams = buildPaymentUrlSearchParams(cloneQuery);
const isVerified = verifySecureHash({
secureSecret: this.config.secureSecret,
data: searchParams.toString(),
hashAlgorithm: this.hashAlgorithm,
receivedHash: vnp_SecureHash
});
let outputResults = {
isVerified,
isSuccess: cloneQuery.vnp_ResponseCode === "00" || cloneQuery.vnp_ResponseCode === 0,
message: getResponseByStatusCode(
cloneQuery.vnp_ResponseCode?.toString() ?? "",
this.config.vnp_Locale
)
};
if (!isVerified) {
outputResults = {
...outputResults,
message: "Wrong checksum"
};
}
const result = {
...cloneQuery,
...outputResults,
vnp_Amount: cloneQuery.vnp_Amount / 100
};
const data2Log = {
createdAt: /* @__PURE__ */ new Date(),
method: "verifyReturnUrl",
...result,
vnp_SecureHash: options?.withHash ? vnp_SecureHash : void 0
};
this.logger.log(data2Log, options, "verifyReturnUrl");
return result;
}
/**
* Phương thức xác thực tính đúng đắn của lời gọi ipn từ VNPay
*
* Sau khi nhận được lời gọi, hệ thống merchant cần xác thực dữ liệu nhận được từ VNPay,
* kiểm tra đơn hàng có hợp lệ không, kiểm tra số tiền thanh toán có đúng không.
*
* @en Method to verify the ipn url from VNPay
*
* After receiving the call, the merchant system needs to verify the data received from VNPay,
* check if the order is valid, check if the payment amount is correct.
*
* @param {ReturnQueryFromVNPay} query - Đối tượng dữ liệu trả về từ VNPay
* @en @param {ReturnQueryFromVNPay} query - The object of data return from VNPay
*
* @param {VerifyIpnCallOptions<LoggerFields>} options - Tùy chọn
* @en @param {VerifyIpnCallOptions<LoggerFields>} options - Options
*
* @returns {VerifyIpnCall} Kết quả xác thực
* @en @returns {VerifyIpnCall} The verification result
*/
verifyIpnCall(query, options) {
const hash2 = query.vnp_SecureHash;
const silentOptions = { logger: { loggerFn: ignoreLogger } };
const result = this.verifyReturnUrl(
query,
silentOptions
);
const data2Log = {
createdAt: /* @__PURE__ */ new Date(),
method: "verifyIpnCall",
...result,
...options?.withHash ? { vnp_SecureHash: hash2 } : {}
};
this.logger.log(data2Log, options, "verifyIpnCall");
return result;
}
};
__name(_VerificationService, "VerificationService");
var VerificationService = _VerificationService;
// src/vnpay.ts
var _VNPay = class _VNPay {
/**
* Khởi tạo đối tượng VNPay
* @en Initialize VNPay instance
*
* @param {VNPayConfig} config - VNPay configuration
*/
constructor({
vnpayHost = VNPAY_GATEWAY_SANDBOX_HOST,
queryDrAndRefundHost = VNPAY_GATEWAY_SANDBOX_HOST,
vnp_Version = VNP_VERSION,
vnp_CurrCode = "VND" /* VND */,
vnp_Locale = "vn" /* VN */,
testMode = false,
paymentEndpoint = PAYMENT_ENDPOINT,
endpoints = {},
...config
}) {
if (testMode) {
vnpayHost = VNPAY_GATEWAY_SANDBOX_HOST;
queryDrAndRefundHost = VNPAY_GATEWAY_SANDBOX_HOST;
}
this.hashAlgorithm = config?.hashAlgorithm ?? "SHA512" /* SHA512 */;
const initializedEndpoints = {
paymentEndpoint: endpoints.paymentEndpoint || paymentEndpoint,
queryDrRefundEndpoint: endpoints.queryDrRefundEndpoint || QUERY_DR_REFUND_ENDPOINT,
getBankListEndpoint: endpoints.getBankListEndpoint || GET_BANK_LIST_ENDPOINT
};
this.globalConfig = {
vnpayHost,
vnp_Version,
vnp_CurrCode,
vnp_Locale,
vnp_OrderType: "other" /* Other */,
vnp_Command: VNP_DEFAULT_COMMAND,
paymentEndpoint: initializedEndpoints.paymentEndpoint,
endpoints: initializedEndpoints,
queryDrAndRefundHost,
...config
};
this.loggerService = new LoggerService(config?.enableLog ?? false, config?.loggerFn);
this.paymentService = new PaymentService(
this.globalConfig,
this.loggerService,
this.hashAlgorithm
);
this.verificationService = new VerificationService(
this.globalConfig,
this.loggerService,
this.hashAlgorithm
);
this.queryService = new QueryService(
this.globalConfig,
this.loggerService,
this.hashAlgorithm
);
}
/**
* Lấy cấu hình mặc định của VNPay
* @en Get default config of VNPay
*
* @returns {DefaultConfig} Cấu hình mặc định
* @en @returns {DefaultConfig} Default configuration
*/
get defaultConfig() {
return {
vnp_TmnCode: this.globalConfig.tmnCode,
vnp_Version: this.globalConfig.vnp_Version,
vnp_CurrCode: this.globalConfig.vnp_CurrCode,
vnp_Locale: this.globalConfig.vnp_Locale,
vnp_Command: this.globalConfig.vnp_Command,
vnp_OrderType: this.globalConfig.vnp_OrderType
};
}
/**
* Lấy danh sách ngân hàng được hỗ trợ bởi VNPay
* @en Get list of banks supported by VNPay
*
* @returns {Promise<Bank[]>} Danh sách ngân hàng
* @en @returns {Promise<Bank[]>} List of banks
*/
async getBankList() {
const response = await fetch(
resolveUrlString(
this.globalConfig.vnpayHost ?? VNPAY_GATEWAY_SANDBOX_HOST,
this.globalConfig.endpoints.getBankListEndpoint
),
{
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: `tmn_code=${this.globalConfig.tmnCode}`
}
);
if (!response.ok) {
throw new Error(`Failed to fetch bank list: HTTP ${response.status}`);
}
const bankList = await response.json();
for (const bank of bankList) {
const logoPath = bank.logo_link && bank.logo_link.startsWith("/") ? bank.logo_link.slice(1) : bank.logo_link;
bank.logo_link = resolveUrlString(
this.globalConfig.vnpayHost ?? VNPAY_GATEWAY_SANDBOX_HOST,
logoPath
);
}
return bankList;
}
/**
* Phương thức xây dựng, tạo thành url thanh toán của VNPay
* @en Build the payment url
*
* @param {BuildPaymentUrl} data - Dữ liệu thanh toán cần thiết để tạo URL
* @en @param {BuildPaymentUrl} data - Payment data required to create URL
*
* @param {BuildPaymentUrlOptions<LoggerFields>} options - Tùy chọn bổ sung
* @en @param {BuildPaymentUrlOptions<LoggerFields>} options - Additional options
*
* @returns {string} URL thanh toán
* @en @returns {string} Payment URL
* @see https://sandbox.vnpayment.vn/apis/docs/thanh-toan-pay/pay.html#tao-url-thanh-toan
*/
buildPaymentUrl(data, options) {
return this.paymentService.buildPaymentUrl(data, options);
}
/**
* Phương thức xây dựng, tạo thành qr thanh toán của VNPay
* @en Build the qr payment
*
* @param {BuildPaymentUrl} data - Dữ liệu thanh toán cần thiết để tạo URL QR
* @en @param {BuildPaymentUrl} data - Payment data required to create QR URL
*
* @param {GenerateQrResponseOptions<LoggerFields>} options - Tùy chọn bổ sung
* @en @param {GenerateQrResponseOptions<LoggerFields>} options - Additional options
*
* @returns {Promise<GenerateQrResponse>} Kết quả QR Pay
* @en @returns {Promise<GenerateQrResponse>} QR Pay result
*/
async generateQr(data, options) {
return this.paymentService.generateQr(data, options);
}
/**
* Phương thức xác thực tính đúng đắn của các tham số trả về từ VNPay
* @en Method to verify the return url from VNPay
*
* @param {ReturnQueryFromVNPay} query - Đối tượng dữ liệu trả về từ VNPay
* @en @param {ReturnQueryFromVNPay} query - The object of data returned from VNPay
*
* @param {VerifyReturnUrlOptions<LoggerFields>} options - Tùy chọn để xác thực
* @en @param {VerifyReturnUrlOptions<LoggerFields>} options - Options for verification
*
* @returns {VerifyReturnUrl} Kết quả xác thực
* @en @returns {VerifyReturnUrl} Verification result
* @see https://sandbox.vnpayment.vn/apis/docs/thanh-toan-pay/pay.html#code-returnurl
*/
verifyReturnUrl(query, options) {
return this.verificationService.verifyReturnUrl(query, options);
}
/**
* Phương thức xác thực tính đúng đắn của lời gọi ipn từ VNPay
*
* Sau khi nhận được lời gọi, hệ thống merchant cần xác thực dữ liệu nhận được từ VNPay,
* kiểm tra đơn hàng có hợp lệ không, kiểm tra số tiền thanh toán có đúng không.
*
* Sau đó phản hồi lại VNPay kết quả xác thực thông qua các `IpnResponse`
*
* @en Method to verify the ipn call from VNPay
*
* After receiving the call, the merchant system needs to verify the data received from VNPay,
* check if the order is valid, check if the payment amount is correct.
*
* Then respond to VNPay the verification result through `IpnResponse`
*
* @param {ReturnQueryFromVNPay} query - Đối tượng dữ liệu từ VNPay qua IPN
* @en @param {ReturnQueryFromVNPay} query - The object of data from VNPay via IPN
*
* @param {VerifyIpnCallOptions<LoggerFields>} options - Tùy chọn để xác thực
* @en @param {VerifyIpnCallOptions<LoggerFields>} options - Options for verification
*
* @returns {VerifyIpnCall} Kết quả xác thực
* @en @returns {VerifyIpnCall} Verification result
* @see https://sandbox.vnpayment.vn/apis/docs/thanh-toan-pay/pay.html#code-ipn-url
*/
verifyIpnCall(query, options) {
return this.verificationService.verifyIpnCall(query, options);
}
/**
* Đây là API để hệ thống merchant truy vấn kết quả thanh toán của giao dịch tại hệ thống VNPAY.
* @en This is the API for the merchant system to query the payment result of the transaction at the VNPAY system.
*
* @param {QueryDr} query - Dữ liệu truy vấn kết quả thanh toán
* @en @param {QueryDr} query - The data to query payment result
*
* @param {QueryDrResponseOptions<LoggerFields>} options - Tùy chọn truy vấn
* @en @param {QueryDrResponseOptions<LoggerFields>} options - Query options
*
* @returns {Promise<QueryDrResponse>} Kết quả truy vấn từ VNPay sau khi đã xác thực
* @en @returns {Promise<QueryDrResponse>} Query result from VNPay after verification
* @see https://sandbox.vnpayment.vn/apis/docs/truy-van-hoan-tien/querydr&refund.html#truy-van-ket-qua-thanh-toan-PAY
*/
async queryDr(query, options) {
return this.queryService.queryDr(query, options);
}
/**
* Đây là API để hệ thống merchant gửi yêu cầu hoàn tiền cho giao dịch qua hệ thống Cổng thanh toán VNPAY.
* @en This is the API for the merchant system to refund the transaction at the VNPAY system.
*
* @param {Refund} data - Dữ liệu yêu cầu hoàn tiền
* @en @param {Refund} data - The data to request refund
*
* @param {RefundOptions<LoggerFields>} options - Tùy chọn hoàn tiền
* @en @param {RefundOptions<LoggerFields>} options - Refund options
*
* @returns {Promise<RefundResponse>} Kết quả hoàn tiền từ VNPay sau khi đã xác thực
* @en @returns {Promise<RefundResponse>} Refund result from VNPay after verification
* @see https://sandbox.vnpayment.vn/apis/docs/truy-van-hoan-tien/querydr&refund.html#hoan-tien-thanh-toan-PAY
*/
async refund(data, options) {
return this.queryService.refund(data, options);
}
};
__name(_VNPay, "VNPay");
var VNPay = _VNPay;
export { VNPay };
//# sourceMappingURL=chunk-PHIG47AV.js.map
//# sourceMappingURL=chunk-PHIG47AV.js.map