createCallbackHandler
createCallbackHandler(
options):HttpHandler
Defined in: src/callbacks/receiver.ts:106
Create an HTTP request handler that receives Daraja callbacks, parses the body, and calls your typed handler. Use with Node’s http.createServer(handler) or mount in your framework.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”HttpHandler
Example
Section titled “Example”const handler = createCallbackHandler({ routes: { "/mpesa/stk": { parse: parseStkPushCallback, handler: async (payload) => { if (payload.ResultCode === 0) { const meta = getStkMetadata(payload); if (meta) console.log(meta.mpesaReceiptNumber, meta.amount); } }, }, "/mpesa/c2b/confirm": { parse: parseC2BConfirmation, handler: (p) => console.log(p.TransID, p.TransAmount), }, },});import { createServer } from "node:http";createServer(handler).listen(3000);