_name = 'Recaptcha3'; $this->_privateKey = $privateKey; $this->_publicKey = $publicKey; } public function validateToken(array $post): bool { $token = $post['recaptcha']; $url = 'https://www.google.com/recaptcha/api/siteverify'; $result = HttpClient::post($url, [ 'secret' => $this->getPrivateKey(), 'response' => $token, ])->json(true); return $result['success'] == 'true'; } public function validateSecret(string $secret) : bool { return true; } public function validateKey(string $key) : bool { return true; } public function getHtml(): ?string { return null; } public function getJavascriptSource(): string { return 'https://www.google.com/recaptcha/api.js?render=' . $this->getPublicKey(); } public function getJavascriptSubmit(string $id): string { return ' grecaptcha.ready(function() { grecaptcha.execute("' . $this->getPublicKey() . '", { action: "submit" }).then(function(token) { $("#' . $id . '").prepend(""); $("#' . $id . '").off("submit").submit(); }); }); '; } }