Yet another Golang daraja api client library (WIP).
Work Done
Lipa Na Mpesa Api / Express.
C2B Regsiter URL & Simulate Payment Api
B2B Api
B2C Api
Transaction Api
Balance Query APi
Reversal Api
Parsers for the callback responses(stk callback parser done)
Installation
go get github.com/jakhax/go_daraja
APIs
This section contain code examples for different apis in daraja
Note this is not a daraja documentation, refer to references in every section below for detailed documentations.
Creating the Mpesa Service
package main;
import(
"fmt""log""github.com/jakhax/go_daraja/mpesa"
)
//MpesaConfig configvarMpesaConfig=&mpesa.Config{
//'sandbox' / 'production' , you can use built in consts like belowEnvironment:mpesa.SandBox,
ConsumerKey:"CONSUMER KEY",
ConsumerSecret:"CONSUMER SECRET",
}
mpesaService, err:=mpesa.NewMpesa(config)
funcc2BRegisterURLExample()(errerror){
mpesaService, err:=mpesa.NewMpesa(MpesaConfig)
iferr!=nil{
return
}
registerURL:=&mpesa.RegisterURLs{
ValidationURL:"https://callback.com/validation",
ConfirmationURL:"https://callback.com/confirmation",
ShortCode:"123456",
// Cancelled/Completed , you can use built in const like belowResponseType:mpesa.CompletedResponseType,
}
res,err:=mpesaService.RegisterURLs(registerURL)
iferr!=nil{
return
}
fmt.Println(res.ResponseDescription)
return
}