@vegaci_shared/vsplit-payment-gateway
Version:
A B2B payment gateway integration package for Stripe with split payment capabilities
106 lines (105 loc) • 2.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PaymentTimer = void 0;
/**
* Payment timer utility for handling timeouts
*/
class PaymentTimer {
constructor() {
this.timers = new Map();
this.activeTimer = null;
}
/**
* Start a timer with callback
*/
startTimer(duration, callback, timerId) {
const timer = setTimeout(() => {
if (timerId) {
this.timers.delete(timerId);
}
this.activeTimer = null;
callback();
}, duration);
if (timerId) {
// Clear existing timer with same ID
this.clearTimer(timerId);
this.timers.set(timerId, timer);
}
else {
// Clear active timer
this.clearTimer();
this.activeTimer = timer;
}
}
/**
* Clear a specific timer or the active timer
*/
clearTimer(timerId) {
if (timerId) {
const timer = this.timers.get(timerId);
if (timer) {
clearTimeout(timer);
this.timers.delete(timerId);
}
}
else {
if (this.activeTimer) {
clearTimeout(this.activeTimer);
this.activeTimer = null;
}
}
}
/**
* Clear all timers
*/
clearAllTimers() {
// Clear active timer
if (this.activeTimer) {
clearTimeout(this.activeTimer);
this.activeTimer = null;
}
// Clear all named timers
this.timers.forEach((timer) => {
clearTimeout(timer);
});
this.timers.clear();
}
/**
* Check if a timer is active
*/
hasActiveTimer(timerId) {
if (timerId) {
return this.timers.has(timerId);
}
return this.activeTimer !== null;
}
/**
* Get remaining time for a timer (approximate)
*/
getRemainingTime(_timerId) {
// Note: JavaScript doesn't provide built-in way to get remaining time
// This would need to be tracked separately if needed
return null;
}
/**
* Start a recurring timer
*/
startInterval(duration, callback, timerId) {
const timer = setInterval(callback, duration);
if (timerId) {
this.clearTimer(timerId);
this.timers.set(timerId, timer);
}
else {
this.clearTimer();
this.activeTimer = timer;
}
}
/**
* Destroy the timer instance
*/
destroy() {
this.clearAllTimers();
}
}
exports.PaymentTimer = PaymentTimer;