makeWithdrawal method

Future<Map?> makeWithdrawal(
  1. String amount,
  2. String withdrawalPin
)

Implementation

Future<Map?> makeWithdrawal(String amount, String withdrawalPin) async {
  dynamic returnable;
  await SharedPreferences.getInstance().then((pref) async {
    String? token = pref.getString("token");
    Map data = {'amount': amount, 'withdrawal_pin': withdrawalPin};
    String? client_id = iAmA == "consultant"
        ? Params.consultant_client_id
        : Params.patient_client_id;

    /*Calling the API url */
    var jsonData;
    final response = await http.post(
        Uri.parse(Params.base_url + "/wallets/withdraw"),
        body: data,
        headers: {"Client-ID": "$client_id", "Authorization": "$token"});

    if (debug) {
      print('Status Code = ' +
          response.statusCode.toString() +
          ". Response: " +
          response.body);
    }
    jsonData = json.decode(response.body);
    if (response.statusCode == 200 || response.statusCode == 201) {
      returnable = {
        "status": jsonData["status"],
        "message": jsonData["message"]
      };
    }
    //response::Unprocessable entity
    if (response.statusCode == 422) {
      returnable = {
        "status": jsonData["status"],
        "message": jsonData["message"]
      };
    }
    //response::Forbidden
    else if (response.statusCode == 403) {
      returnable = {"detail": jsonData["detail"]};
    } else {
      returnable = null;
    }
  });
  return returnable;
}