verify-token-action.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Captcha\Hcaptcha; |
| 5 | |
| 6 | use Jet_Form_Builder\Exceptions\Gateway_Exception; |
| 7 | use JFB_Modules\Captcha\Module; |
| 8 | use JFB_Modules\Captcha\Re_Captcha_V3\Verify_Token_Action as BaseVerify; |
| 9 | |
| 10 | class Verify_Token_Action extends BaseVerify { |
| 11 | |
| 12 | private $site_key; |
| 13 | |
| 14 | public function base_url(): string { |
| 15 | return 'https://hcaptcha.com/'; |
| 16 | } |
| 17 | |
| 18 | public function before_make_request() { |
| 19 | parent::before_make_request(); |
| 20 | |
| 21 | if ( $this->site_key ) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 26 | throw new Gateway_Exception( Module::SPAM_EXCEPTION, 'Empty site key. Spammer detected' ); |
| 27 | } |
| 28 | |
| 29 | public function send_request() { |
| 30 | $this->request(); |
| 31 | $this->response_body_as_array(); |
| 32 | |
| 33 | $response = $this->get_response_body(); |
| 34 | |
| 35 | if ( ! empty( $response['success'] ) ) { |
| 36 | return $response; |
| 37 | } |
| 38 | |
| 39 | // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 40 | throw new Gateway_Exception( Module::SPAM_EXCEPTION ); |
| 41 | } |
| 42 | |
| 43 | public function set_site_key( string $site_key ): Verify_Token_Action { |
| 44 | $this->site_key = $site_key; |
| 45 | |
| 46 | return $this; |
| 47 | } |
| 48 | |
| 49 | public function action_body() { |
| 50 | return array_merge( |
| 51 | parent::action_body(), |
| 52 | array( 'sitekey' => $this->site_key ) |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | } |
| 57 |