Skip to content

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

License

Notifications You must be signed in to change notification settings

TheCollinsByte/Mobile-Payments-Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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:

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

Maven

Add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.kwawingu</groupId>
    <artifactId>mobile-payment</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

Initialization

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

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.

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 for guidelines on how to contribute to this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.



⭐ hit the star button if you found this useful ⭐

Source | Twitter | LinkedIn | Email

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published