Billing & Packages

NIVAA uses a prepaid package model -- parents purchase session bundles, and each approved session deducts from their balance. Coordinator billing and payout UI is currently frozen for the beta period, so the sidebar entry remains visible but disabled and active workspace monetary values are hidden.

Current Beta Freeze

Coordinator billing routes remain documented here for system reference, but the current workspace UI intentionally disables /admin/billing and hides live money values until the finance scope is re-opened.

Monthly Billing Run

Endpoint

POST /billing/run-monthly -- triggers invoice and payout generation for a billing period. Creates one invoice per parent and one payout record per tutor for all approved sessions in the period.

The billing run aggregates all Approved sessions within the specified period, calculates totals using the pricing catalog, and generates PDF invoices stored in R2. This runs automatically via Cloudflare Cron Triggers at the start of each month, but coordinators can trigger it manually for corrections.

Month-to-Date Summary

Endpoint

GET /billing/mtd -- returns aggregated billing data for the current month. Includes total sessions, total revenue, and per-tutor/per-parent breakdowns.

Billing Records

Endpoint

GET /billing/records/me -- admin view returns all billing records across all users. Supports filtering by date range, parent, and tutor.

Core Billing Endpoints

EndpointMethodDescription
/billing/run-monthlyPOSTRun monthly billing -- creates invoices and payouts
/billing/mtdGETMonth-to-date aggregated billing summary
/billing/records/meGETAll billing records (admin sees all users)
/payoutGETList all payout records
/payout/:idPATCHUpdate payout status (mark as paid, hold, etc.)
/payout/generateGETGenerate payout summary for a period
/admin/package-ledgersGETSessions purchased/redeemed/remaining per customer
/admin/pricing/catalogGETAll pricing plans by service line, level, duration
/admin/matches/:id/incentivePUTSet per-match tutor incentive bonus

Payout Cycles

Payouts are generated alongside invoices during the monthly billing run. Each tutor receives a payout record summarizing their sessions and earnings for the period.

  • GET /payout -- list all payout records, filterable by status and period.
  • PATCH /payout/:id -- update a payout (mark as paid, add notes, hold for review).
  • GET /payout/generate -- preview payout summary before committing.

Frontend page: /admin/billing/payouts

Package Ledgers

Endpoint

GET /admin/package-ledgers -- shows sessions purchased, redeemed, and remaining for each parent. Use this to identify parents running low on sessions.

Frontend page: /admin/billing/packages

Low Package Alerts

Alert Threshold

Parents with < 20% sessions remaining in their package are flagged automatically. These alerts appear in the parent alert system and on the coordinator dashboard.

The alert system computes sessions_remaining / sessions_purchased for each active package. When the ratio drops below 0.20, a low-package alert is generated. Coordinators should reach out to the parent to discuss renewal.

Pricing Catalog

Endpoint

GET /admin/pricing/catalog -- returns all pricing plans organized by service line, level, and duration. Each plan includes the per-session rate and package pricing tiers.

Tutor Incentives

Coordinators can set per-match incentive bonuses for tutors to encourage quality and retention.

Endpoint

PUT /admin/matches/:id/incentive -- set or update the bonus amount for a specific tutor-student match.

PDF Generation

Invoices and payout summaries are generated as PDFs using pdf-lib directly inside the Cloudflare Worker. Generated PDFs are stored in the nivaa-pdfs R2 bucket and linked to the corresponding billing record.

Frontend Pages

RoutePurpose
/admin/billing/invoicesView and manage parent invoices
/admin/billing/payoutsView and manage tutor payouts
/admin/billing/cyclesBilling cycle history and management
/admin/billing/packagesPackage ledgers and session balances