SchoolPay inbound
The public pay-code webhook, the three-day pull, and the staff inbox that books or ignores an unmatched row.
SchoolPay reaches the ledger in two different ways. The adapter in Gateways handles an ad-hoc payment the Hub started (register, phone prompt, parseCallback). This page is the other path: money a payer made with a student pay code, which arrives as a webhook or as a pull, and is stored on school_pay_inbound before it is booked.
Both controllers sit behind Feature.BURSARY. The webhook is @Public(), so the feature flag does not run on that route. The inbox is authenticated.
Webhook
POST /api/v1/transactions/school-pay/inbound/:campusId is SchoolPayInboundWebhookController.webhook (operationId schoolPayInboundWebhook). campusId is a UUID (ParseUUIDPipe, so a bad id is 400 before the service runs). The body is untyped (unknown). The handler always returns 200 and { "message": "Callback processed" }. The service return value is not the HTTP body. The method comment says SchoolPay does not retry.
ingestWebhook returns 'rejected' without throwing when any of these is true:
payment.schoolpayReceiptNumber,payment.studentPaymentCode,signature, or a stringpayment.paymentDateAndTimeis missing.- Campus SchoolPay credentials cannot be resolved, or they have no
password. verifySignaturefails.- The row fails
validateRow(below). - The campus id is unknown or has no
schoolId.
verifySignature hashes the campus API password concatenated with schoolpayReceiptNumber (SHA-256, hex). It lowercases the provided signature and compares the two digests with timingSafeEqual after a length check. A mismatch is logged and still answered with HTTP 200. Do not treat that status as proof the signature was valid. See Security and example data.
The payload type on SchoolPayWebhookPayload is 'SCHOOL_FEES' | 'OTHER_FEES'.
What counts as a completed row
COMPLETED_STATUSES is SUCCESS, SUCCESSFUL, COMPLETED, and PAID, compared after toUpperCase(). The comment above the set says the vocabulary is unspecified and should be widened after the first UAT payload.
validateRow skips a row (the webhook then returns 'rejected'; the pull increments nothing for that row) when:
- The webhook’s
transactionCompletionStatusis not a string. A pull row with no status is allowed. The comment says the pull endpoint is documented to return settled rows only. - The status is a string and is not in
COMPLETED_STATUSES. paymentDateAndTimeis not a parseable'YYYY-MM-DD HH:MM:SS'string. The parser appends+03:00(the comment says Uganda time, no DST).amountis not a finite number greater than zero.
A new receipt is inserted with .orIgnore(). A known receipt makes ingest return 'duplicate'. A new row returns 'stored' even if matching or booking then throws. That failure is logged.
Matching looks up a student with the same campusId and schoolPayCode as the row’s pay code. No student leaves the row unmatched and emits LEDGER_EVENTS.schoolPayUnmatched. A match claims the row (unmatched to matched) and books a ledger credit. Booking uses TransactionProvider.SCHOOL_PAY, TransactionReason.OTHER, externalReference and receiptNumber set to the SchoolPay receipt, and accountUserId set to the student’s user id. Channel text matching mobile, mtn, airtel, or momo maps to mobile_money. Text matching bank, agent, or branch maps to bank_deposit. Anything else leaves method null.
book throws ConflictException with Already booked when the row already has a transactionId, and Receipt already booked when a SchoolPay transaction already uses that receipt as externalReference.
Pull
CronJob.SyncSchoolPayTransactions is the scheduler id sync-school-pay-transactions. CronRegistrar registers it from cron.syncSchoolPay, which is CRON_SYNC_SCHOOL_PAY. The schema default and .env.example are both 0 0 * * *, and the registrar passes tz: 'UTC'. That is 00:00 UTC (03:00 in Kampala) once a day, not an hourly tick. A comment inside validateRow still says “the hourly pull”. TransactionOutcomeService.queueFollowUpChecks mentions a twice-daily check in a comment. The cron processor has one SchoolPay case, not a second schedule. CRON_ENABLED=0 purges schedules and registers none. The job was not run.
The tick does not pull. CronProcessor handles CronJob.SyncSchoolPayTransactions by adding LedgerJob.SYNC_SCHOOL_PAY to LEDGER_QUEUE with an empty payload, removeOnComplete: 20, and removeOnFail: 50. LedgerProcessor handles that job by calling inbound.pullAll() and logging SchoolPay pull run. A campus failure inside pullAll is the service’s own catch, described below. An unknown cron name throws No handler for cron job: ... so the tick is retried rather than marked successful.
pullAll lists campuses with SchoolPay enabled, keeps those where Feature.BURSARY is enabled for that school and campus, and calls pullCampus for each. One campus failing does not stop the others. Two enabled campuses that share a schoolCode are logged. They are not skipped.
pullCampus asks SchoolPay for three Africa/Kampala dates: today, yesterday, and two days ago. returnCode !== 0 counts as a failed day and stores nothing from that response. transactions are ingested as SCHOOL_FEES. supplementaryFeePayments are ingested as OTHER_FEES. The stored source is sync. Webhook rows use webhook.
Inbox
Prefix GET and POST under /api/v1/ledger/school-pay. Class SchoolPayInboxController. Bearer auth. Each handler requires create on ledger and calls assertCanAccess with the campus id (the query campus for list, the row’s campus for assign and ignore).
| Method and path | operationId | Body or query | Success | Errors from the service |
|---|---|---|---|---|
GET /inbox | listSchoolPayInbox | SchoolPayInboxQueryDto: required campusId (UUID), optional status (matched, unmatched, ignored), plus cursor pagination | SchoolPayInboxListResponseDto. Sort is paidAt descending, then the cursor sort. Each item is SchoolPayInboundDto (no rawPayload, no schoolId) | Permission failures from the guard and assertCanAccess. This method does not throw its own NotFoundException |
POST /inbox/:id/assign | assignSchoolPayInbound | UUID id. Body AssignSchoolPayInboundDto: studentId (UUID), saveCode (boolean) | TransactionDto from TransactionService.findById | 404 SchoolPay inbound row not found. 404 Student not found. 409 Row is not unmatched. 400 Student is not on the same campus as this payment. 409 That SchoolPay code already belongs to another student in this campus when saveCode hits STUDENT_SCHOOL_PAY_CODE_UNIQUE. 409 This payment was already handled. Booking conflicts above |
POST /inbox/:id/ignore | ignoreSchoolPayInbound | UUID id. Body ReasonDto: reason string, length 3 to 500 | SchoolPayInboundDto | 404 SchoolPay inbound row not found. 409 Row is not unmatched. 409 This payment was already handled |
saveCode: true writes schoolPayCode on that student before the row is claimed. Ignore stores ignoredReason and books nothing. The row stays listable.
Statuses on the row are matched, unmatched, and ignored.
Sources
Naalya-API a5dff0c208d5193c274d3d1f87787b55344d5d30: apps/server/src/app/ledger/school-pay-inbound.controller.ts, school-pay-inbound.service.ts (verifySignature, ingestWebhook, validateRow, pullCampus, assign, ignore), school-pay-inbox.controller.ts, dto/school-pay-inbound.dto.ts, dto/school-pay-inbound.types.ts, dto/reverse-payment.dto.ts ReasonDto, libs/shared/src/cron/cron.constants.ts CronJob.SyncSchoolPayTransactions, libs/shared/src/config/env.config.ts CRON_SYNC_SCHOOL_PAY, apps/worker/src/cron/cron.registrar.ts, apps/worker/src/cron/cron.processor.ts (the SchoolPay case), apps/worker/src/processors/ledger/ledger.processor.ts (the SYNC_SCHOOL_PAY case). None of these handlers were called.