all(), [ 'g-recaptcha-response' => [ 'required', 'string', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed function ($attribute, $value, $fail) use ($isV3) { try { $response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [ 'secret' => config('services.google.recaptcha.private'), 'response' => \strval($value), 'remoteip' => app('clientIp') ]); if ($e = $response->toException()) { throw $e; } if ($isV3) { if ( !$response->json('success') or !$response->json('challenge_ts') or Carbon::parse($response->json('challenge_ts'))->lessThan(\now('utc')->subMinutes(5)) or $response->json('hostname') !== \parse_url(config('app.url'), \PHP_URL_HOST) or !$response->json('score') ) { throw new \RuntimeException(); } if (\floatval($response->json('score')) < 0.8) { $fail("Vous n'avez pas obtenu un score assez élevé lors de la validation du recaptcha"); } return; } if ( !$response->json('success') or !$response->json('challenge_ts') or Carbon::parse($response->json('challenge_ts'))->lessThan(\now('utc')->subMinutes(5)) or $response->json('hostname') !== \parse_url(config('app.url'), \PHP_URL_HOST) ) { throw new \RuntimeException(); } } catch (\Exception $e) { $fail('Erreur lors de la validation du formulaire veuillez réssayer'); } //end try } ] ], [], ['g-recaptcha-response' => 'reCaptcha']); } }