Reorden Toku
This commit is contained in:
105
app/src/Service/Venta/MediosPago/Toku/Subscription.php
Normal file
105
app/src/Service/Venta/MediosPago/Toku/Subscription.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta\MediosPago\Toku;
|
||||
|
||||
use Incoviba\Model\Venta;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service\Venta\MediosPago\AbstractEndPoint;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
|
||||
class Subscription extends AbstractEndPoint
|
||||
{
|
||||
public function __construct(ClientInterface $client, protected Repository\Venta\MediosPago\Toku\Subscription $subscriptionRepsitory)
|
||||
{
|
||||
parent::__construct($client);
|
||||
}
|
||||
|
||||
public function getById(string $id): array
|
||||
{
|
||||
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}";
|
||||
return $this->sendGet($request_uri, [200], [401, 404, 422]);
|
||||
}
|
||||
public function add(array $data): bool
|
||||
{
|
||||
$request_uri = '/subscriptions';
|
||||
return $this->sendAdd($request_uri, $data, [200, 201], [401, 404, 409, 422]);
|
||||
}
|
||||
public function edit(string $id, array $data): bool
|
||||
{
|
||||
$request_uri = "/subscriptions/{$id}";
|
||||
return $this->sendEdit($request_uri, $data, [200], [401, 404, 409, 422]);
|
||||
}
|
||||
public function delete(string $id): void
|
||||
{
|
||||
$request_uri = "/subscriptions/{$id}";
|
||||
$this->sendDelete($request_uri, [204], [404, 409]);
|
||||
}
|
||||
|
||||
protected function save(array $data): bool
|
||||
{
|
||||
return $this->doSave($this->subscriptionRepsitory, $data);
|
||||
}
|
||||
protected function mapParams(array $data): array
|
||||
{
|
||||
$paramsMap = [
|
||||
'customer' => 'customer',
|
||||
'product_id' => 'product_id',
|
||||
'pac_mandate_id' => null,
|
||||
'is_recurring' => null,
|
||||
'due_day' => null,
|
||||
'amount' => 'pieValor',
|
||||
'receipt_product_code' => null,
|
||||
'metadata' => 'datosVenta'
|
||||
];
|
||||
|
||||
$params = [];
|
||||
foreach ($paramsMap as $key => $ref) {
|
||||
if ($ref === null) {
|
||||
continue;
|
||||
}
|
||||
if ($ref === 'pieValor') {
|
||||
$params[$key] = $data['venta']->formaPago()?->pie?->valor ?? 0;
|
||||
continue;
|
||||
}
|
||||
if ($ref === 'datosVenta') {
|
||||
$params[$key] = $this->datosVenta($data['venta']);
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($ref, $data)) {
|
||||
$params[$key] = $data[$ref];
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
protected function mapSave(array $data): array
|
||||
{
|
||||
$responseMap = [
|
||||
'product_id' => 'venta_id',
|
||||
'id' => 'toku_id'
|
||||
];
|
||||
$mappedData = [];
|
||||
foreach ($responseMap as $responseKey => $dataKey) {
|
||||
if (isset($data[$responseKey])) {
|
||||
$mappedData[$dataKey] = $data[$responseKey];
|
||||
}
|
||||
}
|
||||
return $mappedData;
|
||||
}
|
||||
protected function datosVenta(Venta $venta): string
|
||||
{
|
||||
$datos = [
|
||||
'proyecto' => $venta->proyecto()->descripcion,
|
||||
'propiedad' => $venta->propiedad()->summary()
|
||||
];
|
||||
return json_encode($datos);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user