Golang SDK for seamless integration with Safaricom's Daraja API.
# Daraja Golang SDK
The SDK provides fast, secure and easy integration for Safaricom MPESA Daraja API for golang applications.
## Installing
You can install the package by running:
```
go get
github.com
```
## Technology
1. Golang v 1.17 or higher
2.
github.com - For caching of authentication token
3. Backoff retry strategy for calling api calls that needs retrys.
## Getting started
Obtain mpesaApiKey, mpesaConsumerSecret, mpesaPassKey from Safaricom MPESA Daraja API. Also generate credentials either for sandbox or production.
```
const (
// Sandbox or production credentials. Note store sucurely as environment vartiables
mpesaApiKey = "CAmGHG070hAlXgGkbA3CZDQEEXapvmmT"
mpesaConsumerSecret = "PJ7Wet8fMBLu42Xw"
mpesaPassKey = "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919"
securityCredential = "JSAxBuZk0KAtro5vbdMyvn5aUYQ0uGN1RY=="
)
```
Then declare service for either production or sandbox
```
darajaService, err := daraja.New(mpesaApiKey, mpesaConsumerSecret, mpesaPassKey, daraja.SANDBOX)
if err != nil {
log.Println("failed initializing safaricom daraja client ", err)
}
```
### Network Initiated/Mpesa Express (STKPush)
This api initiates payment prompt on customer sim tool kit.
```go
package main
import (
"log"
"
github.com"
)
const (
mpesaApiKey = "CAmGHG070hAlXgGkbA3CZDQEEXapvmmT"
mpesaConsumerSecret = "PJ7Wet8fMBLu42Xw"
mpesaPassKey = "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919"
)
func main() {
darajaService, err := daraja.New(mpesaApiKey, mpesaConsumerSecret, mpesaPassKey, daraja.SANDBOX)
if err != nil {
log.Println("failed initializing safaricom daraja client ", err)
}
stkRes, err := darajaService.InitiateStkPush(daraja.STKPushBody{
BusinessShortCode: "174379",
TransactionType: "CustomerBuyGoodsOnline",
Amount: "1",
PartyA: "254728922469",
PartyB: "174379", …