hcaptcha 3.2.1

hCaptcha client response verification. Validate the hCaptcha response submitted from to your server from the client.
Documentation
// SPDX-FileCopyrightText: 2022 jerusdp
//
// SPDX-License-Identifier: MIT OR Apache-2.0

use super::error::ContactError;
use super::param;
use hcaptcha::{Captcha, Client, Request, Response};

const HCAPTCHA_SECRET: &str = "/hcaptcha/secret";

pub async fn response_valid(captcha: Captcha) -> Result<Response, ContactError> {
    let secret = param::get_parameter(HCAPTCHA_SECRET).await?;

    let client = Client::new();

    let request = Request::new(&secret, captcha)?;

    let res = client.verify_request(request).await?;

    Ok(res)
}