diff --git a/app/Http/Controllers/PostMarkController.php b/app/Http/Controllers/PostMarkController.php index 63af8b0069..552db691be 100644 --- a/app/Http/Controllers/PostMarkController.php +++ b/app/Http/Controllers/PostMarkController.php @@ -65,7 +65,12 @@ class PostMarkController extends BaseController public function webhook(Request $request) { if ($request->header('X-API-SECURITY') && $request->header('X-API-SECURITY') == config('services.postmark.token')) { - ProcessPostmarkWebhook::dispatch($request->all())->delay(15); + ProcessPostmarkWebhook::dispatch($request->all(), $request->header('X-API-SECURITY'))->delay(15); + + return response()->json(['message' => 'Success'], 200); + } + elseif($request->header('X-API-SECURITY') && stripos($request->header('X-API-SECURITY'), \Illuminate\Support\Facades\Cache::get('client_postmark_keys')) !== false){ + ProcessPostmarkWebhook::dispatch($request->all(), $request->header('X-API-SECURITY'))->delay(15); return response()->json(['message' => 'Success'], 200); } diff --git a/app/Jobs/PostMark/ProcessPostmarkWebhook.php b/app/Jobs/PostMark/ProcessPostmarkWebhook.php index 1482017005..fd05275064 100644 --- a/app/Jobs/PostMark/ProcessPostmarkWebhook.php +++ b/app/Jobs/PostMark/ProcessPostmarkWebhook.php @@ -59,7 +59,7 @@ class ProcessPostmarkWebhook implements ShouldQueue * Create a new job instance. * */ - public function __construct(private array $request) + public function __construct(private array $request, private string $security_token) { } @@ -356,9 +356,7 @@ class ProcessPostmarkWebhook implements ShouldQueue public function getRawMessage(string $message_id) { - $postmark_secret = !empty($this->company->settings->postmark_secret) ? $this->company->settings->postmark_secret : config('services.postmark.token'); - - $postmark = new PostmarkClient($postmark_secret); + $postmark = new PostmarkClient($this->security_token); $messageDetail = $postmark->getOutboundMessageDetails($message_id); try { @@ -400,9 +398,7 @@ class ProcessPostmarkWebhook implements ShouldQueue try { - $postmark_secret = !empty($this->company->settings->postmark_secret) ? $this->company->settings->postmark_secret : config('services.postmark.token'); - - $postmark = new PostmarkClient($postmark_secret); + $postmark = new PostmarkClient($this->security_token); try { $messageDetail = $postmark->getOutboundMessageDetails($this->request['MessageID']); diff --git a/routes/api.php b/routes/api.php index 69ce64c8c9..d1bb209638 100644 --- a/routes/api.php +++ b/routes/api.php @@ -465,7 +465,7 @@ Route::match(['get', 'post'], 'payment_notification_webhook/{company_key}/{compa ->name('payment_notification_webhook'); -Route::post('api/v1/postmark_webhook', [PostMarkController::class, 'webhook'])->middleware('throttle:2000,1'); +Route::post('api/v1/postmark_webhook', [PostMarkController::class, 'webhook'])->middleware('throttle:5000,1'); Route::post('api/v1/postmark_inbound_webhook', [PostMarkController::class, 'inboundWebhook'])->middleware('throttle:1000,1'); Route::post('api/v1/mailgun_webhook', [MailgunController::class, 'webhook'])->middleware('throttle:1000,1'); Route::post('api/v1/mailgun_inbound_webhook', [MailgunController::class, 'inboundWebhook'])->middleware('throttle:1000,1');