Java SDK for Mpesa payment API
# Java M-Pesa Payment SDK
This project integrates with the **Mpesa API**, providing functionality to trigger payments, validate them, register payment notification URLs, and handle USSD push requests and other requests.
## Live Documentation
🔗 mpesa-java-docs-et.vercel.app/
## 🚀 Features
### 🔒 Authentication
- Secure and fullly manged authentication and access token mangement.
### 📦 Data Models for Request
- Predefined, ready to use data models like `UssdPushRequest`, `RegisterUrlRequest`, `C2BPaymentValidationRequest` and more.
### ⚙️ Async and Sync API Client
- Supports both **synchronous** and **asynchronous** API calls for optimal performance.
### 💻 Custom HTTP Client
- Customizable http `Client` for making HTTP requests to the M-Pesa API.
### 🛡️ Validation
- Automatic validation for request integrity and error handling.
### 🧪 Testing
- Includes tests using **MockWebServer** for simulating API responses and also contain for actual integration tests.
## 🔧 Requirements
- Java 11 or higher.
- Maven for dependency management.
- Mpesa API credentials (consumer key, consumer secret).
## 🛠️ Installation
To integrate Mpesa Payment API into your project, follow these steps:
1. **Clone the repository**:
```bash
git clone
github.com
cd mpesa-sdk
```
2. **Install dependencies**:
For Maven:
```bash
mvn install -Dgroups=mocked # This runs only mock tests then install locally
```
## ⚡ Usage Examples
### Maven
```xml
io.github.dere7
mpesa-sdk
1.1
```
### Example 1: Trigger USSD Push Request (Without Configuration)
```java
// Create Mpesa instance without configuration
Mpesa mpesa = new Mpesa("test_consumer_key", "test_consumer_secret");
UssdPushRequest request = UssdPushRequest.builder()
.merchantRequestId("4354354351")
.businessShortCode("174379")
.passkey("passkey")
.transactionType("CustomerPayBillOnline")
.amount("10000")
.partyA("600982")
.partyB("600000")
.phoneNumber("251708374149")
.transactionDesc("Monthly Unlimi …