1 | <?php |
||
20 | class MailgunController extends Controller |
||
21 | { |
||
22 | const TYPE_CLICKED = 'clicked'; |
||
23 | const TYPE_COMPLAINED = 'complained'; |
||
24 | const TYPE_DELIVERED = 'delivered'; |
||
25 | const TYPE_OPENED = 'opened'; |
||
26 | const TYPE_PERMANENT_FAIL = 'permanent_fail'; |
||
27 | const TYPE_TEMPORARY_FAIL = 'temporary_fail'; |
||
28 | const TYPE_UNSUBSCRIBED = 'unsubscribed'; |
||
29 | |||
30 | protected $eventsCount = 0; |
||
31 | protected $skipCount = 0; |
||
32 | private static $allowed_actions = [ |
||
|
|||
33 | 'incoming', |
||
34 | 'test', |
||
35 | 'configure_inbound_emails' |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * Inject public dependencies into the controller |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | private static $dependencies = [ |
||
44 | 'logger' => '%$Psr\Log\LoggerInterface', |
||
45 | ]; |
||
46 | |||
47 | /** |
||
48 | * @var Psr\Log\LoggerInterface |
||
49 | */ |
||
50 | public $logger; |
||
51 | |||
52 | public function index(HTTPRequest $req) |
||
59 | |||
60 | /** |
||
61 | * You can also see /resources/webhook.txt |
||
62 | * |
||
63 | * @param HTTPRequest $req |
||
64 | */ |
||
65 | public function test(HTTPRequest $req) |
||
82 | |||
83 | /** |
||
84 | * @link https://support.Mailgun.com/customer/portal/articles/2039614-enabling-inbound-email-relaying-relay-webhooks |
||
85 | * @param HTTPRequest $req |
||
86 | * @return string |
||
87 | */ |
||
88 | public function configure_inbound_emails(HTTPRequest $req) |
||
114 | |||
115 | /** |
||
116 | * Handle incoming webhook |
||
117 | * |
||
118 | * @param HTTPRequest $req |
||
119 | */ |
||
120 | public function incoming(HTTPRequest $req) |
||
168 | |||
169 | /** |
||
170 | * A receiving URI must be public, so webhooks should be secured with a signature, |
||
171 | * time stamp and token to create a hash map using an API key to verify that the data |
||
172 | * is coming from the developer’s ESP. Users should program their application to check |
||
173 | * that hash map and compare it to that of the ESP, and then allow the post to be made only if it matches. |
||
174 | * |
||
175 | * To verify the webhook is originating from their ESP, users should concatenate time stamp and token values, |
||
176 | * encode the resulting string with the HMAC algorithm (using the ESP’s supplied API Key as a key and SHA256 digest mode), |
||
177 | * and compare the resulting hexdigest to the signature. |
||
178 | * Optionally, users can cache the token value locally and not honor any subsequent request with the same token. This will prevent replay attacks. |
||
179 | * |
||
180 | * @return bool |
||
181 | */ |
||
182 | protected function verifyCall() |
||
187 | |||
188 | /** |
||
189 | * Process data |
||
190 | * |
||
191 | * @param string $payload |
||
192 | * @param string $batchId |
||
193 | */ |
||
194 | protected function processPayload($payload, $batchId = null) |
||
228 | |||
229 | |||
230 | /** |
||
231 | * Get logger |
||
232 | * |
||
233 | * @return Psr\SimpleCache\CacheInterface |
||
234 | */ |
||
235 | public function getLogger() |
||
239 | } |
||
240 |