makeDeposit method

Future<Map?> makeDeposit(
  1. String type,
  2. String amount
)

Implementation

Future<Map?> makeDeposit(String type, String amount) async {
  dynamic returnable;
  await SharedPreferences.getInstance().then((pref) async {
    String? token = pref.getString("token");

    Map data = {'type': type, 'amount': amount};
    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/deposit"),
        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);
    //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"]};
    }

    /*If the response is 200 or 201 (success) then the response will be decoded */
    else if (response.statusCode == 200 || response.statusCode == 201) {
      returnable = {
        "status": "success",
        "responseMessage": jsonData["data"]["data"]["responseMessage"],
        "orderRef": jsonData["data"]["data"]["orderRef"],
        "accountNumber": jsonData["data"]["data"]["accountNumber"],
        "bankName": jsonData["data"]["data"]["bankName"],
        "amount": jsonData["data"]["data"]["amount"],
        "txRef": jsonData["data"]["data"]["txRef"]
      };
    }
  });
  return returnable;
}