| | |
| | | |
| | | namespace JVBase\integrations\services; |
| | | use JVBase\integrations\Admin; |
| | | use JVBase\integrations\Instance; |
| | | use JVBase\Instance; |
| | | use JVBase\integrations\Integrations; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | |
| | | protected function initialize(): void |
| | | { |
| | | // TODO: Implement initialize() method. |
| | | add_action('woocommerce_review_order_before_submit', [$this, 'addToCheckout']); |
| | | add_action('wp_enqueue_scripts', [$this, 'enqueueOnCheckout']); |
| | | add_action('woocommerce_checkout_process', [$this, 'checkoutTurnstile']); |
| | | } |
| | | |
| | | public function getServiceDescription():string |
| | |
| | | |
| | | /** |
| | | * Verify the Turnstile response |
| | | * Can be called directly via JVB()->connect('cloudflare')->verifyTurnstile($token) |
| | | * or Cloudflare::getInstance()->verifyTurnstile($token) |
| | | * Can be called directly via Cloudflare::getInstance()->verifyTurnstile($token) |
| | | * @param string|null $token |
| | | * @param string $remote_ip |
| | | * @return bool |
| | |
| | | } |
| | | return $result['success'] ?? false; |
| | | } |
| | | |
| | | public function enqueueOnCheckout():void |
| | | { |
| | | if (function_exists('is_checkout') && is_checkout()) { |
| | | self::enqueueTurnstileScripts(); |
| | | } |
| | | } |
| | | public function addToCheckout():void |
| | | { |
| | | self::renderTurnstile(); |
| | | } |
| | | public function checkoutTurnstile():void |
| | | { |
| | | $verified = $this->verifyTurnstile(); |
| | | if (!$verified && function_exists('wc_add_notice')) { |
| | | wc_add_notice('Security check failed. Please try again', 'error'); |
| | | return; |
| | | } |
| | | } |
| | | } |