Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added wild cards support #601

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
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)
seekshiva marked this conversation as resolved.
Show resolved Hide resolved
Loading