Inherited the parent class of the RecaptchaV3 package:
<?php
namespace App\Services;
use Lunaweb\RecaptchaV3\RecaptchaV3;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Psr7\Response;
class RecaptchaV3Async extends RecaptchaV3
{
/**
* @param $token
* @param null $action
* @return Promise
*/
public function verifyAsync($token, $action = null)
{
return $this->http->requestAsync('POST', $this->origin . '/api/siteverify', [
'form_params' => [
'secret' => $this->secret,
'response' => $token,
'remoteip' => $this->request->getClientIp(),
],
])->then(function (Response $response) use ($action) {
$body = json_decode($response->getBody(), true);
if (!isset($body['success']) || $body['success'] !== true) {
return false;
}
if ($action && (!isset($body['action']) || $action != $body['action'])) {
return false;
}
return isset($body['score']) ? $body['score'] : false;
});
}
}