FIX: Check if invoice exists before sending, if exists then save

Send correct UF amount if date in future
This commit is contained in:
Juan Pablo Vial
2025-05-16 14:36:20 -04:00
parent 8ba54fd3ad
commit 8ce7d2570d
5 changed files with 45 additions and 12 deletions

View File

@ -42,7 +42,7 @@ class Customer extends AbstractEndPoint
$this->sendDelete($request_uri, [204], [404, 409]);
}
protected function save(array $data): bool
public function save(array $data): bool
{
return $this->doSave($this->customerRepository, $data);
}

View File

@ -3,6 +3,8 @@ namespace Incoviba\Service\Venta\MediosPago\Toku;
use DateMalformedStringException;
use DateTimeImmutable;
use Psr\Http\Client\ClientInterface;
use Incoviba\Common\Implement\Exception\EmptyResponse;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\InvalidResult;
use Incoviba\Model;
@ -10,7 +12,6 @@ use Incoviba\Repository;
use Incoviba\Service\UF;
use Incoviba\Service\Venta\MediosPago\AbstractEndPoint;
use Incoviba\Service\Venta\Pago;
use Psr\Http\Client\ClientInterface;
class Invoice extends AbstractEndPoint
{
@ -50,6 +51,17 @@ class Invoice extends AbstractEndPoint
$this->sendDelete($request_uri, [204], [404, 409]);
}
/**
* @param string $customer_id
* @return array
* @throws EmptyResponse
*/
public function getByCustomer(string $customer_id): array
{
$request_uri = "/invoices/customer/{$customer_id}";
return $this->sendGet($request_uri, [200], [404]);
}
/**
* @param string $invoice_toku_id
* @param array $data
@ -89,7 +101,7 @@ class Invoice extends AbstractEndPoint
return $this->pagoService->depositar($invoice->cuota->pago, $date);
}
protected function save(array $data): bool
public function save(array $data): bool
{
return $this->doSave($this->invoiceRepository, $data);
}
@ -122,7 +134,11 @@ class Invoice extends AbstractEndPoint
continue;
}
if ($ref === 'valor') {
$params[$key] = $data['cuota']->pago->valor();
$valor = $data['cuota']->pago->valor();
if ($valor === 0) {
$valor = $data['cuota']->pago->valor / $data['venta']->uf;
}
$params[$key] = $valor;
continue;
}
if ($ref === 'datosCuota') {

View File

@ -70,7 +70,7 @@ class Subscription extends AbstractEndPoint
return compact('existingSubscriptions', 'missingVentas');
}
protected function save(array $data): bool
public function save(array $data): bool
{
return $this->doSave($this->subscriptionRepsitory, $data);
}