postPaymentData static method

Future<Response?> postPaymentData(
  1. String mainUrl,
  2. String endpoint,
  3. String token, {
  4. required dynamic data,
})

Post method with a timeout of 2 minutes.

Implementation

static Future<http.Response?> postPaymentData(
    String mainUrl, String endpoint, String token,
    {required var data}) async {
  Uri url = Uri.https(mainUrl, endpoint);
  var body = jsonEncode(data);

  if (kDebugMode) {
    print('URL: $url');
    print('Post data: $body');
  }
  String basicAuth = 'Bearer $token';
  try {
    http.Response response = await _client.post(
      url,
      body: body,
      headers: <String, String>{
        'authorization': basicAuth,
        'Content-Type': 'application/json; charset=UTF-8'
      },
    ).timeout(paymentTimeoutDuration);
    if (kDebugMode) {
      print('response (${response.statusCode}): ${response.body}');
    }
    return response;
  } on Exception catch (e) {
    debugPrint(e.toString());
    return null;
  }
}