Logo Lanfrica

tanlio/mpesa-api-go

Domain:

digital infrastructure

Record type:

software
Creator:
tan
Host:
# MPESA Golang API Wrapper The wrapper provides convenient access to the Safaricom MPESA Daraja API for applications written in server-side Golang. :rocket: ## Installing You can install the package by running: ``` go get github.com ``` ## Usage The package needs to be configured with your **appKey** and **appSecret** which can be obtained from Safaricom. ``` const ( appKey = "YOUR_APP_KEY" appSecret = "YOUR_APP_SECRET" ) ``` The following examples with show you how to make requests to the various api's available. ### MPESAExpress (Formerly STKPush) This api allows you to do Lipa Na M-Pesa payment using STK Push. This is a simple example: ```go package main import ( "log" "github.com" ) const ( appKey = "" appSecret = "" ) func main() { svc, err := mpesa.New(appKey, appSecret, mpesa.SANDBOX) if err != nil { panic(err) } res, err := svc.Simulation(mpesa.Express{ BusinessShortCode: "", Password: "", Timestamp: "", TransactionType: "", Amount: 0, PartyA: "", PartyB: "", PhoneNumber: "", CallBackURL: "", AccountReference: "", TransactionDesc: "", }) if err != nil { log.Println(err) } log.Println(res) } ``` ### C2B This api allows you to register C2B Callback URLs to Safaricom, and also Simulate a C2B Transaction in ```Sandbox``` This is a simple demo to show how to register C2B Callback URL: ```go package main import ( "log" "github.com" ) const ( appKey = "" appSecret = "" ) func main() { svc, err := mpesa.New(appKey, appSecret, mpesa.SANDBOX) if err != nil { panic(err) } res, err := svc.C2BRegisterURL(mpesa.C2BRegisterURL{ ShortCode: "", ResponseType: "", ConfirmationURL: "", ValidationURL: "", }) if err != nil { log.Println(err) } log.Println(res) } ``` To simulate a C2B Request, use this simple example: ```go package main import ( "log" "github.com" ) const ( appKey = "" a …

Languages

Licenses