diff --git a/app/src/Repository/MediosPago/Toku/Customer.php b/app/src/Repository/MediosPago/Toku/Customer.php new file mode 100644 index 0000000..dd4b9d8 --- /dev/null +++ b/app/src/Repository/MediosPago/Toku/Customer.php @@ -0,0 +1,68 @@ +register('rut', (new Implement\Repository\Mapper()) + ->setProperty('persona') + ->setFunction(function($data) { + $rut = (int) substr($data['rut'], 0, -1); + return $this->personaService->getById($rut); + }) + ); + return $this->parseData(new Model\MediosPago\Toku\Customer(), $data, $map); + } + public function save(Define\Model $model): Model\MediosPago\Toku\Customer + { + $model->id = $this->saveNew( + ['rut', 'toku_id', 'created_at'], + [implode('', [$model->persona->rut, $model->persona->digito]), $model->toku_id, (new DateTimeImmutable())->format('Y-m-d H:i:s.u')] + ); + return $model; + } + public function edit(Define\Model $model, array $new_data): Model\MediosPago\Toku\Customer + { + return $this->update($model, ['rut', 'toku_id', 'updated_at'], array_merge($new_data, ['updated_at' => (new DateTimeImmutable())->format('Y-m-d H:i:s.u')])); + } + + /** + * @param string $rut + * @return Model\MediosPago\Toku\Customer + * @throws Implement\Exception\EmptyResult + */ + public function fetchByRut(string $rut): Model\MediosPago\Toku\Customer + { + if (str_contains($rut, '-')) { + $rut = str_replace('-', '', $rut); + } + if (str_contains($rut, '.')) { + $rut = str_replace('.', '', $rut); + } + $rut = strtoupper($rut); + $query = $this->connection->getQueryBuilder() + ->select() + ->from($this->getTable()) + ->where('rut = :rut'); + return $this->fetchOne($query, compact('rut')); + } +} diff --git a/app/src/Repository/MediosPago/Toku/Invoice.php b/app/src/Repository/MediosPago/Toku/Invoice.php new file mode 100644 index 0000000..1a7354b --- /dev/null +++ b/app/src/Repository/MediosPago/Toku/Invoice.php @@ -0,0 +1,53 @@ +register('cuota_id', (new Implement\Repository\Mapper()) + ->setProperty('cuota') + ->setFunction(function($data) { + return $this->cuotaRepository->fetchById($data['cuota_id']); + })); + return $this->parseData(new Model\MediosPago\Toku\Invoice(), $data, $map); + } + public function save(Define\Model $model): Model\MediosPago\Toku\Invoice + { + $model->id = $this->saveNew( + ['cuota_id', 'toku_id', 'created_at'], + [$model->cuota->id, $model->toku_id, (new DateTimeImmutable())->format('Y-m-d H:i:s.u')] + ); + return $model; + } + public function edit(Define\Model $model, array $new_data): Model\MediosPago\Toku\Invoice + { + return $this->update($model, ['cuota_id', 'toku_id', 'updated_at'], array_merge($new_data, ['updated_at' => (new DateTimeImmutable())->format('Y-m-d H:i:s.u')])); + } + + public function fetchByCuota(int $cuota_id): Model\MediosPago\Toku\Invoice + { + $query = $this->connection->getQueryBuilder() + ->select() + ->from($this->getTable()) + ->where('cuota_id = :cuota_id'); + return $this->fetchOne($query, compact('cuota_id')); + } +} diff --git a/app/src/Repository/MediosPago/Toku/Subscription.php b/app/src/Repository/MediosPago/Toku/Subscription.php new file mode 100644 index 0000000..d005548 --- /dev/null +++ b/app/src/Repository/MediosPago/Toku/Subscription.php @@ -0,0 +1,54 @@ +register('venta_id', (new Implement\Repository\Mapper()) + ->setProperty('venta') + ->setFunction(function($data) { + return $this->ventaRepository->fetchById($data['venta_id']); + })); + return $this->parseData(new Model\MediosPago\Toku\Subscription(), $data, $map); + } + public function save(Define\Model $model): Model\MediosPago\Toku\Subscription + { + $model->id = $this->saveNew( + ['venta_id', 'toku_id', 'created_at'], + [$model->venta->id, $model->toku_id, (new DateTimeImmutable())->format('Y-m-d H:i:s.u')] + ); + return $model; + } + public function edit(Define\Model $model, array $new_data): Model\MediosPago\Toku\Subscription + { + return $this->update($model, ['venta_id', 'toku_id', 'updated_at'], array_merge($new_data, ['updated_at' => (new DateTimeImmutable())->format('Y-m-d H:i:s.u')])); + } + + public function fetchByVenta(int $venta_id): Model\MediosPago\Toku\Subscription + { + $query = $this->connection->getQueryBuilder() + ->select() + ->from($this->getTable()) + ->where('venta_id = :venta_id'); + return $this->fetchOne($query, compact('venta_id')); + } +}