1 import type { ChargebeeInstanceConfiguration } from '../lib';
2 import { addCheckpoint } from './checkpoints';
4 let chargebee: any | null = null;
5 export function resetChargebee() {
9 export function createChargebee(config: ChargebeeInstanceConfiguration) {
15 addCheckpoint('chargebee.init', config);
16 const instance = (window as any).Chargebee.init(config);
17 addCheckpoint('chargebee.init.done');
20 } catch (error: any) {
21 addCheckpoint('chargebee.init.error', {
22 message: error?.message,
29 export function getChargebeeInstance() {
31 throw new Error('Chargebee is not initialized');
37 export function isChargebeeLoaded(): boolean {
38 return !!(window as any).Chargebee;
41 export async function wait(ms: number) {
42 return new Promise((resolve) => setTimeout(resolve, ms));
45 export async function pollUntilLoaded(): Promise<void> {
47 const maxTime = 55000;
50 while (timeElapsed < maxTime) {
51 if (isChargebeeLoaded()) {
52 addCheckpoint('chargebee.loaded', {
58 timeElapsed += timeStep;
61 throw new Error('Chargebee did not load');