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