From 54e613cc4e992f760543c1be796cf7563c5c78cf Mon Sep 17 00:00:00 2001 From: sakksham7 <130480324+sakksham7@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:16:27 +0530 Subject: [PATCH] fix: added wild cards support (#601) Co-authored-by: Saksham Sharma Co-authored-by: Shiva Nandan --- src/CardUtils.res | 8 ++++++-- src/GlobalVars.res | 2 +- src/Payment.res | 3 ++- src/Utilities/PaymentUtils.res | 4 +++- src/Utilities/Utils.res | 2 ++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/CardUtils.res b/src/CardUtils.res index 9ad523fb7..a20967fdc 100644 --- a/src/CardUtils.res +++ b/src/CardUtils.res @@ -458,8 +458,12 @@ let maxCardLength = cardBrand => { let cardValid = (cardNumber, cardBrand) => { let clearValueLength = cardNumber->clearSpaces->String.length - (clearValueLength == maxCardLength(cardBrand) || - (cardBrand === "Visa" && clearValueLength == 16)) && calculateLuhn(cardNumber) + if cardBrand == "" && (GlobalVars.isInteg || GlobalVars.isSandbox) { + Utils.checkIsTestCardWildcard(cardNumber) + } else { + (clearValueLength == maxCardLength(cardBrand) || + (cardBrand === "Visa" && clearValueLength == 16)) && calculateLuhn(cardNumber) + } } let blurRef = (ref: React.ref>) => { ref.current->Nullable.toOption->Option.forEach(input => input->blur)->ignore diff --git a/src/GlobalVars.res b/src/GlobalVars.res index 0580a11fb..e7be7c345 100644 --- a/src/GlobalVars.res +++ b/src/GlobalVars.res @@ -12,5 +12,5 @@ @val external maxLogsPushedPerEventName: int = "maxLogsPushedPerEventName" let targetOrigin: string = "*" let isInteg = sdkUrl === "https://dev.hyperswitch.io" -let isSandbox = sdkUrl === "https://beta.hyperswitch.io" +let isSandbox = sdkUrl === "https://beta.hyperswitch.io" || sdkUrl === "http://localhost:9050" let isProd = sdkUrl === "https://checkout.hyperswitch.io" diff --git a/src/Payment.res b/src/Payment.res index 8ead3bf2a..13dd3d733 100644 --- a/src/Payment.res +++ b/src/Payment.res @@ -87,7 +87,8 @@ let make = (~paymentMode, ~integrateError, ~logger) => { setCardValid(clearValue, setIsCardValid) if ( cardValid(clearValue, cardBrand) && - PaymentUtils.checkIsCardSupported(clearValue, supportedCardBrands)->Option.getOr(false) + (PaymentUtils.checkIsCardSupported(clearValue, supportedCardBrands)->Option.getOr(false) || + Utils.checkIsTestCardWildcard(clearValue)) ) { handleInputFocus(~currentRef=cardRef, ~destinationRef=expiryRef) } diff --git a/src/Utilities/PaymentUtils.res b/src/Utilities/PaymentUtils.res index 92a9d34c1..108f3f8c2 100644 --- a/src/Utilities/PaymentUtils.res +++ b/src/Utilities/PaymentUtils.res @@ -498,7 +498,9 @@ let getSupportedCardBrands = ( let checkIsCardSupported = (cardNumber, supportedCardBrands) => { let cardBrand = cardNumber->CardUtils.getCardBrand let clearValue = cardNumber->CardUtils.clearSpaces - if CardUtils.cardValid(clearValue, cardBrand) { + if cardBrand == "" && (GlobalVars.isInteg || GlobalVars.isSandbox) { + Some(CardUtils.cardValid(clearValue, cardBrand)) + } else if CardUtils.cardValid(clearValue, cardBrand) { switch supportedCardBrands { | Some(brands) => Some(brands->Array.includes(cardBrand->String.toLowerCase)) | None => Some(true) diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index 572300a53..e6f1e9f13 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1375,3 +1375,5 @@ let getFirstAndLastNameFromFullName = fullName => { (firstName, lastNameJson) } + +let checkIsTestCardWildcard = val => ["1111222233334444"]->Array.includes(val)