The ultimate version of mpesa golang sdk.
# `mpesagosdk`: The Best M-Pesa SDK for Golang
`mpesagosdk` is a Go SDK for interacting with Safaricom's M-Pesa API. This SDK simplifies integration with M-Pesa's services, enabling operations such as B2C payments, C2B URL registration, USSD Push payments, transaction status queries, account balance checks, and transaction reversals.
## Documentation
For further detailed documentation and api keys you can access it here.
## Features
- **B2C Payments**: Transfer funds from a business account to a customer account.
- **C2B URL Registration**: Register URLs for payment notifications.
- **USSD Push**: Initiate USSD-based payment requests.
- **Transaction Status**: Query the status of transactions.
- **Account Balance**: Retrieve M-Pesa account balances.
- **Transaction Reversal**: Reverse a completed M-Pesa transaction.
## Table of Contents
- Installation
- Quick Start
- Examples
- Register C2B URL
- Simulate C2B Payment
- Make B2C Payment
- Transaction Status Query
- Account Balance Query
- Transaction Reversal
- USSD Push Payment
- Contributing
- License
## Installation
To install the SDK, use the following command:
```bash
go get
github.com
```
## Quick Start
### Initialize the MpesaClient
```go
package main
import (
"fmt"
"log"
"
github.com"
"
github.com"
)
func main() {
// Load configuration from environment variables
cfg, err := config.NewFromEnv()
if err != nil {
log.Fatal(err.Error())
}
// Create a new Mpesa client
app := mpesagosdk.New(cfg)
fmt.Println("Application is created with: ", *app)
}
```
## Configuration
To configure this application you can either create the config struct by yourself or you can create .env file
this package depends on joho/godotenv/autoload package this will load the .env
to the program.
Simple .env looks like this
```bash
# Required credentials
CONSUMER_SECRET=your_consumer_secret_here
CONSUMER_KEY=your_consumer_key_here
# Optional settings with defa …