| @@ -1,0 +1,42 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +class SendinblueWebhooks extends SendinblueClass | |
| 4 | +{ | |
| 5 | + public function addWebhooks() | |
| 6 | + { | |
| 7 | + $sendingMethod = $this->config->get('mailer_method', 'phpmail'); | |
| 8 | + if ($sendingMethod != plgAcymSendinblue::SENDING_METHOD_ID) return; | |
| 9 | + | |
| 10 | + $webhooks = $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_webhooks_added'); | |
| 11 | + if (!empty($webhooks)) return; | |
| 12 | + | |
| 13 | + $securityKey = $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_webhooks_seckey'); | |
| 14 | + if (empty($securityKey)) { | |
| 15 | + $securityKey = acym_generateKey(40); | |
| 16 | + $this->config->saveConfig([plgAcymSendinblue::SENDING_METHOD_ID.'_webhooks_seckey' => $securityKey]); | |
| 17 | + } | |
| 18 | + | |
| 19 | + $types = ['transactional', 'marketing']; | |
| 20 | + | |
| 21 | + $webhooks = []; | |
| 22 | + foreach ($types as $type) { | |
| 23 | + $response = $this->callApiSendingMethod( | |
| 24 | + 'webhooks?type='.$type, | |
| 25 | + [ | |
| 26 | + 'events' => ['hardBounce', 'spam', 'unsubscribed'], | |
| 27 | + 'type' => $type, | |
| 28 | + 'url' => acym_frontendLink('frontservices&task=sendinblue&seckey='.$securityKey), | |
| 29 | + 'description' => 'Disable users in AcyMailing', | |
| 30 | + ], | |
| 31 | + $this->headers, | |
| 32 | + 'POST' | |
| 33 | + ); | |
| 34 | + | |
| 35 | + if (!empty($response['id'])) { | |
| 36 | + $webhooks[$type] = $response['id']; | |
| 37 | + } | |
| 38 | + } | |
| 39 | + | |
| 40 | + $this->config->saveConfig([plgAcymSendinblue::SENDING_METHOD_ID.'_webhooks_added' => json_encode($webhooks)]); | |
| 41 | + } | |
| 42 | +} | |