$context */ public function recordReceived(string $provider, ?string $eventId, ?string $eventType, array $context = []): IntegrationWebhookEvent { return IntegrationWebhookEvent::create([ 'provider' => $provider, 'event_id' => $eventId, 'event_type' => $eventType, 'status' => IntegrationWebhookEvent::STATUS_RECEIVED, 'received_at' => now(), 'context' => $context, ]); } /** * @param array $context */ public function markProcessed(IntegrationWebhookEvent $event, array $context = []): IntegrationWebhookEvent { $event->forceFill([ 'status' => IntegrationWebhookEvent::STATUS_PROCESSED, 'processed_at' => now(), 'context' => $this->mergeContext($event, $context), ])->save(); return $event; } /** * @param array $context */ public function markIgnored(IntegrationWebhookEvent $event, array $context = []): IntegrationWebhookEvent { $event->forceFill([ 'status' => IntegrationWebhookEvent::STATUS_IGNORED, 'processed_at' => now(), 'context' => $this->mergeContext($event, $context), ])->save(); return $event; } /** * @param array $context */ public function markFailed(IntegrationWebhookEvent $event, string $message, array $context = []): IntegrationWebhookEvent { $event->forceFill([ 'status' => IntegrationWebhookEvent::STATUS_FAILED, 'failed_at' => now(), 'error_message' => Str::limit($message, 500, ''), 'context' => $this->mergeContext($event, $context), ])->save(); return $event; } /** * @param array $context * @return array */ private function mergeContext(IntegrationWebhookEvent $event, array $context): array { $existing = $event->context ?? []; if (! is_array($existing)) { $existing = []; } return array_merge($existing, $context); } }