Package io.github.openpaydev.mpesa
Class MpesaClient
java.lang.Object
io.github.openpaydev.mpesa.MpesaClient
- All Implemented Interfaces:
C2bService,StkPushService
The main client for interacting with the Safaricom M-Pesa API. This class implements the
StkPushService and C2bService interfaces.-
Constructor Summary
ConstructorsConstructorDescriptionMpesaClient(MpesaConfig config, TokenManager tokenManager, okhttp3.OkHttpClient client) -
Method Summary
Modifier and TypeMethodDescriptionqueryStkStatus(String checkoutRequestID) Queries the status of an STK Push transaction.registerC2bUrl(C2bRegisterUrlRequest userRequest) ADD THIS NEW METHOD IMPLEMENTATIONstkPush(StkPushRequest userRequest) Initiates an M-Pesa STK Push request.
-
Constructor Details
-
MpesaClient
-
-
Method Details
-
stkPush
Description copied from interface:StkPushServiceInitiates an M-Pesa STK Push request.- Specified by:
stkPushin interfaceStkPushService- Parameters:
userRequest- The STK Push request object.- Returns:
- The initial synchronous response from the API.
- Throws:
MpesaException- If a network or API error occurs.
-
queryStkStatus
Description copied from interface:StkPushServiceQueries the status of an STK Push transaction.- Specified by:
queryStkStatusin interfaceStkPushService- Parameters:
checkoutRequestID- The unique ID of the transaction to query.- Returns:
- The response containing the transaction status details.
- Throws:
MpesaException- If a network or API error occurs.
-
registerC2bUrl
public C2bRegisterUrlResponse registerC2bUrl(C2bRegisterUrlRequest userRequest) throws MpesaException ADD THIS NEW METHOD IMPLEMENTATION- Specified by:
registerC2bUrlin interfaceC2bService- Parameters:
userRequest- The C2B registration request object.- Returns:
- The response confirming the registration.
- Throws:
MpesaException- If a network or API error occurs.
-