HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/iphim.naniguide.com/common/Settings/Validators/RecaptchaCredentialsValidator.php
<?php

namespace Common\Settings\Validators;

use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;

class RecaptchaCredentialsValidator
{
    const KEYS = ['recaptcha.site_key', 'recaptcha.secret_key'];

    public function fails($settings): array|false
    {
        try {
            $response = Http::asForm()->post(
                'https://www.google.com/recaptcha/api/siteverify',
                [
                    'response' => 'foo-bar',
                    'secret' => Arr::get($settings, 'recaptcha.secret_key'),
                ],
            );

            if (
                $response['success'] === false &&
                $response['error-codes'][0] !== 'invalid-input-response'
            ) {
                return [
                    'recaptcha_group' =>
                        Arr::get($response, 'error-codes')[0] ??
                        __('These credentials are not valid'),
                ];
            }
        } catch (Exception $e) {
            return $this->getErrorMessage($e);
        }

        return false;
    }

    private function getErrorMessage(Exception $e): array
    {
        return ['recaptcha_group' => $e->getMessage()];
    }
}