Logo Lanfrica

vgichira/mpesa-wrapper

Domaine:

digital infrastructure

Type de record:

software
Créateur:
vgi
Hôte:
This is an Mpesa Daraja API wrapper # Safaricom Mpesa Golang SDK This is an unofficial Mpesa Daraja API wrapper. You can easily install and reuse this package in you Go projects. This allows you to focus on the business logic by leaving the Mpesa APIs heavylifting. ## Installation This documentation assumes that you already have Go installed on your device. If you have not installed Go, check out the documentation on how to install it on your computer. ``` go get github.com ``` ## Initialize instance of the gateway To start using the SDK, we first need to create a new instance of the service with the daraja app credentials and the environment. Environment is either SANDBOX or PRODUCTION. Default environment is SANDBOX. ```go mpesaService, err := mpesa.Init("CONSUMER_KEY_HERE", "CONSUMER_SECRET_HERE", "ENVIROMENT (SANDBOX / LIVE)") ``` ## Generate Lipa Na Mpesa (STK Push Password When sending an STK Push request to a client phone number, one of the parameters required if the password. The password is generated by Base64 encoding the shortcode, LNM passkey and the timestamp (YYYYMMDDHHMMSS). ```yaml { "BusinessShortCode": "", "Password": "", // This password "Timestamp": "", "TransactionType": "", "Amount": "", "PartyA": "", "PartyB": "", "PhoneNumber": "", "CallBackURL": "" "AccountReference": "", "TransactionDesc": "" , } ``` To generate the password, you need to call the ***GenerateLipaNaMpesaPassword*** method from the SDK and pass ***shortcode***, ***passkey*** and the ***timestamp*** as parameters. ```go password := mpesaService.GenerateLipaNaMpesaPassword("SHORTCODE", "PASSKEY", "TIMESTAMP") ``` ## Send Lipa Na Mpesa (STK Push) Request To send STK Push to client's phone number, you need to call the ***LipaNaMpesaOnline*** method and pass the payload as a parameter. ```go requestBody := &mpesa.LipaNaMpesaRequest { BusinessShortCode: "", Password: "", Timestamp: "", TransactionType: "", Amount: "", PartyA: "", PartyB: "", PhoneNumber: "", CallBackURL: "", AccountRefe …

Languages