External Gateways
External Gateway Integrations & Telephony Services
Gateway Integration Matrix
This document formalizes the production integration architectures for third-party endpoints: Safaricom M-Pesa (Daraja), Social Health Authority (SHA), and localized SMS gateway aggregators.
1. Safaricom M-Pesa Daraja C2B/B2C API Integration
The financial engine implements direct automated hooks into Safaricom’s Daraja API to provide zero-touch collection reconciliation via Lipa Na M-Pesa Paybill / STK Push services.
1.1 Secure Authorization Lifecycle
Daraja APIs require an OAuth2 bearer token refreshed every 3,599 seconds. The system executes this handshake via a background task engine and caches the active token inside Redis.
1.2 STK Push (M-Pesa Express) Payload Schema
When an agent clicks "Trigger Mobile Payment" at any billing terminal, the HMIS issues a synchronous loopback request to the stkpush/v1/processrequest endpoint:
2. Social Health Authority (SHA) Portal Handshaking
Under the Digital Health Act (2023), integration with SHA (enclosing SHIF, PHF, and emergency structures) requires biometric token assertions paired alongside structured claims packets.
2.1 Complete Claim Pipeline Flow
2.2 SHA Biometric Assertions
The local fingerprint readers transmit a hashed ISO/IEC 19794-2 template string client-side. The HMIS maps this assertion directly to the authorization payload block:
3. Localized SMS Telephony Gateways
Patient engagement loops (e.g., triage prioritization summaries, diagnostic clearance flags, chronic disease clinic recalls) utilize multi-carrier SMS notification engines via localized SMPP/REST aggregators (such as Africa's Talking or Safaricom Bulk SMS channels).
3.1 Non-Blocking Task-Driven Message Dispatch
To ensure that slow external telecommunication lines never bottleneck clinical or financial screens, all outbound messages are offloaded to asynchronous background jobs.
4. Error Tolerances, Circuit Breaking, and Offline Queues
Third-party external web connections can drop frequently. The HMIS handles these failures using a Circuit Breaker pattern managed in memory via Redis.
- M-Pesa STK Callback Failure Fallback: If Safaricom's callback notification fails to reach the facility due to an external fiber line drop, the billing terminal initiates an on-demand transaction status pull task checking payment states manually: POST /mpesa/stkpushquery/v1/query.
- SHA Queue Backup Strategy: When the National Data Highway endpoint enters an offline or maintenance state, signed financial files are safely retained in local database tables labeled pending_offline_sha_claims, waiting to be automatically dispatched during a midnight reconciliation task once connections are restored.
Document Verification Block
Author: Ian Wataka - Backend DeveloperTarget Scope: External API Routing Handshakes & Task Architecture