@cfxlabsinc/b2b-services
    Preparing search index...

    Class RecurringFeeInvoiceAdminService

    Issues each month's invoice and publishes the events that email it and its receipt. The terms promise the invoice before payment, so the sweep waits for the invoice email before charge, which also refuses an undelivered one.

    Hierarchy (View Summary)

    Index
    db: B2bDatabase
    instance: (...args: []) => RecurringFeeInvoiceAdminService = ...

    The process default: built from each dependency's own instance().

    • The dashboard's Charge again. An escalated month whose invoice was never emailed, as the sweep leaves a reissue at the retry limit, has it emailed instead (INVOICE_SENT); the next Charge again charges once delivered.

      Parameters

      • month: { billingDate?: string; customerId: string; periodKey: string }
        • OptionalbillingDate?: string

          YYYY-MM-DD in the billing timezone; today when omitted.

        • customerId: string
        • periodKey: string

      Returns Promise<
          | { ok: true; value: RecurringFeeChargeOutcome }
          | {
              error:
                  | ServiceError<
                      "INVALID_PERIOD_KEY"
                      | "FUTURE_PERIOD_KEY",
                      { periodKey: string },
                  >
                  | ServiceError<
                      "RECURRING_FEE_MONTH_NOT_ESCALATED",
                      { customerId: string; periodKey: string },
                  >;
              ok: false;
          },
      >

    • The month's invoice, issued if none, numbered CFX-YYYYMMDD-NN under an advisory lock on the date. Unmailed and uncharged, it takes the current terms; billingDate is charge's, so both refuse a later month alike.

      Parameters

      • __namedParameters: { billingDate?: string; customerId: string; periodKey: string }
        • OptionalbillingDate?: string

          YYYY-MM-DD in the billing timezone; the issue clock's date when omitted.

        • customerId: string
        • periodKey: string

      Returns Promise<
          | { ok: true; value: RecurringFeeInvoiceIssueOutcome }
          | {
              error:
                  | ServiceError<
                      "RECURRING_FEE_SOURCE_ACCOUNT_UNAVAILABLE",
                      { sourceAccountId: string },
                  >
                  | ServiceError<"FUTURE_PERIOD_KEY", { periodKey: string }>;
              ok: false;
          },
      >

    • Republish receipts settled one hour to seven days ago and never sent, paging through all so unsendable ones cannot crowd out the rest. The fixed event id dedupes; republished counts SNS accepts, and a refusal throws.

      Returns Promise<{ republished: number }>

    • Parameters

      • __namedParameters: {
            customerIds?: string[];
            escalated?: boolean;
            ids?: string[];
            page?: number;
            pageSize?: number;
            paid?: boolean;
            periodKeys?: string[];
            voided?: boolean;
            waived?: boolean;
        }
        • OptionalcustomerIds?: string[]
        • Optionalescalated?: boolean

          Omit for both; true keeps only invoices escalated to ops.

        • Optionalids?: string[]
        • Optionalpage?: number
        • OptionalpageSize?: number
        • Optionalpaid?: boolean

          Omit for both; false keeps only months with no COMPLETED charge.

        • OptionalperiodKeys?: string[]
        • Optionalvoided?: boolean

          Omit for both; false keeps only the live invoice of each month.

        • Optionalwaived?: boolean

          Omit for both; false drops waived invoices.

      Returns Promise<
          {
              ok: true;
              value: { hasNext: boolean; items: RecurringFeeInvoice[]; total: number };
          },
      >

    • Close a month that ended unbilled with the fee PAUSED or the customer not ACTIVE. A sweep past the billing day records it with a voided invoice, which a resume reissues past; next month's sweep waives it if still inactive. Idempotent per customer-month; not emailed.

      Parameters

      • __namedParameters: { billingDate: string; periodKey: string }

      Returns Promise<{ marked: number; waived: number }>