Skip to content

Keep significant zeros in the NFC-e CSC id - #465

Open
SashaMIT wants to merge 1 commit into
TadaSoftware:mainfrom
SashaMIT:codered-csc-id
Open

SashaMIT wants to merge 1 commit into
TadaSoftware:mainfrom
SashaMIT:codered-csc-id

Conversation

@SashaMIT

Copy link
Copy Markdown

Summary

The NFC-e QR builder removed every 0 from the CSC id. SEFAZ only drops zeros that are not significant (the ones on the left). Id 000100 was sent as 1, and the SHA-1 was taken over that wrong id, so the receipt QR does not match the token registered for that taxpayer. 000001 still becomes 1.

Test plan

  • tests/test_nfce_qrcode_csc.py: before this change the id came back as 1. After it, the parameter is 100 and the hash matches SHA-1 of that parameter plus the CSC.
  • 000001 still becomes 1.

Made with Cursor

SEFAZ drops only non-significant zeros. Removing every zero turned id 100 into 1, so the QR hash was for the wrong token.
@Gomes343

Copy link
Copy Markdown

Confirmo o bug em uso real com NFC-e em SP, e a correção deste PR resolve.

O re.sub("([0])", "", token) apaga todos os zeros do identificador do CSC, mas o Manual do DANFE NFC-e manda tirar só os não significativos (à esquerda). Exemplos:

cIdToken esperado main hoje
000001 1 1 (acerta por acaso)
000010 10 1
010203 10203 123

Com o id errado o cHashQRCode sai errado e a falha é silenciosa: a SEFAZ autoriza a nota, o cupom imprime, e o consumidor não consegue consultá-la pelo QR Code.

Rodei o teste deste PR localmente: falha no main ('1' != '100') e passa com a correção (token.lstrip("0")).

A CI vermelha não vem do PR: o passo ruff format --check acusa "2 files would be reformatted" em arquivos que o PR não toca (os mesmos que derrubam outros PRs recentes).

@felps-dev, consegue avaliar o merge? Obrigado, @SashaMIT, pela correção.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants