validateOtp method

Future<MobileVerifyModel?> validateOtp(
  1. RequestModel requestModel,
  2. String msisdn,
  3. String otp,
  4. BuildContext context,
)

Implementation

Future<MobileVerifyModel?> validateOtp(RequestModel requestModel,
    String msisdn, String otp, BuildContext context) async {
  try {
    String authToken =
        "Basic ${base64.encode(utf8.encode("${requestModel.user.toString()}:${requestModel.password.toString()}"))}";
    String url =
        ApiConstants.getSelectedBaseUrl() + ApiConstants.VALIDATE_OTP;
    Map<String, String> data = new Map();
    data["Otp"] = otp;
    data["Msisdn"] = msisdn;
    data["MerchantCode"] = requestModel.merchantCode.toString();

    Map<String, String> headers = new Map();
    headers["Authorization"] = authToken;
    headers["Module"] = requestModel.module.toString();
    headers["Content-Type"] = "application/json;charset=UTF-8";


    var response = await http.post(Uri.parse(url),
        body: jsonEncode(data), headers: headers);


    if (response.statusCode == 401) {
      Utils.showSnackbar(context, "Unauthorized");
      return null;
    } else if (response.body == null) {
      Utils.showSnackbar(context, "Something Went Wrong");
      return null;
    } else if (response.statusCode == 500) {
      Utils.showSnackbar(context, "Something Went Wrong");
      return null;
    } else {
      MobileVerifyModel model =
          MobileVerifyModel.fromJson(json.decode(response.body));
      return model;
    }
  } catch (ex) {
    return null;
  }
}