Naalya Handbook
School featuresPayments

Payment item and transaction operations

The bursary routes that define a fee, start a payment and take the provider callback, what happens when the money is posted, and how the Hub shows an account.

Every route here needs Feature.BURSARY. @Public() skips that guard but not the checks inside the services. SchoolPay pay-code webhooks are a separate controller; see SchoolPay inbound.

How a payment moves from the Hub through the provider to the ledger

Which route starts a payment

WhoRouteUse it for
Any signed-in userPOST /payment-items/:id/pay (payPaymentItem)A fee the school defined
Account holder, verified guardian, or staff with create on ledgerPOST /ledger/accounts/:accountUserId/pay (payLedgerAccount)Paying what an account owes, or adding credit. The Hub's pay screen
Students and guardiansPOST /transactions (createTransaction)An ad-hoc payment with a reason
Anyone with the referencePOST /transactions/:reference/request-mobile-paymentSending the phone prompt for a pending payment

Every route returns a pending transaction with a provider reference. A phone prompt or the hosted page's redirectUrl comes next. Nothing is posted until the provider calls back.

Payment items

PaymentItemController at /api/v1/payment-items.

RouteOperation idNeedsNotes
GET /me/eligiblelistMyEligiblePaymentItemsStaff, student, guardian or guestActive items the caller may pay, with paid status
GET /me/chargeslistMyPaymentChargesSameCharges for ASSIGNED items
POST /:id/paypayPaymentItemSameOptional provider (school_pay, pesapal, manual), resourceId (for resource-bound items), email, phoneNumber
POST /createPaymentItemcreate payment_item
GET /listPaymentItemslist payment_item
GET /chargeslistPaymentChargeslist payment_item
GET /billing/previewpreviewTermBillinglist payment_item and list ledgerTerm not found., Term does not belong to this campus.
POST /billing/raiseraiseTermFeescreate ledger and create payment_itemQuery campusId. Refused for a locked year. Jobs are idempotent
GET, PATCH, DELETE /:idgetPaymentItem, updatePaymentItem, deletePaymentItemread, update, delete payment_item
GET /:id/chargeslistPaymentItemChargesread payment_item
POST /:id/materializematerializePaymentItemChargesupdate payment_itemQueues charges. Refused unless the item is ASSIGNED

The static me and billing paths are declared before /:id, so they are never read as ids.

Transactions

TransactionController at /api/v1/transactions.

RouteOperation idWhoNotes
POST /createTransactionStudent or guardianreason (admission_fees, tuition_fees, school_uniform, other), campusId, amount, firstName, lastName; optional paymentItemId, resourceId, provider, email, phoneNumber
GET /listTransactionslist on transaction
GET /:referencegetTransactionByReferencePublicLooks up by reference across schools. Does not check the bursary flag
POST /:reference/request-mobile-paymentrequestMobilePaymentByReferencePublicOnly for pending. Checks the bursary flag for that school and campus. The provider must support phone prompts
POST /callback/:providertransactionProviderCallbackPublicschool_pay, pesapal or manual, else 400

From callback to posted money

Find the payment. handleCallback reads the provider's reference and finds the transaction by externalReference, or by a phone-prompt entry in providerMetadata.

Verify it. Campus credentials are loaded and parseCallback checks the provider's signature. A non-pending payment is acknowledged and left alone.

Record the outcome. applyOutcome: on success it stores the receipt fields and queues SETTLE_PAYMENT (job id settle-{transactionId}, removing a failed job with that id first). Pending stores metadata. Anything else marks the payment failed and emits paymentFailed.

Post it. The worker's LedgerSettlementService.settle locks the row and continues only for pending or cancelled. It sets success, then allocates to the intended charges in id order, each up to the smallest of the requested line, the charge's outstanding, and what is left of the payment. The rest is credit.

Announce it. After commit, paymentSettled fires once. A second settle on a success row does nothing, so nothing posts or notifies twice.

A 200 from the callback is not proof of payment

A missing or unknown reference, or a failed signature, returns acknowledged: false, but the HTTP reply is still Callback processed (Pesapal gets status 500 in its body). A queued SETTLE_PAYMENT job has not posted either. Only a committed settle has.

manual passes the controller's check but is not a registered adapter (only school_pay and pesapal are), so its callback is refused with Unsupported payment provider: manual. Manual payments are posted by settleManual (for pending or pending_verification) or recordAndSettle, not by a callback.

After the money is posted

paymentSettled sets off:

WhatTo whomNotes
PAYMENT_RECEIVED emailThe payer (payerUserId), not necessarily the account holderSubject Payment received: plus the school. PDF receipt attached. Links to /guest/account, /guardian/payments or /staff-hub/account by user type; anyone else to /
PAYMENT_RECEIVED WhatsAppThe payerThe school's saved wording, or the default if the saved one has missing or unknown tokens. No PDF
Receipt archiveA PDF job receipt-{transactionId}, 3 attempts
LEDGER_CHANGEStaff screens on that accountRealtime refresh
Staff alertThe school's Teams route, and its WhatsApp route if setNot the payer's notification

None of these can unsettle a payment. Failures are logged and the money stays posted. The payload's balanceAfter is what the account owes minus credit, never below zero.

Reading an account

GET /ledger/accounts/me (getMyLedgerAccount) and GET /ledger/accounts/:accountUserId (getLedgerAccount) need read on ledger for that account. Students and staff can read their own; a verified guardian can read their children's. Anyone else gets Access denied to this resource.

FieldMeans
Open chargesopen charges with outstanding above zero (amount minus waived minus allocated)
overdueOutstanding on charges whose dueAt has passed. No dueAt (an admission fee) is never overdue
creditEvery successful payment's amount minus what was allocated, across the whole account
balanceOutstanding minus credit. Negative when credit exceeds what's owed
recentPaymentsThe latest 20 transactions, any status

In the Hub

The account page (AccountPage):

SituationWallet shows
Something owedTo pay, the amount owed, and any credit beside it
Nothing owed, charges remainBalance, the credit, "Your credit covers what you owe"
No chargesBalance, "You are all paid up"

Use credit appears when there is credit and an open charge. Payers aren't on the realtime bus, so the page polls every 10 seconds while any payment is pending, and refetches on focus.

The pay screen (PayAccountPage):

Choose what to pay. Every open charge starts ticked (or only the one in chargeId). With nothing owed, enter an amount; anything not put on a fee becomes credit.

Choose a campus, only for an amount with no fee when there's more than one payable campus.

Confirm with a phone number and optional email.

Choose how to pay, only when the campus has more than one provider. The Hub calls payLedgerAccount, which defers registering with the provider.

The result opens /pay/$reference: Pesapal goes on to redirectUrl; SchoolPay offers a phone prompt or the pay code; a paid admission fee returns to its application. Download receipt opens a signed link.

payLedgerAccount refuses a request with no allocations and no amount, lines that add up to more than the amount, a campus the account can't pay at, and anyone other than the holder, a verified guardian, or staff with create on ledger (the route decorator only asks for read).

On this page