postRequest static method

Future postRequest(
  1. String api,
  2. Map body,
  3. bool testMood
)

Implementation

static Future postRequest(String api, Map body, bool testMood) async {
  var url2 = testMood == true
      ? Uri.parse('https://uatcheckout.thawani.om/api/v1/checkout/session')
      : Uri.parse('https://checkout.thawani.om/api/v1/checkout/session');
  http.Response response = await http.post(url2,
      headers: {'thawani-api-key': api, 'Content-Type': 'application/json'},
      body: json.encode(body));

  try {
    if (response.statusCode == 200) {
      String data = response.body;
      var decodeData = jsonDecode(data);
      // print(decodeData);
      return decodeData;
    } else {
      var data = response.body;
      var decodeData = jsonDecode(data);
      // print(decodeData);
      return decodeData;
    }
  } catch (e) {
    return 'failed';
  }
}