- score(order) → FraudScore (score 0-100, signals[], recommendation) - flag(order, reason) → void (marks for review) - block(order, reason) → void (rejects order) - reviewQueue() → Collection<Order> - approve(order) → void Data/FraudScore.php as readonly DTO. Pest tests _Good/_Bad/_Ugly per AX-10 for all 5 methods. pint/pest skipped (vendor binaries missing). Co-authored-by: Codex <noreply@openai.com> Closes tasks.lthn.sh/view.php?id=859
39 lines
1,009 B
PHP
39 lines
1,009 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Mod\Commerce\Data;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
/**
|
|
* Order-level fraud score for manual review and blocking decisions.
|
|
*/
|
|
readonly class FraudScore
|
|
{
|
|
public function __construct(
|
|
public int $score,
|
|
public array $signals,
|
|
public string $recommendation,
|
|
) {
|
|
if ($this->score < 0 || $this->score > 100) {
|
|
throw new InvalidArgumentException('Fraud score must be between 0 and 100.');
|
|
}
|
|
|
|
if (! in_array($this->recommendation, ['approve', 'review', 'block'], true)) {
|
|
throw new InvalidArgumentException('Fraud recommendation must be approve, review, or block.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array{score: int, signals: array, recommendation: string}
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'score' => $this->score,
|
|
'signals' => $this->signals,
|
|
'recommendation' => $this->recommendation,
|
|
];
|
|
}
|
|
}
|