@openinsure/billing package handles the full billing lifecycle: installment schedule creation, invoice generation, Stripe payment collection, NSF handling, commission accounting, premium financing, and fiduciary trust account management.
Installment Plan Types
When a policy is bound, the billing module creates an installment schedule based on the selected plan:| Plan | Code | Down Payment | Remaining Payments | Service Fee |
|---|---|---|---|---|
| Paid in Full | PIF | 100% | None | None |
| 2-Pay | TWO_PAY | 50% | 1 × 50% at 6 months | None |
| Quarterly | QUARTERLY | 25% | 3 × 25% quarterly | $5/installment |
| Monthly (10-pay) | MONTHLY_10 | 20% (2 months) | 8 × 10% monthly | $8/installment |
| Monthly (12-pay) | MONTHLY_12 | ~8.33% | 11 × 8.33% monthly | $8/installment |
| Premium Finance | PREMIUM_FINANCE | Down per PFA | Per PFA schedule | Per PFA rate |
billing_schedules table. Each installment has a due_date, amount, status (pending, invoiced, paid, overdue, waived), and a stripe_payment_intent_id when collected.
Create Installment Schedule
The schedule is automatically created whenPOST /v1/submissions/:id/bind succeeds. You can also create or modify it:
Stripe Integration
OpenInsure uses Stripe PaymentIntents for all premium collection. The integration is inpackages/billing/src/stripe/.
Payment Flow
Creating a PaymentIntent
Stripe Webhook Events Handled
| Event | Action |
|---|---|
payment_intent.succeeded | Mark invoice paid, post commission, send receipt |
payment_intent.payment_failed | Mark invoice failed, trigger dunning |
charge.dispute.created | Flag policy for review, notify UW |
charge.refunded | Post return premium to ledger |
setup_intent.succeeded | Store verified payment method for recurring billing |
Webhook Endpoint
Stripe webhooks are received atPOST /v1/webhooks/stripe. The Worker validates the Stripe-Signature header before processing:
Premium Financing
For commercial accounts where the full annual premium is large, OpenInsure integrates with Premium Finance Agreements (PFAs). The insured borrows the net premium from a premium finance company (PFC), pays the PFC in installments, and the MGA receives the full premium upfront.PFA Workflow
- Producer selects “Premium Finance” as the installment plan.
- The portal generates a PFA quote via the configured PFC integration (e.g., AFCO, First Insurance Funding).
- Insured signs the PFA electronically.
- PFC wires the net premium to the MGA trust account.
- Billing module records
PIFpayment against the policy invoice. - If the insured defaults, the PFC sends a
PREMIUM_FINANCE_CANCELLATIONnotice — the system triggers a 10-day notice of cancellation workflow.
Commission Accounting
Every policy transaction posts commission entries to thecommission_ledger table.
Commission Types
| Type | Description | Timing |
|---|---|---|
PRODUCER_COMMISSION | Percentage of gross premium to the producer | Earned pro-rata with premium |
MGA_OVERRIDE | MGA’s retained spread above producer commission | Earned pro-rata |
CARRIER_NET | Net premium remitted to carrier | Earned pro-rata |
CONTINGENT | Profit-sharing based on loss ratio | Calculated at year-end |
MGAFEE | Flat policy fee retained by MGA | 100% earned at inception |
Earned vs. Unearned Premium
Commission is earned on a pro-rata basis across the policy term. If a policy is cancelled:- Earned commission = Commission × (days in force / total days)
- Unearned commission must be returned to the carrier
Commission Dashboard API
Fiduciary Trust Account Management
MGAs are fiduciaries for premium they collect on behalf of carriers. OpenInsure maintains a shadow trust ledger that reconciles against the actual bank account.Trust Account Entries
Every premium receipt, commission deduction, carrier remittance, and refund is posted to thetrust_ledger table:
Carrier Remittance Reports
At the end of each remittance cycle (typically monthly), the billing module generates a carrier remittance report:Double-Entry Ledger (TigerBeetle)
Thetrust_ledger SQL table shown above is the PlanetScale-side reconciliation record. The authoritative double-entry ledger is TigerBeetle, a purpose-built financial database running on Fly.io. Every premium dollar is accounted for in both systems, but TigerBeetle is the source of truth for balances.
Fiduciary Split Flow
When a premium payment is received,calculateFiduciarySplit() breaks the gross amount into 5-6 buckets. The split is posted atomically to TigerBeetle as a set of transfers debiting MGA_FIDUCIARY and crediting the destination accounts:
Account Types
Each organization is provisioned with 9 TigerBeetle accounts:| Code | Account Type | Purpose |
|---|---|---|
| 1 | CARRIER_PAYABLE | Net premium owed to the carrier |
| 2 | MGA_FIDUCIARY | Hub account — all premium receipts land here first |
| 3 | MGA_REVENUE | MGA commission and fee income |
| 4 | PRODUCER_PAYABLE | Commissions owed to producers |
| 5 | TAX_AUTHORITY_PAYABLE | Premium taxes owed to state authorities |
| 6 | LOSS_FUND | Captive loss fund assets |
| 7 | CLAIMS_PAID | Cumulative claim disbursements |
| 8 | RESERVES | Outstanding loss reserves |
| 9 | REINSURER_PAYABLE | Reinsurance premiums owed to reinsurers |
Transfer Codes
| Code | Name | Description |
|---|---|---|
| 101 | PREMIUM_PAYMENT | Gross premium receipt into the fiduciary account |
| 102 | COMMISSION_SPLIT | Commission payout to producer or MGA |
| 103 | TAX_SPLIT | Premium tax allocation to tax authority |
| 104 | FEE_SPLIT | Fee allocation (stamping, policy, MGA) |
| 201 | SETTLEMENT | Claim settlement disbursement |
Claim Transactions
recordClaimTransaction supports four transaction types:
- payment — Debits
LOSS_FUNDand creditsCLAIMS_PAIDwhen a claim payment is issued. - reserve_adjustment — Moves funds between
RESERVESandLOSS_FUNDwhen case reserves change. - recovery — Credits
LOSS_FUNDwhen a subrogation or salvage recovery is received. - reinsurance_recovery — Debits
REINSURER_PAYABLEand creditsLOSS_FUNDwhen a stop-loss or treaty recovery is received.
NSF and Return Premium Handling
NSF (Non-Sufficient Funds)
When a Stripe payment fails:- The invoice is marked
FAILED. - A dunning sequence begins: reminder at Day 1, warning at Day 5, final notice at Day 9.
- If the invoice remains unpaid at Day 10, a cancellation for non-payment is initiated (state notice requirements apply).
- An NSF fee (configurable, typically 35) is added to the outstanding balance.
Return Premium
Return premium arises from cancellations, endorsements that reduce coverage, and audit adjustments that result in lower payroll/revenue than estimated.refundMethod field controls this — the compliance engine will override
ORIGINAL_PAYMENT with CHECK if the original charge is too old to reverse.
:::