Skip to content

Instantly share code, notes, and snippets.

@standa
Last active October 6, 2018 10:24
Show Gist options
  • Save standa/74b6ae5519258da06410c27108fad6fb to your computer and use it in GitHub Desktop.
Save standa/74b6ae5519258da06410c27108fad6fb to your computer and use it in GitHub Desktop.
Parse mailgun webhook
<?php
function parse_mailgun_webhook_stdin(): array
{
$raw = file_get_contents('php://input');
$json = json_decode($raw, true);
$order_id = $json['event-data']['user-variables']['order_id'] ?? $json['event-data']['user-variables']['order-id'] ?? null;
$mail_id = $json['event-data']['user-variables']['mail_id'] ?? $json['event-data']['user-variables']['mail-id'] ?? null;
$recipient = $json['event-data']['recipient'] ?? null;
$event = $json['event-data']['event'] ?? null;
$timestamp = date('c', $json['event-data']['timestamp'] ?? 0);
return ['recipient' => $recipient, 'event' => $event,
'order_id' => $order_id, 'mail_id' => $mail_id, 'timestamp' => $timestamp, 'raw' => $raw];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment