loginWithAuthToken static method

Future loginWithAuthToken(
  1. Map<String, dynamic> payload,
  2. String env
)

Implementation

static Future<dynamic> loginWithAuthToken(Map<String, dynamic> payload, String env) async {
  String url = getBaseUrl(env) + "issuance/v1/cardholders/login/token";
  //print("Requested Data loginWithAuthToken${jsonEncode(payload)}");
  try {
    final response = await Card91HttpMethods.postMethods(jsonEncode(payload), url, "", "", "");
    if (response.statusCode >= 200 && response.statusCode <= 299) {
      var loginAuthTokenResponseModel = loginAuthTokenResponseModelFromJson(response.body);
      var bodyClient = loginAuthTokenResponseModelToJson(loginAuthTokenResponseModel);
      final Map<String, dynamic> data = json.decode(bodyClient);
      //Map<String, dynamic> jsonData = jsonDecode(response.body);
      return card91ResponseBodyToJson(new Card91ResponseBody(success: true, headers: response.headers, data: data));
    } else {
      Map<String, dynamic> jsonData = jsonDecode(response.body);
      Map<String, dynamic> jsonDataHeader = jsonDecode("{}");
      return card91ResponseBodyToJson(new Card91ResponseBody(success: false, headers: jsonDataHeader, data: jsonData));
    }
  } on SocketException {
    Map<String, dynamic> jsonData = jsonDecode('{"message": "Internet or Socket Exception"}');
    Map<String, dynamic> jsonDataHeader = jsonDecode("{}");
    return card91ResponseBodyToJson(new Card91ResponseBody(success: false, headers: jsonDataHeader, data: jsonData));
    throw ('noInternetConnection'.tr);
  } on HandshakeException {
    Map<String, dynamic> jsonData = jsonDecode('{"message":"Handshake Exception"}');
    Map<String, dynamic> jsonDataHeader = jsonDecode("{}");
    return card91ResponseBodyToJson(new Card91ResponseBody(success: false, headers: jsonDataHeader, data: jsonData));
    throw ("No internet");
  }
}