Package io.github.openpaydev.mpesa.auth
Class MpesaTokenManager
java.lang.Object
io.github.openpaydev.mpesa.auth.MpesaTokenManager
- All Implemented Interfaces:
TokenManager
Concrete implementation of the
TokenManager interface. It retrieves and caches the M-Pesa
OAuth access token using OkHttp. This class is thread-safe.-
Constructor Summary
ConstructorsConstructorDescriptionMpesaTokenManager(MpesaConfig config, okhttp3.OkHttpClient client) The primary public constructor for the SDK. -
Method Summary
Modifier and TypeMethodDescriptionReturns a valid access token, fetching a new one if necessary.
-
Constructor Details
-
MpesaTokenManager
The primary public constructor for the SDK. It uses the default system clock.- Parameters:
config- The M-Pesa configuration object.client- The OkHttpClient for making requests.
-
-
Method Details
-
getAccessToken
Description copied from interface:TokenManagerReturns a valid access token, fetching a new one if necessary.- Specified by:
getAccessTokenin interfaceTokenManager- Returns:
- A valid OAuth access token string.
- Throws:
MpesaAuthException- If an error occurs during the fetch.
-