Add coupon fraud context and analytics tracking
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-02 23:31:26 +01:00
parent 75d862748b
commit 41ed682fbe
16 changed files with 461 additions and 21 deletions

View File

@@ -32,6 +32,9 @@ class CheckoutSessionService
if ($existing) {
$this->refreshExpiration($existing);
if ($this->applyRequestContext($existing, $context)) {
$existing->save();
}
return $existing;
}
@@ -50,6 +53,7 @@ class CheckoutSessionService
$session->locale = $context['locale'] ?? app()->getLocale();
$session->expires_at = now()->addMinutes($this->sessionTtlMinutes);
$session->status_history = [];
$this->applyRequestContext($session, $context);
$this->appendStatus($session, CheckoutSession::STATUS_DRAFT, 'session_created');
$session->save();
@@ -218,6 +222,27 @@ class CheckoutSessionService
$session->status_history = $history;
}
protected function applyRequestContext(CheckoutSession $session, array $context): bool
{
$updated = false;
foreach (['ip_address', 'device_id', 'user_agent'] as $key) {
if (! array_key_exists($key, $context)) {
continue;
}
$value = $context[$key];
if (! is_string($value) || $value === '') {
continue;
}
$session->{$key} = $value;
$updated = true;
}
return $updated;
}
protected function packageSnapshot(Package $package): array
{
return [