@@ -28,10 +28,14 @@ class ReCaptchaProvider
2828
2929 private string $ secretKey ;
3030
31- public function __construct (string $ siteKey , string $ secretKey )
31+ // Range 0..1 (1.0 is very likely a good interaction, 0.0 is very likely a bot)
32+ private float $ minimalScore ;
33+
34+ public function __construct (string $ siteKey , string $ secretKey , float $ minimalScore )
3235 {
3336 $ this ->siteKey = $ siteKey ;
3437 $ this ->secretKey = $ secretKey ;
38+ $ this ->setMinimalScore ($ minimalScore );
3539 }
3640
3741 public function getSiteKey (): string
@@ -57,7 +61,7 @@ public function validate(string $response): ?ReCaptchaResponse
5761 $ answer = json_decode ($ response , true );
5862
5963 // Return response
60- return $ answer ['success ' ] === true ? new ReCaptchaResponse (true ) : new ReCaptchaResponse (false , $ answer ['error-codes ' ] ?? null );
64+ return $ answer ['success ' ] === true && $ answer [ ' score ' ] >= $ this -> minimalScore ? new ReCaptchaResponse (true ) : new ReCaptchaResponse (false , $ answer ['error-codes ' ] ?? null );
6165 }
6266
6367 public function validateControl (BaseControl $ control ): bool
@@ -77,6 +81,11 @@ public function validateControl(BaseControl $control): bool
7781 return false ;
7882 }
7983
84+ public function setMinimalScore (float $ score ): void
85+ {
86+ $ this ->minimalScore = $ score ;
87+ }
88+
8089 protected function makeRequest (?string $ response , ?string $ remoteIp = null ): string |null
8190 {
8291 if ($ response === null || $ response === '' ) {
0 commit comments