All files / src/billing check.ts

96% Statements 24/25
90.91% Branches 10/11
100% Functions 3/3
95.45% Lines 21/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  1x 1x 1x 1x 1x 1x   12x 12x   12x 45x   12x     12x   12x 3x 3x   9x 9x   9x 7x 10x         1x      
import {Context} from '../context';
import {SessionInterface} from '../auth/session/types';
 
import {hasActivePayment} from './has_active_payment';
import {requestPayment} from './request_payment';
 
interface CheckInterface {
  session: SessionInterface;
  isTest?: boolean;
}
 
interface CheckReturn {
  hasPayment: boolean;
  confirmBillingUrl?: string;
}I

export async function check({
  session,
  isTest = true,
}: CheckInterface): Promise<CheckReturn> {
  if (!Context.BILLING) {
    return {hasPayment: true, confirmBillingUrl: undefined};
  }
 
  let hasPayment: boolean;
  let confirmBillingUrl: string | undefined;
 
  if (await hasActivePayment(session, isTest)) {
    hasPayment = true;
  } else {
    hasPayment = false;
    confirmBillingUrl = await requestPayment(session, isTest);
  }
 
  return {hasPayment, confirmBillingUrl};
}