Skip to content

Commit 9c05d89

Browse files
authored
Merge pull request #218 from blockalicious-io/fix-resource-lifecycle-webhook-payload
Fix resource lifecycle webhook payload mismatch
2 parents 1948c29 + 5aaede9 commit 9c05d89

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)