onFailure method

void onFailure(
  1. String data
)

Implementation

void onFailure(String data) {
  var jsonObject = json.decode(data) as Map<String, dynamic>;
  var order = jsonObject["order"];
  var orderId = order["orderId"] as dynamic ?? "";
  var message = order["errorText"] as String;
  var transaction = jsonObject["transaction"] as dynamic;
  if(transaction != null) {
    message = transaction["txMsg"] as String ?? "";
    if(_onError != null) {
      var errorResponse = CFErrorResponse("FAILED", message, "invalid_request", "invalid request");
      _onError!(errorResponse, orderId);
      _outerDiv?.remove();
    }
  } else {
    if((message.toLowerCase() == "order is no longer active") || (message.toLowerCase() == "token is not present")) {
      if(_onError != null) {
        var errorResponse = CFErrorResponse("FAILED", message, "invalid_request", "invalid request");
        _onError!(errorResponse, orderId.toString());
        _outerDiv?.remove();
      }
    } else {
      _showToast(message);
    }
  }
}