PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.6.0
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.6.0
1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / src / Api / Webhooks / Handlers / WebhookHandler.php
hostinger-reach / src / Api / Webhooks / Handlers Last commit date
CartAbandoned.php 8 months ago OrderPurchased.php 8 months ago WebhookHandler.php 8 months ago
WebhookHandler.php
56 lines
1 <?php
2
3 namespace Hostinger\Reach\Api\Webhooks\Handlers;
4
5 use Hostinger\Reach\Api\Handlers\ReachApiHandler;
6 use Hostinger\Reach\Repositories\FormRepository;
7
8 abstract class WebhookHandler {
9
10 protected ReachApiHandler $reach_api_handler;
11 protected FormRepository $form_repository;
12
13 public function __construct( ReachApiHandler $reach_api_handler, FormRepository $form_repository ) {
14 $this->reach_api_handler = $reach_api_handler;
15 $this->form_repository = $form_repository;
16 }
17
18 public function init(): void {
19 add_action( 'init', array( $this, 'init_hooks' ) );
20 }
21
22 public function is_enabled(): bool {
23 return $this->reach_api_handler->is_connected() && $this->is_automation_active();
24 }
25
26 public function is_automation_active(): bool {
27 return $this->form_repository->is_form_active( $this->get_name() );
28 }
29
30 public function increase_automation_submission_counter(): bool {
31 return $this->form_repository->submit( array( 'form_id' => $this->get_name() ) );
32 }
33
34 public function handle( string $email, mixed $data ): bool {
35 $webhook_payload = array(
36 'name' => $this->get_name(),
37 'contact' => array(
38 'email' => $email,
39 ),
40 'metadata' => $this->get_metadata( $data ),
41 );
42
43 $response = $this->reach_api_handler->post_webhook_event( $webhook_payload );
44 if ( ! $response->is_error() ) {
45 $this->increase_automation_submission_counter();
46 return true;
47 }
48
49 return false;
50 }
51
52 abstract public function init_hooks(): void;
53 abstract public function get_metadata( mixed $data ): array;
54 abstract public function get_name(): string;
55 }
56