feat(purchase): add expiration time calculations to PurchaseResource and implement related tests

This commit is contained in:
2026-08-26 17:00:17 -03:00
parent 05944cec9c
commit daa74845b7
2 changed files with 76 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ class PurchaseResource extends JsonResource
*/
public function toArray(Request $request): array
{
$serverTime = now();
$expiresAt = $this->stockReservation?->expires_at;
$items = $this->resource->relationLoaded('items')
? $this->resource->getRelation('items')
: collect();
@@ -48,7 +50,11 @@ class PurchaseResource extends JsonResource
'created_at' => $this->created_at,
'status' => $this->status,
'payment_method' => $this->payment_method,
'expires_at' => $this->stockReservation?->expires_at,
'expires_at' => $expiresAt,
'expires_in_seconds' => $expiresAt === null
? null
: max(0, $expiresAt->getTimestamp() - $serverTime->getTimestamp()),
'server_time' => $serverTime,
'dni' => $this->dni,
'transfer_payer_dni' => $this->transfer_payer_dni,
'telefono' => $this->telefono,