fix(purchase): unify expired checkout errors

This commit is contained in:
2026-08-20 17:01:06 -03:00
parent ae6149df84
commit 9fd34f900f
11 changed files with 174 additions and 18 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Domains\Purchase\Services;
use App\Domains\Purchase\Exceptions\PurchaseExpiredException;
use App\Domains\Purchase\Models\Purchase;
class PurchaseStateGuard
{
public function assertNotExpired(Purchase $purchase): void
{
$hasExpiredStatus = $purchase->status === Purchase::STATUS_EXPIRED;
$hasExpiredByTime = in_array($purchase->status, [
Purchase::STATUS_CREATED,
Purchase::STATUS_PENDING_PAYMENT,
], true)
&& $purchase->expires_at !== null
&& $purchase->expires_at->isPast();
if ($hasExpiredStatus || $hasExpiredByTime) {
throw new PurchaseExpiredException;
}
}
}