Allow client postmark webhooks

This commit is contained in:
David Bomba 2025-02-04 11:40:46 +11:00
parent 26e0e702d6
commit fd28457f13
3 changed files with 10 additions and 9 deletions

View File

@ -65,7 +65,12 @@ class PostMarkController extends BaseController
public function webhook(Request $request) public function webhook(Request $request)
{ {
if ($request->header('X-API-SECURITY') && $request->header('X-API-SECURITY') == config('services.postmark.token')) { 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); return response()->json(['message' => 'Success'], 200);
} }

View File

@ -59,7 +59,7 @@ class ProcessPostmarkWebhook implements ShouldQueue
* Create a new job instance. * 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) 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($this->security_token);
$postmark = new PostmarkClient($postmark_secret);
$messageDetail = $postmark->getOutboundMessageDetails($message_id); $messageDetail = $postmark->getOutboundMessageDetails($message_id);
try { try {
@ -400,9 +398,7 @@ class ProcessPostmarkWebhook implements ShouldQueue
try { try {
$postmark_secret = !empty($this->company->settings->postmark_secret) ? $this->company->settings->postmark_secret : config('services.postmark.token'); $postmark = new PostmarkClient($this->security_token);
$postmark = new PostmarkClient($postmark_secret);
try { try {
$messageDetail = $postmark->getOutboundMessageDetails($this->request['MessageID']); $messageDetail = $postmark->getOutboundMessageDetails($this->request['MessageID']);

View File

@ -465,7 +465,7 @@ Route::match(['get', 'post'], 'payment_notification_webhook/{company_key}/{compa
->name('payment_notification_webhook'); ->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/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_webhook', [MailgunController::class, 'webhook'])->middleware('throttle:1000,1');
Route::post('api/v1/mailgun_inbound_webhook', [MailgunController::class, 'inboundWebhook'])->middleware('throttle:1000,1'); Route::post('api/v1/mailgun_inbound_webhook', [MailgunController::class, 'inboundWebhook'])->middleware('throttle:1000,1');