submitCaptcha method

Future<bool> submitCaptcha({
  1. required String txt,
  2. required String requestId,
  3. required String visiterId,
  4. required CyberCieraModel cieraModel,
})

Submits the CAPTCHA response for verification.

This function sends a POST request to the submitCaptchInfoForAndroid endpoint, verifying the user-provided CAPTCHA code along with device and session details. If the CAPTCHA is successfully validated, the function further validates a token using validateToken().

Parameters:

  • txt: The user-entered CAPTCHA text.
  • requestId: A unique identifier for the request.
  • visiterId: A unique identifier for the visitor session.
  • cieraModel: An instance of CyberCieraModel containing API-related configurations.

Function Workflow:

  1. Sets isLoading to true to indicate processing.
  2. Clears previous error messages.
  3. Constructs a request payload containing:
    • Master URL
    • Device details (IP, type, name)
    • Browser identity (udid)
    • CAPTCHA input (UserCaptcha)
    • Additional metadata (ByPass, Timespent, Flag, etc.)
    • User session (VisiterId, RequestID)
  4. Sends the request using ApiManager.post().
  5. Parses the response:
    • If successful (Message == "success"), validates the token via validateToken().
      • If token validation succeeds, returns true.
      • If token validation fails, sets an error message.
    • If the CAPTCHA is incorrect, sets an error message.
  6. Catches and logs any errors encountered.
  7. Finally, sets isLoading to false.

Returns:

  • true if CAPTCHA validation and token verification succeed.
  • false otherwise.

Implementation

Future<bool> submitCaptcha({required String txt, required String requestId, required String visiterId, required CyberCieraModel cieraModel}) async {
  isLoading(true);
  error("");
  bool isSuccess = false;
  try {
    Map<String, dynamic> map = {
      "MasterUrl": cieraModel.masterUrlId,
      "DeviceIp": deviceIp,
      "DeviceType": Platform.isAndroid ? "Android" : "ios",
      "DeviceName": deviceName,
      "UserCaptcha": txt,
      "ByPass": "Netural",
      "BrowserIdentity": udid,
      "Timespent": "24",
      "Protocol": "http",
      "Flag": "1",
      "second": "2",
      "RequestID": requestId,
      "VisiterId": visiterId,
      "fillupsecond": "8"
    };
    ResponseAPI responseAPI = await ApiManager.post(methodName: ApiConstant.submitCaptchInfoForAndroid, params: map);
    Map<String, dynamic> valueMap = (responseAPI.response);
    if (valueMap["Message"] == "success") {
      bool success = await validateToken(valueMap["data"], cieraModel);
      if (success) {
        isSuccess = success;
      } else {
        error("We cannot verify your private key.");
      }
    } else {
      error("You have enter wrong code");
    }
  } catch (err) {
    error(err.toString());
  } finally {
    isLoading(false);
  }
  return isSuccess;
}