diff --git a/app/src/Controller/API/Ventas/MediosPago/Toku.php b/app/src/Controller/API/Ventas/MediosPago/Toku.php new file mode 100644 index 0000000..8f2f9ae --- /dev/null +++ b/app/src/Controller/API/Ventas/MediosPago/Toku.php @@ -0,0 +1,64 @@ +getParsedBody(); + $output = [ + 'input' => $input, + 'venta_id' => $venta_id, + 'cuotas' => [], + 'success' => false, + 'partial' => false, + ]; + try { + $venta = $ventaService->getById($venta_id); + $cuotas = $tokuService->sendCuotas($venta, $input['cuotas']); + $output['cuotas'] = array_map(function($row) { return $row['cuota_id']; }, $cuotas); + if (count($cuotas) < count($input['cuotas'])) { + $output['partial'] = true; + } else { + $output['success'] = true; + } + } catch (Read | InvalidResult) {} + return $this->withJson($response, $output); + } + public function success(ServerRequestInterface $request, ResponseInterface $response, + ResponseFactoryInterface $responseFactory, + Service\MediosPago\Toku $tokuService): ResponseInterface + { + $body = $request->getBody(); + $input = json_decode($body->getContents(), true); + try { + if ($tokuService->updatePago($input['payment_intent'])) { + return $responseFactory->createResponse(204); + } + return $responseFactory->createResponse(409, 'Payment could not be updated'); + } catch (InvalidResult $exception) { + $this->logger->warning($exception); + if (str_contains($exception->getMessage(), 'Customer')) { + $message = 'Customer not found'; + } elseif (str_contains($exception->getMessage(), 'Invoice')) { + $message = 'Invoice not found'; + } else { + $message = $exception->getMessage(); + } + return $responseFactory->createResponse($exception->getCode(), $message); + } + } +}