| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Captcha\Friendly_Captcha; |
| 5 |
|
| 6 |
use Jet_Form_Builder\Exceptions\Gateway_Exception; |
| 7 |
use JFB_Modules\Captcha\Module; |
| 8 |
use JFB_Modules\Gateways\Actions_Abstract\Action_Application_Raw_Body_It; |
| 9 |
use JFB_Modules\Gateways\Base_Gateway_Action; |
| 10 |
|
| 11 |
class Verify_Token_Action extends Base_Gateway_Action implements |
| 12 |
Action_Application_Raw_Body_It { |
| 13 |
|
| 14 |
private $secret; |
| 15 |
private $solution; |
| 16 |
private $site_key; |
| 17 |
|
| 18 |
public function action_endpoint() { |
| 19 |
return 'siteverify'; |
| 20 |
} |
| 21 |
|
| 22 |
public function base_url(): string { |
| 23 |
return 'https://api.friendlycaptcha.com/api/v1/'; |
| 24 |
} |
| 25 |
|
| 26 |
public function send_request() { |
| 27 |
$response = parent::send_request(); |
| 28 |
|
| 29 |
if ( ! empty( $response['success'] ) ) { |
| 30 |
return $response; |
| 31 |
} |
| 32 |
|
| 33 |
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 34 |
throw new Gateway_Exception( Module::SPAM_EXCEPTION, $response, $this->get_request_args() ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* @throws Gateway_Exception |
| 39 |
*/ |
| 40 |
public function before_make_request() { |
| 41 |
if ( $this->solution && $this->secret && $this->site_key ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 46 |
throw new Gateway_Exception( Module::SPAM_EXCEPTION, 'Empty solution. Spammer detected' ); |
| 47 |
} |
| 48 |
|
| 49 |
public function set_secret( string $secret ): Verify_Token_Action { |
| 50 |
$this->secret = $secret; |
| 51 |
|
| 52 |
return $this; |
| 53 |
} |
| 54 |
|
| 55 |
public function set_solution( string $solution ): Verify_Token_Action { |
| 56 |
$this->solution = $solution; |
| 57 |
|
| 58 |
return $this; |
| 59 |
} |
| 60 |
|
| 61 |
public function set_site_key( string $key ): Verify_Token_Action { |
| 62 |
$this->site_key = $key; |
| 63 |
|
| 64 |
return $this; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
public function action_body() { |
| 69 |
return array( |
| 70 |
'secret' => $this->secret, |
| 71 |
'solution' => $this->solution, |
| 72 |
'sitekey' => $this->site_key, |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|