Skip to content

Commit b23f1ea

Browse files
committed
Remove last digit validation based on iin length
1 parent 2704279 commit b23f1ea

2 files changed

Lines changed: 14 additions & 36 deletions

File tree

minfraud/validation.py

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from email_validator import validate_email # type: ignore
1818
from voluptuous import All, Any, In, Match, Range, Required, Schema
19-
from voluptuous.error import LengthInvalid, UrlInvalid
19+
from voluptuous.error import UrlInvalid
2020

2121
# Pylint doesn't like the private function type naming for the callable
2222
# objects below. Given the consistent use of them, the current names seem
@@ -291,25 +291,6 @@ def _uri(s: str) -> str:
291291
return s
292292

293293

294-
def _validate_last_digits(cc):
295-
iin = cc.get("issuer_id_number", None)
296-
if iin is None:
297-
return
298-
299-
if iin and len(iin) == 8:
300-
last_digits = cc.get("last_digits", None)
301-
last_4_digits = cc.get("last_4_digits", None)
302-
if last_digits and len(last_digits) != 2:
303-
raise LengthInvalid(
304-
"last_digits must be two digits when the issuer_id_number is eight digits."
305-
)
306-
if last_4_digits and len(last_4_digits) != 2:
307-
raise LengthInvalid(
308-
"last_4_digits must be two digits when the issuer_id_number is eight digits."
309-
)
310-
return
311-
312-
313294
validate_transaction = Schema(
314295
{
315296
"account": {
@@ -322,21 +303,18 @@ def _validate_last_digits(cc):
322303
"was_authorized": bool,
323304
"decline_code": str,
324305
},
325-
"credit_card": All(
326-
{
327-
"avs_result": _single_char,
328-
"bank_name": str,
329-
"bank_phone_country_code": _telephone_country_code,
330-
"bank_phone_number": str,
331-
"cvv_result": _single_char,
332-
"issuer_id_number": _iin,
333-
"last_digits": _credit_card_last_digits,
334-
"last_4_digits": _credit_card_last_digits,
335-
"token": _credit_card_token,
336-
"was_3d_secure_successful": bool,
337-
},
338-
_validate_last_digits,
339-
),
306+
"credit_card": {
307+
"avs_result": _single_char,
308+
"bank_name": str,
309+
"bank_phone_country_code": _telephone_country_code,
310+
"bank_phone_number": str,
311+
"cvv_result": _single_char,
312+
"issuer_id_number": _iin,
313+
"last_digits": _credit_card_last_digits,
314+
"last_4_digits": _credit_card_last_digits,
315+
"token": _credit_card_token,
316+
"was_3d_secure_successful": bool,
317+
},
340318
"custom_inputs": {_custom_input_key: _custom_input_value},
341319
"device": {
342320
"accept_language": str,

tests/test_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_last_digits(self):
158158
self.check_transaction(
159159
{"credit_card": {"issuer_id_number": "88888888", "last_digits": "12"}}
160160
)
161-
self.check_invalid_transaction(
161+
self.check_transaction(
162162
{"credit_card": {"issuer_id_number": "88888888", "last_digits": "1234"}}
163163
)
164164
self.check_transaction(

0 commit comments

Comments
 (0)