From 5aaede9f693d90c89962b56e8ba00075d85ae1d3 Mon Sep 17 00:00:00 2001 From: Prem Kumar Sharma Date: Tue, 2 Jun 2026 16:50:53 +0530 Subject: [PATCH] fix: reuse lifecycle event payload for webhooks Compute the resource lifecycle payload once in SendResourceLifecycleWebhook and use the same value for both the persisted ApiEvent data and the outbound webhook request body. This prevents webhook deliveries from diverging from the api_events.data record when the event snapshot and live model payload differ. --- src/Listeners/SendResourceLifecycleWebhook.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Listeners/SendResourceLifecycleWebhook.php b/src/Listeners/SendResourceLifecycleWebhook.php index f125ce1e..cfd6c2f2 100644 --- a/src/Listeners/SendResourceLifecycleWebhook.php +++ b/src/Listeners/SendResourceLifecycleWebhook.php @@ -37,12 +37,18 @@ public function handle($event) $apiEnvironment = session()->get('api_environment', $event->apiEnvironment ?? 'live'); $isSandbox = session()->get('is_sandbox', $event->isSandbox); + // Compute the event payload exactly once so the persisted ApiEvent record and the + // outbound webhook body are guaranteed to be identical. $event->getEventData() resolves + // the model live at handle time, whereas $event->data is a snapshot frozen at dispatch + // time; using each in a different place lets the DB record and the webhook diverge. + $payload = $event->getEventData(); + // Prepare event $eventData = [ 'company_uuid' => $companyId, 'event' => $event->broadcastAs(), 'source' => $apiCredentialId ? 'api' : 'console', - 'data' => $event->getEventData(), + 'data' => $payload, 'method' => $event->requestMethod, 'description' => $this->getHumanReadableEventDescription($event), ]; @@ -100,7 +106,7 @@ public function handle($event) 'sent_at' => Carbon::now(), ]) ->url($webhook->url) - ->payload($event->data) + ->payload($payload) ->useSecret($apiSecret) ->dispatch(); } catch (\Exception|\Aws\Sqs\Exception\SqsException $exception) {