ldc-legaulois/tests/Unit/Lib/Axepta/AxeptaPaymentServiceTest.php
2026-09-25 16:25:31 +02:00

79 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Lib\Axepta;
use App\Lib\Axepta\AxeptaApiGateway;
use App\Lib\Axepta\AxeptaConfig;
use App\Lib\Axepta\AxeptaPaymentService;
use App\Lib\Axepta\AxeptaSignatureVerifier;
use App\Lib\Axepta\AxeptaTokenManager;
use GuzzleHttp\Psr7\Response;
use Illuminate\Http\Request;
use Psr\Log\LoggerInterface;
use Tests\TestCase;
class AxeptaPaymentServiceTest extends TestCase
{
private LoggerInterface $logger;
private AxeptaConfig $config;
private AxeptaApiGateway $gateway;
private AxeptaTokenManager $tokenManager;
private AxeptaSignatureVerifier $verifier;
protected function setUp(): void
{
parent::setUp();
$this->logger = $this->createMock(LoggerInterface::class);
$this->config = new AxeptaConfig('url', 'm_id', 'key', 'hmac', []);
$this->gateway = $this->createMock(AxeptaApiGateway::class);
$this->tokenManager = $this->createMock(AxeptaTokenManager::class);
$this->verifier = $this->createMock(AxeptaSignatureVerifier::class);
}
public function test_can_get_payment_status_by_id(): void
{
// GIVEN
$service = new AxeptaPaymentService($this->logger, $this->config, $this->gateway, $this->tokenManager, $this->verifier);
$this->tokenManager->method('getToken')->willReturn('fake-token');
$jsonResponse = json_encode(['responseCode' => 'SUCCESS']);
$this->gateway->expects($this->once())
->method('get')
->willReturn(new Response(200, [], $jsonResponse));
// WHEN
$status = $service->getPaymentStatusById('PAY_123');
// THEN
$this->assertEquals('SUCCESS', $status);
}
public function test_can_validate_webhook_access(): void
{
// GIVEN
$service = new AxeptaPaymentService($this->logger, $this->config, $this->gateway, $this->tokenManager, $this->verifier);
$request = Request::create('/webhook', 'POST', [], [], [], [
'HTTP_X_PAYGATE_SIGNATURE_VERSION' => 'v1',
'HTTP_X_PAYGATE_SIGNATURE' => 'v1=abc123hex',
'HTTP_X_PAYGATE_TIMESTAMP' => '1600000000',
], '{"payload":true}');
$this->verifier->expects($this->once())
->method('verify')
->with('v1', 'v1=abc123hex', '1600000000', '{"payload":true}')
->willReturn(true);
// WHEN
$isValid = $service->isValidWebhookAccess($request);
// THEN
$this->assertTrue($isValid);
}
}