Logo Lanfrica

jakhax/go_daraja

Domaine:

digital infrastructure

Type de record:

software
Créateur:
jak
Hôte:
safaricom mpesa api(daraja) client for go # Go Daraja Api Client ## Description - Yet another Golang daraja api client library **(WIP)**. ## Work Done - [x] Lipa Na Mpesa Api / Express. - [x] C2B Regsiter URL & Simulate Payment Api - [ ] B2B Api - [x] B2C Api - [x] Transaction Api - [x] Balance Query APi - [x] Reversal Api - [ ] Parsers for the callback responses(stk callback parser done) ## Installation ```bash go get github.com ``` ## 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 ```go package main; import( "fmt" "log" "github.com" ) //MpesaConfig config var MpesaConfig = &mpesa.Config{ //'sandbox' / 'production' , you can use built in consts like below Environment:mpesa.SandBox, ConsumerKey:"CONSUMER KEY", ConsumerSecret:"CONSUMER SECRET", } mpesaService, err := mpesa.NewMpesa(config) ``` ### Express / LNM API #### LNM STK Push - To send an STK push to a customer phone ```go func sTKPushExample()(err error){ mpesaService, err := mpesa.NewMpesa(MpesaConfig) if err != nil{ return } express := &mpesa.Express{ ShortCode:"174379", Password:"LNM Password", Amount:1, PhoneNumber:"0712345678", CallBackURL:"callback.com", } stkRes, err := mpesaService.STKPush(express) if err != nil{ return } fmt.Println(stkRes.ResponseDescription) return } func main(){ err := sTKPushExample() if err != nil{ log.Fatal(err) } } ``` - `mpesaService.STKPush` returns `STKPushRes` which is a pointer to struct containing the api response. For more information refer to the source. ##### Resources - Official API Documentation - API quickstart - SafDaraja Blog #### LNM Transaction Status - Get the transaction status of an lipa na mpesa stk push ```go func lnmTransactionStatusExample()(err error){ mpesaService, err := mpesa.NewMpesa(MpesaConfig) if err != nil{ return } res, err := mpesaService.ExpressTransactionSt …