From 403caf77f5f09b0a6861503b1d3db67d6e567424 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Mon, 6 Jul 2026 09:01:45 -0300 Subject: [PATCH] feat: add getCashinDetails method to TelepagosIntegrationService and corresponding tests --- .../Services/TelepagosIntegrationService.php | 16 +++ .../Integration/IntegrationServiceTest.php | 111 ++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/app/Domains/Integration/Services/TelepagosIntegrationService.php b/app/Domains/Integration/Services/TelepagosIntegrationService.php index d0c7317..0440e60 100644 --- a/app/Domains/Integration/Services/TelepagosIntegrationService.php +++ b/app/Domains/Integration/Services/TelepagosIntegrationService.php @@ -130,6 +130,22 @@ class TelepagosIntegrationService extends BaseIntegrationService ]); } + /** + * Get the details of a cash-in payment. + * + * @param int $cashinId + * @return array + * @throws Exception + */ + public function getCashinDetails(int $cashinId): array + { + $response = $this->client()->get("/v2/payment/cashin/{$cashinId}"); + + return $this->handleResponse($response, 'get cash-in details', [ + 'cashin_id' => $cashinId, + ]); + } + /** * Handle the Telepagos API response, logging any failures and throwing Exceptions. * diff --git a/tests/Feature/Integration/IntegrationServiceTest.php b/tests/Feature/Integration/IntegrationServiceTest.php index 60527ba..54a24b9 100644 --- a/tests/Feature/Integration/IntegrationServiceTest.php +++ b/tests/Feature/Integration/IntegrationServiceTest.php @@ -411,4 +411,115 @@ class IntegrationServiceTest extends TestCase $service->generateQr(1200.00, 'Test Concept', 'Test Description'); } + + public function test_it_gets_cashin_details(): void + { + Integration::create([ + 'integration_code' => 'telepagos_homo', + 'name' => 'Telepagos', + 'url' => 'https://api.telepagos.com.ar', + 'integration_data_schema' => [ + 'username' => 'required|string', + 'password' => 'required|string', + ] + ]); + + TenantIntegration::create([ + 'tenant_code' => $this->tenant->codigo, + 'integration_code' => 'telepagos_homo', + 'integration_data' => [ + 'username' => 'tele_user', + 'password' => 'tele_pass', + ] + ]); + + Http::fake([ + 'https://api.telepagos.com.ar/v2/auth/token' => Http::response([ + 'status' => 'ok', + 'token' => 'mock-jwt-token-123', + 'expires_at' => now()->addHour()->toDateTimeString() + ], 200), + 'https://api.telepagos.com.ar/v2/payment/cashin/6351' => Http::response([ + 'status' => 'ok', + 'buyer' => [ + 'cuit' => '20416561398', + 'cvu' => '0000124900000000011974' + ], + 'amount' => 1200, + 'concept' => 'VAR', + 'operation' => 'QR Telepagos', + 'operation_id' => 37, + 'description' => 'Pago prueba', + 'transaction_id' => '2026070364', + 'qr_order_id' => 6351, + 'link_id' => null + ], 200) + ]); + + $service = new TelepagosIntegrationService('telepagos'); + $service->forTenant($this->tenant->codigo); + + $result = $service->getCashinDetails(6351); + + $this->assertEquals('ok', $result['status']); + $this->assertEquals(1200, $result['amount']); + $this->assertEquals('VAR', $result['concept']); + $this->assertEquals(6351, $result['qr_order_id']); + + Http::assertSent(function ($request) { + return $request->hasHeader('Authorization', 'Bearer mock-jwt-token-123') + && $request->url() === 'https://api.telepagos.com.ar/v2/payment/cashin/6351' + && $request->method() === 'GET'; + }); + } + + public function test_it_logs_and_throws_exception_on_get_cashin_details_error(): void + { + Integration::create([ + 'integration_code' => 'telepagos_homo', + 'name' => 'Telepagos', + 'url' => 'https://api.telepagos.com.ar', + 'integration_data_schema' => [ + 'username' => 'required|string', + 'password' => 'required|string', + ] + ]); + + TenantIntegration::create([ + 'tenant_code' => $this->tenant->codigo, + 'integration_code' => 'telepagos_homo', + 'integration_data' => [ + 'username' => 'tele_user', + 'password' => 'tele_pass', + ] + ]); + + Http::fake([ + 'https://api.telepagos.com.ar/v2/auth/token' => Http::response([ + 'status' => 'ok', + 'token' => 'mock-jwt-token-123', + 'expires_at' => now()->addHour()->toDateTimeString() + ], 200), + 'https://api.telepagos.com.ar/v2/payment/cashin/6351' => Http::response([ + 'status' => 'error', + 'message' => 'Cashin no encontrado' + ], 404) + ]); + + \Illuminate\Support\Facades\Log::shouldReceive('error') + ->once() + ->with('Telepagos get cash-in details failed: Cashin no encontrado', \Mockery::on(function ($context) { + return $context['cashin_id'] === 6351 + && $context['response_status'] === 404 + && $context['response_body'] === ['status' => 'error', 'message' => 'Cashin no encontrado']; + })); + + $service = new TelepagosIntegrationService('telepagos'); + $service->forTenant($this->tenant->codigo); + + $this->expectException(Exception::class); + $this->expectExceptionMessage("Telepagos get cash-in details failed: Cashin no encontrado"); + + $service->getCashinDetails(6351); + } }