From e925e33556531eb7142ee0a7b26cdbcacc920b15 Mon Sep 17 00:00:00 2001 From: Sanskar Atrey Date: Mon, 9 Dec 2024 14:46:14 +0530 Subject: [PATCH] feat: added cb regex and typo fix (#811) Co-authored-by: Pritish Budhiraja --- src/CardPattern.res | 34 ++++++++++++++++++++++------------ src/CardSchemeComponent.res | 2 +- src/CardUtils.res | 2 +- src/Payment.res | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/CardPattern.res b/src/CardPattern.res index 1706eeb06..ab814e31f 100644 --- a/src/CardPattern.res +++ b/src/CardPattern.res @@ -3,7 +3,7 @@ type patterns = { pattern: Re.t, cvcLength: array, length: array, - maxCVCLenth: int, + maxCVCLength: int, pincodeRequired: bool, } type card = {details: array} @@ -11,7 +11,7 @@ let defaultCardPattern = { issuer: "", pattern: %re("/^[0-9]/"), cvcLength: [3], - maxCVCLenth: 3, + maxCVCLength: 3, length: [16], pincodeRequired: false, } @@ -23,7 +23,7 @@ let cardPatterns = [ ), cvcLength: [3, 4], length: [12, 13, 14, 15, 16, 17, 18, 19], - maxCVCLenth: 4, + maxCVCLength: 4, pincodeRequired: true, }, { @@ -33,14 +33,14 @@ let cardPatterns = [ ), cvcLength: [3], length: [16], - maxCVCLenth: 3, + maxCVCLength: 3, pincodeRequired: false, }, { issuer: "DinersClub", pattern: %re("/^(36|38|39|30[0-5])/"), cvcLength: [3], - maxCVCLenth: 3, + maxCVCLength: 3, length: [14, 15, 16, 17, 18, 19], pincodeRequired: false, }, @@ -49,14 +49,14 @@ let cardPatterns = [ pattern: %re("/^(6011|64[4-9]|65|622126|622[1-9][0-9][0-9]|6229[0-1][0-9]|622925)/"), cvcLength: [3], length: [16], - maxCVCLenth: 3, + maxCVCLength: 3, pincodeRequired: true, }, { issuer: "Mastercard", pattern: %re("/^(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[0-1][0-9]|2720|5[1-5])/"), cvcLength: [3], - maxCVCLenth: 3, + maxCVCLength: 3, length: [16], pincodeRequired: true, }, @@ -65,7 +65,7 @@ let cardPatterns = [ pattern: %re("/^3[47]/"), cvcLength: [3, 4], length: [14, 15], - maxCVCLenth: 4, + maxCVCLength: 4, pincodeRequired: true, }, { @@ -73,7 +73,17 @@ let cardPatterns = [ pattern: %re("/^4/"), cvcLength: [3], length: [13, 14, 15, 16, 19], - maxCVCLenth: 3, + maxCVCLength: 3, + pincodeRequired: true, + }, + { + issuer: "CartesBancaires", + pattern: %re( + "/^(401(005|006|581)|4021(01|02)|403550|405936|406572|41(3849|4819|50(56|59|62|71|74)|6286|65(37|79)|71[7])|420110|423460|43(47(21|22)|50(48|49|50|51|52)|7875|95(09|11|15|39|98)|96(03|18|19|20|22|72))|4424(48|49|50|51|52|57)|448412|4505(19|60)|45(33|56[6-8]|61|62[^3]|6955|7452|7717|93[02379])|46(099|54(76|77)|6258|6575|98[023])|47(4107|71(73|74|86)|72(65|93)|9619)|48(1091|3622|6519)|49(7|83[5-9]|90(0[1-6]|1[0-6]|2[0-3]|3[0-3]|4[0-3]|5[0-2]|68|9[256789]))|5075(89|90|93|94|97)|51(0726|3([0-7]|8[56]|9(00|38))|5214|62(07|36)|72(22|43)|73(65|66)|7502|7647|8101|9920)|52(0993|1662|3718|7429|9227|93(13|14|31)|94(14|21|30|40|47|55|56|[6-9])|9542)|53(0901|10(28|30)|1195|23(4[4-7])|2459|25(09|34|54|56)|3801|41(02|05|11)|50(29|66)|5324|61(07|15)|71(06|12)|8011)|54(2848|5157|9538|98(5[89]))|55(39(79|93)|42(05|60)|4965|7008|88(67|82)|89(29|4[23])|9618|98(09|10))|56(0408|12(0[2-6]|4[134]|5[04678]))|58(17(0[0-7]|15|2[14]|3[16789]|4[0-9]|5[016]|6[269]|7[3789]|8[0-7]|9[017])|55(0[2-5]|7[7-9]|8[0-2])))/" + ), + cvcLength: [3], + length: [16, 17, 18, 19], + maxCVCLength: 3, pincodeRequired: true, }, { @@ -81,14 +91,14 @@ let cardPatterns = [ pattern: %re("/^(637513)/"), cvcLength: [3], length: [16], - maxCVCLenth: 3, + maxCVCLength: 3, pincodeRequired: false, }, { issuer: "BAJAJ", pattern: %re("/^(203040)/"), cvcLength: [3], - maxCVCLenth: 3, + maxCVCLength: 3, length: [16], pincodeRequired: true, }, @@ -96,7 +106,7 @@ let cardPatterns = [ issuer: "JCB", pattern: %re("/^35(2[89]|[3-8][0-9])/"), cvcLength: [3], - maxCVCLenth: 3, + maxCVCLength: 3, length: [16], pincodeRequired: false, }, diff --git a/src/CardSchemeComponent.res b/src/CardSchemeComponent.res index dee03adf6..1d6621711 100644 --- a/src/CardSchemeComponent.res +++ b/src/CardSchemeComponent.res @@ -31,7 +31,7 @@ let make = (~cardNumber, ~paymentType, ~cardBrand, ~setCardBrand) => { let enabledCardSchemes = paymentMethodListValue->PaymentUtils.getSupportedCardBrands->Option.getOr([]) - let matchedCardSchemes = cardNumber->CardUtils.getAllMatchedCardSchemes + let matchedCardSchemes = cardNumber->CardUtils.clearSpaces->CardUtils.getAllMatchedCardSchemes let eligibleCardSchemes = CardUtils.getEligibleCoBadgedCardSchemes( ~matchedCardSchemes, diff --git a/src/CardUtils.res b/src/CardUtils.res index 8a93c3495..3301b78da 100644 --- a/src/CardUtils.res +++ b/src/CardUtils.res @@ -156,7 +156,7 @@ let getStrFromIndex = (arr: array, index) => { let formatCVCNumber = (val, cardType) => { let clearValue = val->clearSpaces let obj = getobjFromCardPattern(cardType) - clearValue->slice(0, obj.maxCVCLenth) + clearValue->slice(0, obj.maxCVCLength) } let getCurrentMonthAndYear = (dateTimeIsoString: string) => { diff --git a/src/Payment.res b/src/Payment.res index 253b89391..befaab786 100644 --- a/src/Payment.res +++ b/src/Payment.res @@ -71,7 +71,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => { React.useEffect(() => { let obj = getobjFromCardPattern(cardBrand) - let cvcLength = obj.maxCVCLenth + let cvcLength = obj.maxCVCLength if ( cvcNumberInRange(cvcNumber, cardBrand)->Array.includes(true) && cvcNumber->String.length == cvcLength