Skip to content

Commit

Permalink
fix: card brand configuration error added (#362)
Browse files Browse the repository at this point in the history
Co-authored-by: Pritish Budhiraja <[email protected]>
  • Loading branch information
sakksham7 and Pritish Budhiraja authored May 10, 2024
1 parent e2cb755 commit f14c591
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ let getCardType = val => {
}
}

let getCardStringFromType = val => {
switch val {
| VISA => "Visa"
| MASTERCARD => "Mastercard"
| AMEX => "AmericanExpress"
| MAESTRO => "Maestro"
| DINERSCLUB => "DinersClub"
| DISCOVER => "Discover"
| BAJAJ => "BAJAJ"
| SODEXO => "SODEXO"
| RUPAY => "RuPay"
| JCB => "JCB"
| CARTESBANCAIRES => "CartesBancaires"
| UNIONPAY => "UnionPay"
| INTERAC => "Interac"
| NOTFOUND => "NOTFOUND"
}
}

let getobjFromCardPattern = cardBrand => {
let patternsDict = CardPattern.cardPatterns
patternsDict
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/ArabicLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
nicknamePlaceholder: `اسم البطاقة (اختياري)`,
cardExpiredText: `انتهت صلاحية هذه البطاقة`,
cardHeader: `معلومات البطاقة`,
cardBrandConfiguredErrorText: str => `${str} غير مدعوم في الوقت الحالي.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/CatalanLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Seleccioneu una forma de pagament i torneu-ho a provar`,
cardExpiredText: `Aquesta targeta ha caducat`,
cardHeader: `Informació de la targeta`,
cardBrandConfiguredErrorText: str => `${str} no està suportat en aquest moment.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/DeutschLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
nicknamePlaceholder: `Kartenname (optional)`,
cardExpiredText: `Diese Karte ist abgelaufen`,
cardHeader: `Kartendaten`,
cardBrandConfiguredErrorText: str => `${str} wird derzeit nicht unterstützt.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/DutchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Selecteer een betaalmethode en probeer het opnieuw`,
cardExpiredText: `Deze kaart is verlopen`,
cardHeader: `Kaartinformatie`,
cardBrandConfiguredErrorText: str => `${str} wordt op dit moment niet ondersteund.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/EnglishGBLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
nicknamePlaceholder: "Card Nickname (Optional)",
cardExpiredText: `This card has expired`,
cardHeader: `Card information`,
cardBrandConfiguredErrorText: str => `${str} is not supported at the moment.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/EnglishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
nicknamePlaceholder: "Card Nickname (Optional)",
cardExpiredText: `This card has expired`,
cardHeader: `Card information`,
cardBrandConfiguredErrorText: str => `${str} is not supported at the moment.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/FrenchBelgiumLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Veuillez sélectionner un mode de paiement et réessayer`,
cardExpiredText: `Cette carte a expiré`,
cardHeader: `Informations de carte`,
cardBrandConfiguredErrorText: str => `${str} n'est pas pris en charge pour le moment.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/FrenchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
nicknamePlaceholder: `Surnom de la carte (facultatif)`,
cardExpiredText: `Cette carte a expiré`,
cardHeader: `Informations de carte`,
cardBrandConfiguredErrorText: str => `${str} n'est pas pris en charge pour le moment.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/HebrewLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
nicknamePlaceholder: `כינוי לכרטיס (אופציונלי)`,
cardExpiredText: `הכרטיס הזה פג תוקף`,
cardHeader: `מידע כרטיס`,
cardBrandConfiguredErrorText: str => `${str} לא נתמך כרגע.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/ItalianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Seleziona un metodo di pagamento e riprova`,
cardExpiredText: `Questa carta è scaduta`,
cardHeader: `Informazioni sulla carta`,
cardBrandConfiguredErrorText: str => `${str} non è supportato al momento.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/JapaneseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
nicknamePlaceholder: `カードニックネーム(任意)`,
cardExpiredText: `このカードは期限切れです`,
cardHeader: `カード情報`,
cardBrandConfiguredErrorText: str => `${str} は現在サポートされていません。`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/LocaleStringTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ type localeStrings = {
nicknamePlaceholder: string,
cardExpiredText: string,
cardHeader: string,
cardBrandConfiguredErrorText: string => string,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/PolishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Wybierz metodę płatności i spróbuj ponownie`,
cardExpiredText: `Ta karta wygasła`,
cardHeader: `Informacje o karcie`,
cardBrandConfiguredErrorText: str => `${str} nie jest obecnie obsługiwany.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/PortugueseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Selecione uma forma de pagamento e tente novamente`,
cardExpiredText: `Este cartão expirou`,
cardHeader: `Informações do cartão`,
cardBrandConfiguredErrorText: str => `${str} não é suportado no momento.`,
}
2 changes: 2 additions & 0 deletions src/LocaleStrings/RussianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Пожалуйста, выберите способ оплаты и повторите попытку.`,
cardExpiredText: `Эта карта истекла`,
cardHeader: `Информация о карте`,
cardBrandConfiguredErrorText: str =>
`${str} в данный момент не поддерживается.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/SpanishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Por favor seleccione un método de pago y vuelva a intentarlo`,
cardExpiredText: `Esta tarjeta ha caducado`,
cardHeader: `Información de la tarjeta`,
cardBrandConfiguredErrorText: str => `${str} no está soportado en este momento.`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/SwedishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
selectPaymentMethodText: `Välj en betalningsmetod och försök igen`,
cardExpiredText: `Detta kort har gått ut`,
cardHeader: `Kortinformation`,
cardBrandConfiguredErrorText: str => `${str} stöds inte för tillfället.`,
}
34 changes: 28 additions & 6 deletions src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ let make = (
postFailedSubmitResponse(~errortype="validation_error", ~message)
}

let combinedCardNetworks = React.useMemo1(() => {
let cardPaymentMethod =
paymentMethodListValue.payment_methods
->Array.find(ele => ele.payment_method === "card")
->Option.getOr({
payment_method: "card",
payment_method_types: [],
})

let cardNetworks = cardPaymentMethod.payment_method_types->Array.map(ele => ele.card_networks)

let cardNetworkNames =
cardNetworks->Array.map(ele =>
ele->Array.map(val => val.card_network->CardUtils.getCardStringFromType->String.toLowerCase)
)

cardNetworkNames
->Array.reduce([], (acc, ele) => acc->Array.concat(ele))
->Utils.getUniqueArray
}, [paymentMethodListValue])
let isCardBrandValid = combinedCardNetworks->Array.includes(cardBrand->String.toLowerCase)

let (requiredFieldsBody, setRequiredFieldsBody) = React.useState(_ => Dict.make())

let areRequiredFieldsValid = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsValid)
Expand Down Expand Up @@ -130,12 +152,8 @@ let make = (
defaultCardBody
}
if confirm.doSubmit {
let validFormat =
(isBancontact ||
(isCVCValid->Option.getOr(false) &&
isCardValid->Option.getOr(false) &&
isExpiryValid->Option.getOr(false))) && areRequiredFieldsValid
if validFormat && (showFields || isBancontact) {
let validFormat = (isBancontact || complete) && areRequiredFieldsValid
if validFormat && (showFields || isBancontact) && isCardBrandValid {
intent(
~bodyArr={
(isBancontact ? banContactBody : cardBody)
Expand Down Expand Up @@ -165,6 +183,9 @@ let make = (
if !validFormat {
setUserError(localeString.enterValidDetailsText)
}
if !isCardBrandValid {
setUserError(localeString.cardBrandConfiguredErrorText(cardBrand))
}
}
}
}, (
Expand All @@ -174,6 +195,7 @@ let make = (
complete,
isCustomerAcceptanceRequired,
nickname,
isCardBrandValid,
))
useSubmitPaymentData(submitCallback)

Expand Down
2 changes: 2 additions & 0 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -1242,3 +1242,5 @@ let walletElementPaymentType: array<CardThemeType.mode> = [
let isWalletElementPaymentType = (paymentType: CardThemeType.mode) => {
walletElementPaymentType->Array.includes(paymentType)
}

let getUniqueArray = arr => arr->Array.map(item => (item, ""))->Dict.fromArray->Dict.keysToArray

0 comments on commit f14c591

Please sign in to comment.