getSession method
Get session
Implementation
Future<String?> getSession({String? sessionId}) async {
if (sessionId != null) return sessionId;
apiContext = APIContext(headers: {}, parameters: {})
..setPublicKey(publicKey)
..setApiKey(apiKey)
..setSSL(true)
..setMethodType(APIMethodType.GET)
..setAddress("openapi.m-pesa.com")
..setPort(443)
..setPath("/${env.name}/ipg/v2/${market.name}/getSession/");
apiContext.addHeader("Origin", "*");
req = APIRequest(apiContext);
// apiContext.addHeader("Origin", "*");
// Do the API call and put result in a response packet
// APIResponse? response;
try {
response = await req.execute();
sessionId = response?.getBody()["output_SessionID"];
return sessionId;
} on DioError catch (e) {
throw Exception(e.message);
}
}