This commit is contained in:
Juan Pablo Vial
2025-05-19 16:06:44 -04:00
parent f34ed03b84
commit 3b03c4b64b
2 changed files with 6 additions and 0 deletions

View File

@ -156,6 +156,7 @@ class Toku extends Ideal\Service
$validEvents = ['payment_intent.succeeded', 'payment.succeeded', 'transaction.success',
'transaction.bulk_success', 'payment_intent.succeeded_batch'];
if (!in_array($input['event_type'], $validEvents)) {
$this->logger->warning("{$input['event_type']} is not a valid event");
throw new InvalidResult("{$input['event_type']} is not a valid event", 422);
}
switch ($input['event_type']) {

View File

@ -74,19 +74,23 @@ class Invoice extends AbstractEndPoint
try {
$invoice = $this->invoiceRepository->fetchByTokuId($invoice_toku_id);
} catch (EmptyResult $exception) {
$this->logger->warning($exception, ['invoice_toku_id' => $invoice_toku_id, 'data' => $data]);
throw new InvalidResult("No existe Invoice para toku_id {$invoice_toku_id}", 404, $exception);
}
if ($data['status'] !== 'AUTHORIZED') {
$this->logger->warning("Pago no autorizado", ['invoice_toku_id' => $invoice_toku_id, 'data' => $data]);
throw new InvalidResult("Pago no autorizado", 422);
}
$dateString = $data['date'];
try {
$date = new DateTimeImmutable($dateString);
} catch (DateMalformedStringException $exception) {
$this->logger->warning($exception, ['invoice_toku_id' => $invoice_toku_id, 'data' => $data]);
throw new InvalidResult("Fecha no válida: {$dateString}", 422, $exception);
}
$uf = $this->ufService->get($date);
if ($uf === 0.0) {
$this->logger->warning("No hay UF para la fecha: {$dateString}", ['invoice_toku_id' => $invoice_toku_id, 'data' => $data]);
throw new InvalidResult("No hay UF para la fecha: {$dateString}", 422);
}
$valor = $data['amount'];
@ -94,6 +98,7 @@ class Invoice extends AbstractEndPoint
$valor = $data['amount'] / $uf;
}
if (abs($valor - $invoice->cuota->pago->valor()) >= 0.0001) {
$this->logger->warning("Valor en UF no coincide: {$data['amount']}, {$valor} <=> {$invoice->cuota->pago->valor()}", ['invoice_toku_id' => $invoice_toku_id, 'data' => $data]);
throw new InvalidResult("Valor en UF no coincide: {$data['amount']}, {$valor} <=> {$invoice->cuota->pago->valor()}", 422);
}
if ($invoice->cuota->pago->isPagado()) {