vnpay
Version:
An open-source nodejs library support to payment with VNPay
102 lines (97 loc) • 3.67 kB
TypeScript
import { BinaryLike } from 'crypto';
import { VnpLocale, HashAlgorithm } from './enums.js';
import { G as GlobalConfig } from './vnpay-config.type-Uj0UzQ4I.js';
declare function getDateInGMT7(date?: Date): Date;
/**
* Định dạng lại ngày theo định dạng của VNPay, mặc định là yyyyMMddHHmmss
* @en Format date to VNPay format, default is yyyyMMddHHmmss
*
* @param date date to format
* @param format format of date
* @returns formatted date
*/
declare function dateFormat(date: Date, format?: string): number;
/**
* Parse a vnpay date format number to date
* @param dateNumber An vnpay date format number
* @returns Date
*/
declare function parseDate(dateNumber: number | string, tz?: 'utc' | 'local' | 'gmt7'): Date;
/**
* Validate if the date is match with format `yyyyMMddHHmmss` or not
* @param date The date to be validated
* @returns True if the date is valid, false otherwise
*/
declare function isValidVnpayDateFormat(date: number): boolean;
declare function generateRandomString(length: number, options?: {
onlyNumber?: boolean;
}): string;
/**
* Lấy thông tin response theo mã response
* @en Get response message by response code
*
* @param responseCode response code from VNPay
* @param locale locale of response text
* @param responseMap map of response code and response text if you want to custom
* @returns message of response code
*/
declare function getResponseByStatusCode(responseCode?: string, locale?: VnpLocale, responseMap?: Map<string, Record<VnpLocale, string>>): string;
declare function resolveUrlString(host: string, path: string): string;
declare function hash(secret: string, data: BinaryLike | string | Buffer, algorithm: HashAlgorithm): string;
/**
* Truyền vào `loggerFn` để bỏ qua logger
*
* @en Pass to `loggerFn` for ignoring logger
* @returns {void}
*/
declare function ignoreLogger(): void;
/**
* Ghi dữ liệu ra console
*
* @en Log data to console
* @param data - Data to be logged
*/
declare function consoleLogger(data: unknown, symbol?: keyof Console): void;
/**
* Ghi dữ liệu ra file
*
* @en Log data to file
* @param data Data to be logged
* @param filePath File path to be written
* @param errorCallback Error callback function
*/
declare function fileLogger(data: unknown, filePath: string, errorCallback?: unknown): void;
/**
* Hàm tạo các parameter cho query string
* @en Function to build payment URL search parameters
*/
declare function buildPaymentUrlSearchParams(data: Record<string, unknown>): URLSearchParams;
/**
* Hàm tạo URL thanh toán dựa trên config và data
* @en Function to create payment URL based on config and data
*/
declare function createPaymentUrl({ config, data, }: {
config: GlobalConfig;
data: Record<string, unknown>;
}): URL;
/**
* Hàm tính toán mã bảo mật
* @en Function to calculate secure hash
*/
declare function calculateSecureHash({ secureSecret, data, hashAlgorithm, bufferEncode, }: {
secureSecret: string;
data: string;
hashAlgorithm: HashAlgorithm;
bufferEncode: BufferEncoding;
}): string;
/**
* Hàm xác minh mã bảo mật
* @en Function to verify secure hash
*/
declare function verifySecureHash({ secureSecret, data, hashAlgorithm, receivedHash, }: {
secureSecret: string;
data: string;
hashAlgorithm: HashAlgorithm;
receivedHash: string;
}): boolean;
export { buildPaymentUrlSearchParams, calculateSecureHash, consoleLogger, createPaymentUrl, dateFormat, fileLogger, generateRandomString, getDateInGMT7, getResponseByStatusCode, hash, ignoreLogger, isValidVnpayDateFormat, parseDate, resolveUrlString, verifySecureHash };