I'm learning Go by building a real product: ElimuLocal , a free study-resource platform for Kenyan university students. Once it was solid, I wanted a premium tier, and in Kenya that means one thing: M-Pesa. This article walks through how I integrated Safaricom's Daraja STK Push in Go, what broke, and what I'd do differently.
1. The flow at a glance
STK Push means your server asks Safaricom to pop up a PIN prompt on the customer's phone. Four parties are involved:
Customer phone Your Go server Daraja / Safaricom | | | | taps "Pay" | | |-------------------->| 1. OAuth token | | |------------------------->| | | 2. STK Push request | | |------------------------->| | PIN prompt |<-- 3. "accepted" + ID ---| |<---------------------------------------------- | | enters PIN | | |--------------------------------------------> | | | 4. Callback (result) | | |<-------------------------| | | 5.…