@foxdev/pg-orkut
Version:
simple payment gateway order kuota with qris
26 lines (23 loc) • 772 B
JavaScript
export const getCurrentDateTimeInIndoTime = (tz = "WIB") => {
const offset = { WIB: 7, WITA: 8, WIT: 9 }[tz] ?? 7;
const date = new Date(Date.now() + offset * 3600000);
return date.toISOString().replace("T", " ").slice(0, 19);
};
export function ConvertCRC16(str) {
let crc = 0xffff;
for (let i = 0; i < str.length; i++) {
crc ^= str.charCodeAt(i) << 8;
for (let j = 0; j < 8; j++) {
crc = crc & 0x8000 ? (crc << 1) ^ 0x1021 : crc << 1;
}
}
let hex = crc & 0xffff;
return hex.toString(16).toUpperCase().padStart(4, "0");
}
export function generateReffId() {
const timestamp = Date.now();
const random = Math.floor(Math.random() * 10000)
.toString()
.padStart(4, "0");
return `TRX-${timestamp}`;
}