01 · The problem
The UI was the easy part. Trust was the product.
A campus marketplace can look deceptively simple: show products, add a cart, accept payment. That model stops being useful the moment one payment contains products from multiple sellers, stock can change while the buyer is paying, and each seller eventually needs a payout.
I treated the financial lifecycle as a state machine rather than a collection of payment buttons. The server recomputes what should be paid, verifies the Paystack reference, currency and amount, then validates aggregate demand against the current physical stock pools before any seller order is created.
- Repeated items that target the same product, variant or shared stock pool are aggregated before availability is checked.
- An insufficient-stock failure rolls the whole fulfillment transaction back instead of clamping inventory to zero.
- A duplicate callback for an already fulfilled payment is safe: it does not decrement inventory twice.