From 90ff69dca92dbfabae63f8fe4d0f3ea3a61dcf23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Lucas?= Date: Thu, 22 Oct 2026 17:01:08 -0300 Subject: [PATCH] PHPAY-109: test(support): cover StaticPixCode in the 8.1 smoke test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The smoke test of the minimum supported version exercised Money and Customer but not the value object added in PHPAY-109, so its behaviour on PHP 8.1 rested on the phpVersion of PHPStan rather than on running. The Pest suite cannot fill that gap: the dev toolchain needs 8.2+, which is the whole reason the smoke test exists. Three checks: the test vector of the BACEN manual byte for byte, the amount and txid fields, and the two refusals. The vector is the one that matters — a CRC that stops before the 6304 literal gives 4AAD instead of 1D3D and produces a QR Code that does not read, and that would now fail the 8.1 job rather than reach a payer. --- .github/scripts/smoke.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/scripts/smoke.php b/.github/scripts/smoke.php index 326e039..8932c0c 100644 --- a/.github/scripts/smoke.php +++ b/.github/scripts/smoke.php @@ -45,7 +45,7 @@ use PHPay\PagBank\PagBankGateway; use PHPay\PHPay; use PHPay\Rede\RedeGateway; -use PHPay\Support\{Customer, Money}; +use PHPay\Support\{Customer, Money, StaticPixCode}; use PHPay\Woovi\WooviGateway; /** @var list $failures */ @@ -245,6 +245,40 @@ function () use ($phpay, $accessor, $declared, $ensure, $expect): void { $ensure($customer->phoneParts() !== null, 'phoneParts() não deveria ser nulo'); }); +$check('StaticPixCode: reproduz o vetor de teste do manual do BACEN', function () use ($ensure): void { + /* + * byte a byte, porque é o único jeito de provar o CRC: ele cobre o + * literal `6304` que o anuncia, e parar antes dele dá 4AAD em vez de + * 1D3D — um QR Code que simplesmente não lê. + */ + $esperado = '00020126580014br.gov.bcb.pix0136123e4567-e12b-12d1-a456-' + . '4266554400005204000053039865802BR5913Fulano de Tal6008BRASILIA62070503***63041D3D'; + + $payload = StaticPixCode::make('123e4567-e12b-12d1-a456-426655440000', 'Fulano de Tal', 'BRASILIA') + ->payload(); + + $ensure($payload === $esperado, sprintf('payload divergente do manual: %s', $payload)); +}); + +$check('StaticPixCode: valor em reais com ponto e txid no campo 62', function () use ($ensure): void { + $payload = StaticPixCode::make('fale@phpay.io', 'Sixtec LTDA', 'BRASILIA') + ->withAmount(Money::reais('100,50')) + ->withTxid('PEDIDO1234') + ->payload(); + + $ensure(str_contains($payload, '5406100.50'), 'campo 54 deveria ser 06 e 100.50'); + $ensure(str_contains($payload, '62140510PEDIDO1234'), 'campo 62 deveria levar o txid em 05'); + $ensure(!str_contains($payload, '0503***'), 'com txid, não deveria sobrar o *** do padrão'); +}); + +$check('StaticPixCode: chave vazia e txid fora do padrão são recusados', function () use ($expect): void { + $expect(ValidationException::class, static fn () => StaticPixCode::make('', 'Sixtec LTDA', 'BRASILIA')); + $expect( + ValidationException::class, + static fn () => StaticPixCode::make('fale@phpay.io', 'Sixtec LTDA', 'BRASILIA')->withTxid('PEDIDO-1234') + ); +}); + echo "\nassinatura de webhook\n"; $check('PagBank: assinatura válida passa e inválida não', function () use ($gateways, $ensure): void {