| Conditions | 5 |
| Paths | 12 |
| Total Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | 3 | public function handleWebhook(Request $request) |
|
| 17 | { |
||
| 18 | 3 | $data = $request->get('event-data'); |
|
| 19 | |||
| 20 | 3 | if (! isset($data['message']['headers']['message-id'])) { |
|
| 21 | // If Mailgun receives a 406 (Not Acceptable) code, Mailgun will determine the POST is rejected and not retry. |
||
| 22 | 1 | abort(406); |
|
| 23 | } |
||
| 24 | |||
| 25 | 2 | $message_id = $data['message']['headers']['message-id']; |
|
| 26 | |||
| 27 | 2 | $delivery = EmailLog::where('provider', 'mailgun')->where('provider_email_id', $message_id)->first(); |
|
| 28 | |||
| 29 | 2 | if (! $delivery) { |
|
| 30 | // If Mailgun receives a 406 (Not Acceptable) code, Mailgun will determine the POST is rejected and not retry. |
||
| 31 | 1 | abort(406); |
|
| 32 | } |
||
| 33 | |||
| 34 | 1 | if (in_array($data['event'], ['opened', 'clicked', 'delivered', 'failed'])) { |
|
| 35 | 1 | if ($delivery->{$data['event'].'_at'} == null) { |
|
| 36 | 1 | $delivery->update(["{$data['event']}_at" => now()]); |
|
| 37 | } |
||
| 38 | } |
||
| 39 | 1 | } |
|
| 40 | } |
||
| 41 |