Package io.github.openpaydev.mpesa.core
Class MpesaConfig
java.lang.Object
io.github.openpaydev.mpesa.core.MpesaConfig
Configuration object for the Mpesa API client.
This class holds all the necessary credentials and settings required to interact with the Mpesa API. It is immutable and should be created once and reused throughout your application.
An instance can be created using the builder pattern or from environment variables.
Example using the builder:
MpesaConfig config = MpesaConfig.builder()
.consumerKey("your_key")
.consumerSecret("your_secret")
.businessShortCode("174379")
.passKey("your_passkey")
.environment(MpesaEnvironment.SANDBOX)
.build();
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionMpesaConfig(String consumerKey, String consumerSecret, String businessShortCode, String passKey, MpesaEnvironment environment) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()static MpesaConfigfromEnv()Creates aMpesaConfiginstance by reading credentials from environment variables.The Business Short Code, which is the identifier for your PayBill or Till Number.The Consumer Key obtained from the Safaricom Developer Portal.The Consumer Secret obtained from the Safaricom Developer Portal.The Mpesa environment to use, eitherMpesaEnvironment.SANDBOXorMpesaEnvironment.PRODUCTION.The Lipa Na M-Pesa Pass Key, used to encrypt the password for STK Push requests.
-
Constructor Details
-
MpesaConfig
public MpesaConfig(String consumerKey, String consumerSecret, String businessShortCode, String passKey, MpesaEnvironment environment)
-
-
Method Details
-
fromEnv
Creates aMpesaConfiginstance by reading credentials from environment variables.This is the recommended way to configure the SDK in a production environment. It uses
System.getenv()as the source for the variables.- Returns:
- A new
MpesaConfiginstance.
-
builder
-
getConsumerKey
The Consumer Key obtained from the Safaricom Developer Portal. -
getConsumerSecret
The Consumer Secret obtained from the Safaricom Developer Portal. -
getBusinessShortCode
The Business Short Code, which is the identifier for your PayBill or Till Number. Renamed from 'shortCode' to align with the official M-Pesa API documentation. -
getPassKey
The Lipa Na M-Pesa Pass Key, used to encrypt the password for STK Push requests. -
getEnvironment
The Mpesa environment to use, eitherMpesaEnvironment.SANDBOXorMpesaEnvironment.PRODUCTION.
-