Skip to content

[PG-3218] Adiciona exceção do Luhn check para Softnex#35

Open
felipetrz-maistodos wants to merge 1 commit into
mainfrom
PG-3218
Open

[PG-3218] Adiciona exceção do Luhn check para Softnex#35
felipetrz-maistodos wants to merge 1 commit into
mainfrom
PG-3218

Conversation

@felipetrz-maistodos

@felipetrz-maistodos felipetrz-maistodos commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Comment thread creditcard/card.py

def get_brand(self):
@cached_property
def _brand(self):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adicionei como cached_property pra evitar ficar passando pelas regexes várias vezes pro mesmo cartão.

@mateuspadua mateuspadua Jun 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o motor sempre instancia CreditCard toda vez que vai usar? Isso nao pode mascarar algum comportamento que a gente nao tem ideia ainda?

Comment thread creditcard/card.py
return len(self.number) in range(13, 19) and Luhn.checkdigit(self.number)

def get_brand(self):
if brand := self._brand:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

de onde vem o brand, 🤔

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tem uma função acima que extrai baseado no número

Comment thread creditcard/card.py
if self._brand == "softnex":
# Softnex emite cartões que não são válidos pelo Luhn
return True
return len(self.number) in range(13, 19) and Luhn.checkdigit(self.number)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se for softnex, a validação do range poderia ser usada?

def is_valid(self):
    return len(self.number) in range(13, 19) and self._brand == "softnex" or Luhn.checkdigit(self.number)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pensei em incluir a validação do tamanho na softnex também, mas como eles estão mudando o formato pra não ser mais um cartão de crédito válido, pensei que talvez isso possa mudar no futuro também.
Podemos deixar só eles validando o número do cartão mesmo.

Comment thread creditcard/card.py
return len(self.number) in range(13, 19) and Luhn.checkdigit(self.number)

def get_brand(self):
if brand := self._brand:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tem uma função acima que extrai baseado no número

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.

6 participants