Skip to content

Commit

Permalink
fix: added wild cards support (#601)
Browse files Browse the repository at this point in the history
Co-authored-by: Saksham Sharma <[email protected]>
Co-authored-by: Shiva Nandan <[email protected]>
  • Loading branch information
3 people authored Sep 9, 2024
1 parent 65f873d commit 54e613c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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<Nullable.t<Dom.element>>) => {
ref.current->Nullable.toOption->Option.forEach(input => input->blur)->ignore
Expand Down
2 changes: 1 addition & 1 deletion src/GlobalVars.res
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion src/Utilities/PaymentUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -1375,3 +1375,5 @@ let getFirstAndLastNameFromFullName = fullName => {

(firstName, lastNameJson)
}

let checkIsTestCardWildcard = val => ["1111222233334444"]->Array.includes(val)

0 comments on commit 54e613c

Please sign in to comment.