# M-Pesa SDK for JAVA
M-Pesa SDK for JAVA is an unofficial library aiming to help develbusinesses integrating every M-Pesa operations to their JAVA applications.
## Features
- Receive money from a mobile account to a business account
- Send money from a business account to a mobile account
- Send money from a business account to a another business account
- Revert a transaction
- Query the status of a transaction
## Usage
### Receive Money from a Mobile Account
```java
import org.paymentsds.mpesa.Callback;
import org.paymentsds.mpesa.Client;
import org.paymentsds.mpesa.Environment;
import org.paymentsds.mpesa.Request;
import org.paymentsds.mpesa.Response;
Client client = new Client.Builder()
.apiKey(" ")
.publicKey(" ")
.serviceProviderCode(" ")
.initiatorIdentifier(" ")
.environment(Environment.PRODUCTION)
.host("
vm.co.mz")
.build();
Request paymentRequest = new Request.Builder()
.amount(10.0)
.from("841234567")
.reference("12345")
.transaction("12345")
.build();
// Synchronous Call
try {
Response response = client.receive(paymentRequest);
// Handle success scenario
} catch (Exception e) {
// Handle failure scenario
}
// Asynchronous Call
client.receive(paymentRequest, new Callback() {
@Override
public void onResponse(Response response) {
// Handle success scenario
}
@Override
public void onError(Exception e) {
// Handle failure scenario
}
});
```
### Send Money to a Mobile Account
```java
import org.paymentsds.mpesa.Callback;
import org.paymentsds.mpesa.Client;
import org.paymentsds.mpesa.Environment;
import org.paymentsds.mpesa.Request;
import org.paymentsds.mpesa.Response;
Client client = new Client.Builder()
.apiKey(" ")
.publicKey(" ")
.serviceProviderCode(" ")
.initiatorIdentifier(" ")
.environment(Environment.PRODUCTION)
.host("
vm.co.mz")
.build();
Request paymentIntent = new Request.Builder()
.amount(10.0)
.to("841234567")
.reference("12345")
.transaction("12345")
.build();
// Synchronous Call
try {
Response response = client …