1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Http/Controllers/MailgunWebhookController.php

43 lines
1.2 KiB
PHP
Raw Normal View History

2024-01-16 05:59:29 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2024-01-16 05:59:29 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers;
use App\Jobs\Mailgun\ProcessMailgunWebhook;
use App\Jobs\PostMark\ProcessPostmarkWebhook;
use Illuminate\Http\Request;
/**
* Class MailgunWebhookController.
*/
class MailgunWebhookController extends BaseController
{
2024-02-13 05:25:18 +01:00
public function __construct()
{
}
2024-01-16 05:59:29 +01:00
public function webhook(Request $request)
{
$input = $request->all();
2024-02-13 05:25:18 +01:00
if (\abs(\time() - $request['signature']['timestamp']) > 15) {
2024-01-16 05:59:29 +01:00
return response()->json(['message' => 'Success'], 200);
2024-02-13 05:25:18 +01:00
}
2024-01-16 05:59:29 +01:00
2024-02-13 05:25:18 +01:00
if(\hash_equals(\hash_hmac('sha256', $input['signature']['timestamp'] . $input['signature']['token'], config('services.mailgun.webhook_signing_key')), $input['signature']['signature'])) {
2024-08-22 08:45:06 +02:00
ProcessMailgunWebhook::dispatch($request->all())->delay(rand(2, 10));
2024-02-13 05:25:18 +01:00
}
2024-01-16 05:59:29 +01:00
return response()->json(['message' => 'Success.'], 200);
}
}