postWithIntercept function

Future postWithIntercept(
  1. String endpoint, {
  2. Map<String, dynamic>? body,
  3. Map<String, String>? headers,
  4. Duration timeoutDuration = const Duration(seconds: 60),
})

Implementation

Future<dynamic> postWithIntercept(String endpoint,
    {Map<String, dynamic>? body,
    Map<String, String>? headers,
    Duration timeoutDuration = const Duration(seconds: 60)}) async {
  await initBinoxusPayEnvs();

  final baseUrl = binoxusPayEnvSingleton.baseUrl;
  final url = Uri.parse("$baseUrl$endpoint");

  try {
    final response = await httpClient.post(url, body: body, headers: headers);

    if (response.statusCode == 200 || response.statusCode == 201) {
      return jsonDecode(response.body);
      // IBinoxusPayRepnose.fromJson(response.body as dynamic);
    } else {
      throw Exception('Error : ${response.statusCode}');
    }
  } on HttpException catch (e) {
    throw Exception('Request failed: ${e.message}');
  }
}