Skip to content

Commit 5aaede9

Browse files
committed
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.
1 parent 6995c83 commit 5aaede9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/Listeners/SendResourceLifecycleWebhook.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ public function handle($event)
3737
$apiEnvironment = session()->get('api_environment', $event->apiEnvironment ?? 'live');
3838
$isSandbox = session()->get('is_sandbox', $event->isSandbox);
3939

40+
// Compute the event payload exactly once so the persisted ApiEvent record and the
41+
// outbound webhook body are guaranteed to be identical. $event->getEventData() resolves
42+
// the model live at handle time, whereas $event->data is a snapshot frozen at dispatch
43+
// time; using each in a different place lets the DB record and the webhook diverge.
44+
$payload = $event->getEventData();
45+
4046
// Prepare event
4147
$eventData = [
4248
'company_uuid' => $companyId,
4349
'event' => $event->broadcastAs(),
4450
'source' => $apiCredentialId ? 'api' : 'console',
45-
'data' => $event->getEventData(),
51+
'data' => $payload,
4652
'method' => $event->requestMethod,
4753
'description' => $this->getHumanReadableEventDescription($event),
4854
];
@@ -100,7 +106,7 @@ public function handle($event)
100106
'sent_at' => Carbon::now(),
101107
])
102108
->url($webhook->url)
103-
->payload($event->data)
109+
->payload($payload)
104110
->useSecret($apiSecret)
105111
->dispatch();
106112
} catch (\Exception|\Aws\Sqs\Exception\SqsException $exception) {

0 commit comments

Comments
 (0)