FIX: Cambios a Servicios Toku
This commit is contained in:
@ -17,6 +17,10 @@ class Customer extends AbstractEndPoint
|
||||
{
|
||||
return $this->doGetById([$this->customerRepository, 'fetchByRut'], $id, "No existe toku_id para Persona {$id}");
|
||||
}
|
||||
public function getByExternalId(string $id): array
|
||||
{
|
||||
return $this->doGetById([$this->customerRepository, 'fetchByTokuId'], $id, "No existe Customer para toku_id {$id}");
|
||||
}
|
||||
public function get(string $id): array
|
||||
{
|
||||
$request_uri = "/customers/{$id}";
|
||||
|
@ -1,14 +1,22 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\MediosPago\Toku;
|
||||
|
||||
use Incoviba\Model\Venta\Cuota;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Incoviba\Exception\InvalidResult;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service\MediosPago\AbstractEndPoint;
|
||||
use Incoviba\Service\UF;
|
||||
use Incoviba\Service\Venta\Pago;
|
||||
|
||||
class Invoice extends AbstractEndPoint
|
||||
{
|
||||
public function __construct(ClientInterface $client, protected Repository\MediosPago\Toku\Invoice $invoiceRepository)
|
||||
public function __construct(ClientInterface $client,
|
||||
protected Repository\MediosPago\Toku\Invoice $invoiceRepository,
|
||||
protected Pago $pagoService, protected UF $ufService)
|
||||
{
|
||||
parent::__construct($client);
|
||||
}
|
||||
@ -17,6 +25,10 @@ class Invoice extends AbstractEndPoint
|
||||
{
|
||||
return $this->doGetById([$this->invoiceRepository, 'fetchByCuota'], $id, "No existe toku_id para Cuota {$id}");
|
||||
}
|
||||
public function getByExternalId(string $id): array
|
||||
{
|
||||
return $this->doGetById([$this->invoiceRepository, 'fetchByTokuId'], $id, "No existe Invoice para toku_id {$id}");
|
||||
}
|
||||
public function get(string $id): array
|
||||
{
|
||||
$request_uri = "/invoices/{$id}";
|
||||
@ -38,6 +50,38 @@ class Invoice extends AbstractEndPoint
|
||||
$this->sendDelete($request_uri, [204], [404, 409]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $invoice_toku_id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws InvalidResult
|
||||
*/
|
||||
public function update(string $invoice_toku_id, array $data): bool
|
||||
{
|
||||
try {
|
||||
$invoice = $this->invoiceRepository->fetchByTokuId($invoice_toku_id);
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new InvalidResult("No existe Invoice para toku_id {$invoice_toku_id}", 404, $exception);
|
||||
}
|
||||
if ($data['status'] !== 'AUTHORIZED') {
|
||||
throw new InvalidResult("Pago no autorizado", 422);
|
||||
}
|
||||
try {
|
||||
$date = new DateTimeImmutable($data['transaction_date']);
|
||||
} catch (DateMalformedStringException $exception) {
|
||||
throw new InvalidResult("Fecha no válida: {$data['transaction_date']}", 422, $exception);
|
||||
}
|
||||
$uf = $this->ufService->get($date);
|
||||
if ($uf === 0.0) {
|
||||
throw new InvalidResult("No hay UF para la fecha: {$data['transaction_date']}", 422);
|
||||
}
|
||||
$valor = $data['amount'] / $uf;
|
||||
if (abs($valor - $invoice->cuota->pago->valor()) >= 0.0001) {
|
||||
throw new InvalidResult("Valor en UF no coincide: {$data['amount']}", 422);
|
||||
}
|
||||
return $this->pagoService->depositar($invoice->cuota->pago, $date);
|
||||
}
|
||||
|
||||
protected function save(array $data): bool
|
||||
{
|
||||
return $this->doSave($this->invoiceRepository, $data);
|
||||
@ -71,7 +115,7 @@ class Invoice extends AbstractEndPoint
|
||||
continue;
|
||||
}
|
||||
if ($ref === 'valor') {
|
||||
$params[$key] = $data['cuota']->pago->valor;
|
||||
$params[$key] = $data['cuota']->pago->valor();
|
||||
continue;
|
||||
}
|
||||
if ($ref === 'datosCuota') {
|
||||
@ -104,7 +148,7 @@ class Invoice extends AbstractEndPoint
|
||||
return $mappedData;
|
||||
}
|
||||
|
||||
protected function datosCuota(Cuota $cuota): string
|
||||
protected function datosCuota(Model\Venta\Cuota $cuota): string
|
||||
{
|
||||
return json_encode([
|
||||
'Numero' => $cuota->numero,
|
||||
|
@ -17,6 +17,11 @@ class Subscription extends AbstractEndPoint
|
||||
{
|
||||
return $this->doGetById([$this->subscriptionRepsitory, 'fetchByVenta'], $id, "No existe toku_id para Venta {$id}");
|
||||
}
|
||||
public function getByExternalId(string $id): array
|
||||
{
|
||||
return $this->doGetById([$this->subscriptionRepsitory, 'fetchByTokuId'], $id, "No existe Subscription para toku_id {$id}");
|
||||
}
|
||||
|
||||
public function get(string $id): array
|
||||
{
|
||||
$request_uri = "/subscriptions/{$id}";
|
||||
|
Reference in New Issue
Block a user