TypeScriptStable
Smart City Financial Module
The wallet and payment part of a smart city platform built by a 50+ student class at KMUTT. City services like the metro and insurance cards are paid from it.
Result
Students could top up a wallet with a real PromptPay QR code from SCB and pay city services from it. The module has 32 API endpoints, and I wrote most of the wallet and SCB code (24 of 27 wallet commits and 22 of 23 SCB commits).
Built with
- TypeScript
- Hono
- Prisma
- PostgreSQL
- React
- Swagger / OpenAPI
- Zod
- Pusher Channels
- SCB API
The problem
Every service in the class platform needed one way to hold and move money: wallets, top-ups, transfers between users, and real bank payments. Two transfers at the same time must not corrupt a balance, and a user must never exist without a wallet.
What I built
Led the 3-person financial team. I built the wallet and top-up flow, user-to-user transfers, and the SCB bank integration on the backend, and the financial page, top-up page with QR payment, transaction history, and transfer screen on the frontend. Teammates built the metro and insurance card parts.
How it works
- SCB integration: OAuth tokens are cached until they expire, payment data is encrypted with the SCB public key, and top-ups create a PromptPay QR code (QR v1, because v2 was under maintenance).
- Metro card top-ups charge the card owner's wallet. Donations take a 3% fee.
- Payment status first reached the browser through Server-Sent Events. I later moved it to Pusher Channels.
- Every endpoint is described with zod-openapi, so the Swagger docs and the frontend's generated API client come from the same schema.
Key decisions
- 01
Atomic balance changes
Prisma increment and decrement instead of read then write, so two transfers at the same time cannot overwrite each other.
- 02
User and wallet in one transaction
Creating a user and their wallet runs in one Prisma transaction, so there is never a user without a wallet.
- 03
One wallet per user
The service refuses a second wallet for the same user, and a transfer checks that the wallet is active first.
By the numbers
- 83 backend commits and 38 frontend commits from me between October and December 2025.
- About 2,700 lines added to the backend module and about 3,000 to the frontend.
The hard part
The SCB API, especially the debit card integration and PromptPay. I had to read through their developer docs, learn the whole API, and write a lot of tests just to understand the flow from 0 to 100. Getting proper credentials set up was tricky too, since their API needs the data properly encrypted and decrypted.
