Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thecollinsbyte/mobile-payments-library

The mobile-payment-library repository is a versatile Java-based toolkit engineered for payment integrations across both mobile applications and server-side environments.
https://github.com/thecollinsbyte/mobile-payments-library

airtel-money azampay ezypesa halopesa java java-library mpesa payments selcom t-pesa tigo-pesa

Last synced: about 1 month ago
JSON representation

The mobile-payment-library repository is a versatile Java-based toolkit engineered for payment integrations across both mobile applications and server-side environments.

Awesome Lists containing this project

README

        

Mobile Payment Library


License


People


Stars


Forks


Watches


Last Updated

## Description

This is open-source mobile payment library with support for M-Pesa, Tigo Pesa, Airtel Money and Halopesa. It provides a simple and intuitive API for integrating mobile payments into your applications.

- [Installation](#installation)
- [Features](#features)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)

## Features
- Easy integration with Vodacom (M-Pesa), Tigo (Tigo Pesa), Airtel (Airtel Money), PesaPal, SelcomPay, AzamPay and Halotel (HaloPesa)
- Support to various payment methods
- Extensible for other mobile payment providers
- Detailed error handling and logging

## Installation

### Gradle

Add the following dependency to your `build.gradle` file:

```groovy
dependencies {
implementation 'com.kwawingu:mobile-payment:1.0.0'
}
```

### Maven

Add the following dependency to your `pom.xml` file:

```xml

com.kwawingu
mobile-payment
1.0.0

```

## Usage

### Initialization

First, initialize the library with your M-Pesa credentials from environment variables.

```java
MpesaKeyProviderFromEnvironment.Config config =
new MpesaKeyProviderFromEnvironment.Config.Builder()
.setApiKeyEnvName("MPESA_API_KEY")
.setPublicKeyEnvName("MPESA_PUBLIC_KEY")
.build();
mpesaSessionKeyGenerator = new SessionKeyGenerator();
apiEndpoint = new ApiEndpoint(Environment.SANDBOX, Market.VODACOM_TANZANIA);
keyProvider = new MpesaKeyProviderFromEnvironment(config);
```

This configuration sets up the MpesaKeyProviderFromEnvironment to retrieve the API key and public key from the specified environment variables. The SessionKeyGenerator and ApiEndpoint are also initialized for generating session keys and defining the API endpoint, respectively.

### Customer To Business (C2B)

The C2B API call is used as a standard customer-to-business transaction. Funds from the customer’s mobile money wallet will be deducted and be transferred to the mobile money wallet of the business. To authenticate and authorize this transaction, M-Pesa Payments Gateway will initiate a USSD Push message to the customer to gather and verify the mobile money PIN number. This number is not stored and is used only to authorize the transaction.

```java
Payload customerToBusinessPayload =
new Payload.Builder()
.setAmount("10.00")
.setCustomerMSISDN("+255-762-578-467")
.setCountry(Market.VODACOM_TANZANIA.getInputCountryValue())
.setCurrency(Market.VODACOM_TANZANIA.getInputCurrencyValue())
.setServiceProviderCode("ORG001")
.setTransactionReference("T12344C")
.setThirdPartyConversationID("1e9b774d1da34af78412a498cbc28f5e")
.setPurchasedItemsDesc("Lenovo ThinkPad X1 Carbon Gen 12")
.build();

CustomerToBusinessTransaction customerToBusinessTransaction =
new CustomerToBusinessTransaction.Builder()
.setApiEndpoint(new ApiEndpoint(Environment.SANDBOX, Market.VODACOM_TANZANIA))
.setEncryptedSessionKey(session.getEncryptedSessionKey())
.setPayload(customerToBusinessPayload)
.build();
```

## Contributing

Contributions are welcome! Please read the [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to contribute to this project.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.



⭐ hit the star button if you found this useful ⭐

Source
| Twitter
| LinkedIn
| Email