This commit is contained in:
Juan Pablo Vial
2025-05-12 19:46:09 -04:00
parent 3006adb0f7
commit f14cdd2730
10 changed files with 268 additions and 21 deletions

View File

@ -66,14 +66,15 @@ class Invoice extends AbstractEndPoint
if ($data['status'] !== 'AUTHORIZED') {
throw new InvalidResult("Pago no autorizado", 422);
}
$dateString = $data['date'];
try {
$date = new DateTimeImmutable($data['transaction_date']);
$date = new DateTimeImmutable($dateString);
} catch (DateMalformedStringException $exception) {
throw new InvalidResult("Fecha no válida: {$data['transaction_date']}", 422, $exception);
throw new InvalidResult("Fecha no válida: {$dateString}", 422, $exception);
}
$uf = $this->ufService->get($date);
if ($uf === 0.0) {
throw new InvalidResult("No hay UF para la fecha: {$data['transaction_date']}", 422);
throw new InvalidResult("No hay UF para la fecha: {$dateString}", 422);
}
$valor = $data['amount'] / $uf;
if (abs($valor - $invoice->cuota->pago->valor()) >= 0.0001) {