## Mpesa Java SDK
A Java library for communicating with Mpesa Daraja rest API.
> The SDK provides convenient access to the Mpesa Daraja API from applications written in Java.
## Install
### Maven
Use the following dependency in your project to grab via Maven:
```
com.github.corneliouzbett
mpesa-sdk
1.1
pom
```
### Gradle
For android developers you can install the library by adding dependency to build.gradle
```
implementation 'com.github.corneliouzbett:mpesa-sdk:1.1'
```
### Gradle for Kotlin
For kotlin developers
```
implementation("com.github.corneliouzbett:mpesa-sdk:1.1")
```
### Scala SBT
For developers using scala
```
libraryDependencies += "com.github.corneliouzbett" % "mpesa-sdk" % "1.1"
```
###
## Usage
The SDK needs to be initialized with your consumer key and consumer secret, which you get from the safaricom developers portal. You are required to create an app.
>You can use this SDK for either production or sandbox apps.
### Initialize the client
```java
String consumerKey = "AXXXX-XXXX"; //consumer key
String consumerSecret = "WEDX-XXXX-XXX-XXX"; //consumer secret
Mpesa mpesa = new MpesaClient(consumerKey, consumerSecret); // initializing mpesa client
```
### Authentication
Authenticate mpesa client and genarate accessToken used to access authorized resources (services) e.g C2B, B2C, MExpress, AccountBalance etc
```java
mpesa.authenticate().getAccessToken().enqueue(new Callback<>() {
@Override
public void onResponse(Call call, Response response) {
if (response.isSuccessful()) {
String accessToken = response.body().getAccessToken();
}
}
@Override
public void onFailure(Call call, Throwable throwable) {
throw new MpesaException("Unable to authenticate Mpesa client", throwable);
}
});
```
### Account Balance
This API entrypoint requests for the account balance of a shortcode (Till number).
```java
AccountBalance balance = new AccountBalance();
balance.setCommandId("");
balance.setInitiator("");
balance.setIdentifierType("");
balance.setPa …