MATIH Platform is in active MVP development. Documentation reflects current implementation status.
8. Platform Services
Invoices

Invoices

The InvoiceGenerationService creates, finalizes, and manages invoices for tenant billing periods. Invoices contain line items derived from usage aggregates, support discounts and tax calculations, integrate with Stripe for payment collection, and include late payment tracking with grace periods.


Invoice Lifecycle

StatusDescription
DRAFTInvoice created but not yet finalized
PENDINGFinalized, awaiting payment
PAIDPayment received in full
PARTIALLY_PAIDPartial payment received
OVERDUEPast due date without full payment
VOIDCancelled/voided invoice
UNCOLLECTIBLEMarked as uncollectible

Generate an Invoice

Endpoint: POST /api/v1/billing/tenants/:tenantId/invoices

ParameterTypeDescription
subscriptionIdUUIDSubscription to invoice
curl -X POST "http://localhost:8087/api/v1/billing/tenants/550e8400/invoices?subscriptionId=sub-001" \
  -H "Authorization: Bearer ${TOKEN}"

List Tenant Invoices

Endpoint: GET /api/v1/billing/tenants/:tenantId/invoices


Get Invoice

Endpoint: GET /api/v1/billing/invoices/:invoiceId


Finalize Invoice

Endpoint: POST /api/v1/billing/invoices/:invoiceId/finalize

Transitions the invoice from DRAFT to PENDING and triggers payment collection through Stripe.


Download Invoice PDF

Endpoint: GET /api/v1/billing/invoices/:invoiceId/pdf

Returns the invoice as a downloadable PDF file.


Void Invoice

Endpoint: POST /api/v1/billing/invoices/:invoiceId/void

ParameterTypeDescription
reasonStringReason for voiding

Invoice Entity

FieldTypeDescription
idUUIDInvoice identifier
invoiceNumberStringUnique invoice number
tenantIdUUIDOwning tenant
subscriptionSubscriptionAssociated subscription
statusInvoiceStatusCurrent invoice status
periodStartLocalDateBilling period start
periodEndLocalDateBilling period end
issueDateLocalDateDate invoice was issued
dueDateLocalDatePayment due date
subtotalBigDecimalSum of line items
discountAmountBigDecimalTotal discount applied
taxAmountBigDecimalCalculated tax
taxRateBigDecimalTax rate percentage
totalBigDecimalFinal total (subtotal - discount + tax)
amountPaidBigDecimalAmount paid so far
amountDueBigDecimalRemaining balance (total + late fees - paid)
currencyStringCurrency code (default: USD)
stripeInvoiceIdStringStripe invoice reference
lineItemsListInvoice line items

Late Payment Handling

The invoice entity includes fields for late payment tracking:

FieldTypeDescription
gracePeriodEndsAtLocalDateDefault: due date + 15 days
lateFeeAppliedBooleanWhether a late fee has been applied
lateFeeAmountBigDecimalTotal late fees added
consecutiveUnpaidMonthsIntegerMonths of consecutive non-payment
firstReminderSentAtLocalDateTimeFirst payment reminder timestamp
secondReminderSentAtLocalDateTimeSecond reminder timestamp
lateWarningSentAtLocalDateTimeLate warning notification timestamp

The LatePaymentService manages escalation: first reminder, second reminder, late warning, late fee application, and eventually marking invoices as uncollectible.