feat: add QR code generation and response handling to TelepagosIntegrationService with logging for errors
This commit is contained in:
@@ -239,6 +239,14 @@ class IntegrationServiceTest extends TestCase
|
||||
], 401)
|
||||
]);
|
||||
|
||||
\Illuminate\Support\Facades\Log::shouldReceive('error')
|
||||
->once()
|
||||
->with('Telepagos authentication failed: Invalid credentials', \Mockery::on(function ($context) {
|
||||
return $context['username'] === 'tele_user'
|
||||
&& $context['response_status'] === 401
|
||||
&& $context['response_body'] === ['status' => 'error', 'message' => 'Invalid credentials'];
|
||||
}));
|
||||
|
||||
$service = new TelepagosIntegrationService('telepagos');
|
||||
$service->forTenant($this->tenant->codigo);
|
||||
|
||||
@@ -299,4 +307,108 @@ class IntegrationServiceTest extends TestCase
|
||||
&& $request->url() === 'https://api.telepagos.com.ar/v1/payments';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_it_generates_qr_code(): 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/qr/generate' => Http::response([
|
||||
'status' => 'ok',
|
||||
'qr_code' => 'mock-qr-code-data',
|
||||
'qr_order_id' => 6353
|
||||
], 200)
|
||||
]);
|
||||
|
||||
$service = new TelepagosIntegrationService('telepagos');
|
||||
$service->forTenant($this->tenant->codigo);
|
||||
|
||||
$result = $service->generateQr(1200.00, 'Test Concept', 'Test Description');
|
||||
|
||||
$this->assertEquals('ok', $result['status']);
|
||||
$this->assertEquals('mock-qr-code-data', $result['qr_code']);
|
||||
$this->assertEquals(6353, $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/qr/generate'
|
||||
&& $request['amount'] === 1200.00
|
||||
&& $request['concept'] === 'Test Concept'
|
||||
&& $request['description'] === 'Test Description';
|
||||
});
|
||||
}
|
||||
|
||||
public function test_it_logs_and_throws_exception_on_generate_qr_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/qr/generate' => Http::response([
|
||||
'status' => 'error',
|
||||
'message' => 'Importe inválido'
|
||||
], 422)
|
||||
]);
|
||||
|
||||
\Illuminate\Support\Facades\Log::shouldReceive('error')
|
||||
->once()
|
||||
->with('Telepagos QR generation failed: Importe inválido', \Mockery::on(function ($context) {
|
||||
return $context['amount'] === 1200.00
|
||||
&& $context['concept'] === 'Test Concept'
|
||||
&& $context['description'] === 'Test Description'
|
||||
&& $context['response_status'] === 422
|
||||
&& $context['response_body'] === ['status' => 'error', 'message' => 'Importe inválido'];
|
||||
}));
|
||||
|
||||
$service = new TelepagosIntegrationService('telepagos');
|
||||
$service->forTenant($this->tenant->codigo);
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Telepagos QR generation failed: Importe inválido");
|
||||
|
||||
$service->generateQr(1200.00, 'Test Concept', 'Test Description');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user