Menu

M-pesa STK Push in Go: From Sandbox Credentials to a Working Payment Callback
📰

M-pesa STK Push in Go: From Sandbox Credentials to a Working Payment Callback

DEV Community: beginners·Ryan Kelly·about 5 hours ago
#P1ORWoWp
#devtobeginners#devto#dev#string#json
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.