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

refactor: added submodule for hyperswitch-sdk-utils #167

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
path = android
url = [email protected]:juspay/hyperswitch-sdk-android.git
branch = main
[submodule "hyperswitch-sdk-utils"]
path = hyperswitch-sdk-utils
url = [email protected]:juspay/hyperswitch-sdk-utils.git
branch = main
1 change: 1 addition & 0 deletions hyperswitch-sdk-utils
Submodule hyperswitch-sdk-utils added at 13b443
4 changes: 4 additions & 0 deletions rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
{
"dir": "reactNativeWeb",
"subdirs": true
},
{
"dir": "hyperswitch-sdk-utils",
"subdirs": true
}
],
"bs-dependencies": [
Expand Down
16 changes: 0 additions & 16 deletions src/components/common/ValidationFunctions.res
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
let isValidEmail = text => {
switch text->String.match(
%re(
"/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/"
),
) {
| Some(_match) => Some(true)
| None =>
if text->String.length == 0 {
None
} else {
Some(false)
}
}
}

let isValidZip = (~zipCode, ~country) => {
let countryObj =
Country.country
Expand Down
10 changes: 6 additions & 4 deletions src/components/elements/CardElement.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
open Validation
open ValidationUtils
open CardExpiryValidation
open CardNumberValidation
type cardFormType = {isZipAvailable: bool}
type viewType = PaymentSheet | CardForm(cardFormType)
@react.component
Expand Down Expand Up @@ -56,7 +58,7 @@ let make = (
expireRef: React.ref<Nullable.t<ReactNative.TextInput.element>>,
) => {
let cardBrand = getCardBrand(text)
let num = formatCardNumber(text, cardType(cardBrand))
let num = formatCardNumber(text, getCardType(cardBrand))
let isthisValid = cardValid(num, cardBrand)

setCardData(prev => {...prev, cardNumber: num, isCardNumberValid: Some(isthisValid)})
Expand All @@ -83,7 +85,7 @@ let make = (
}
let onChangeCvv = (text, cvvOrZipRef: React.ref<Nullable.t<ReactNative.TextInput.element>>) => {
let cvvData = formatCVCNumber(text, getCardBrand(cardData.cardNumber))
let isthisValid = checkCardCVC(cvvData, getCardBrand(cardData.cardNumber))
let isthisValid = CardCvcValidation.checkCardCVC(cvvData, getCardBrand(cardData.cardNumber))
if isthisValid {
switch cvvOrZipRef.current->Nullable.toOption {
| None => ()
Expand Down Expand Up @@ -113,7 +115,7 @@ let make = (
cvvRef: React.ref<Nullable.t<ReactNative.TextInput.element>>,
) => {
let cardBrand = getCardBrand(pan)
let cardNumber = formatCardNumber(pan, cardType(cardBrand))
let cardNumber = formatCardNumber(pan, getCardType(cardBrand))
let isCardValid = cardValid(cardNumber, cardBrand)
let expireDate = formatCardExpiryNumber(expiry)
let isExpiryValid = checkCardExpiry(expireDate)
Expand Down
5 changes: 4 additions & 1 deletion src/components/elements/CardFormUi.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
open ReactNative
open Style
open Validation
open CardCvcValidation
open ValidationUtils
open CardNumberValidation

@react.component
let make = (
~cardNumber,
Expand Down
4 changes: 3 additions & 1 deletion src/components/elements/PaymentSheetUi.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
open ReactNative
open Style
open Validation
open CardCvcValidation
open ValidationUtils
open CardNumberValidation

@react.component
let make = (
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/AllPaymentHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,13 @@ let useSavePaymentMethod = () => {
let (nativeProp, _) = React.useContext(NativePropContext.nativePropContext)
let (cardData, _) = React.useContext(CardDataContext.cardDataContext)

let (month, year) = Validation.getExpiryDates(cardData.expireDate)
let (month, year) = CardExpiryValidation.getExpiryDates(cardData.expireDate)
let payment_method_data =
[
(
"card",
[
("card_number", cardData.cardNumber->Validation.clearSpaces->JSON.Encode.string),
("card_number", cardData.cardNumber->ValidationUtils.clearSpaces->JSON.Encode.string),
("card_exp_month", month->JSON.Encode.string),
("card_exp_year", year->JSON.Encode.string),
]
Expand Down
2 changes: 1 addition & 1 deletion src/pages/payment/Redirect.res
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ let make = (
}

let handlePressEmail = text => {
setIsEmailValid(_ => text->ValidationFunctions.isValidEmail)
setIsEmailValid(_ => text->EmailValidation.isEmailValid)
setEmail(_ => Some(text))
}
let handlePressName = text => {
Expand Down
10 changes: 6 additions & 4 deletions src/pages/payment/SaveCardsList.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open ReactNative
open Style
open CardCvcValidation

module CVVComponent = {
@react.component
Expand All @@ -17,13 +18,14 @@ module CVVComponent = {
isCvcFocus || savedCardCvv->Option.isNone
? true
: savedCardCvv->Option.getOr("")->String.length > 0 &&
Validation.cvcNumberInRange(savedCardCvv->Option.getOr(""), cardScheme)
cvcNumberInRange(savedCardCvv->Option.getOr(""), cardScheme)

let localeObject = GetLocale.useGetLocalObj()

let errorMsgText = !isCvcValid ? Some(localeObject.inCompleteCVCErrorText) : None

let onCvvChange = cvv => setSavedCardCvv(_ => Some(Validation.formatCVCNumber(cvv, cardScheme)))
let onCvvChange = cvv =>
setSavedCardCvv(_ => Some(ValidationUtils.formatCVCNumber(cvv, cardScheme)))

{
isPaymentMethodSelected
Expand Down Expand Up @@ -59,7 +61,7 @@ module CVVComponent = {
secureTextEntry=true
textColor={isCvcValid ? component.color : dangerColor}
iconRight=CustomIcon({
Validation.checkCardCVC(savedCardCvv->Option.getOr(""), cardScheme)
checkCardCVC(savedCardCvv->Option.getOr(""), cardScheme)
? <Icon name="cvvfilled" height=35. width=35. fill="black" />
: <Icon name="cvvempty" height=35. width=35. fill="black" />
})
Expand Down Expand Up @@ -230,7 +232,7 @@ module PaymentMethodListView = {
| "NotCard" => true
| _ =>
switch savedCardCvv {
| Some(cvv) => cvv->String.length > 0 && Validation.cvcNumberInRange(cvv, cardScheme)
| Some(cvv) => cvv->String.length > 0 && cvcNumberInRange(cvv, cardScheme)
| None => !(pmObject->PaymentUtils.checkIsCVCRequired)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/widgets/CardWidget.res
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ let make = () => {
| _ => handleSuccessFailure(~apiResStatus=status, ())
}
}
let (month, year) = Validation.getExpiryDates(expireDate)
let (month, year) = CardExpiryValidation.getExpiryDates(expireDate)
let payment_method_data =
[
(
prop.payment_method,
[
("card_number", cardNumber->Validation.clearSpaces->JSON.Encode.string),
("card_number", cardNumber->ValidationUtils.clearSpaces->JSON.Encode.string),
("card_exp_month", month->JSON.Encode.string),
("card_exp_year", year->JSON.Encode.string),
("card_holder_name", ""->JSON.Encode.string),
Expand Down
2 changes: 1 addition & 1 deletion src/types/RequiredFieldsTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ let checkIsValid = (
} else {
switch field_type {
| Email =>
switch text->ValidationFunctions.isValidEmail {
switch text->EmailValidation.isEmailValid {
| Some(false) => Some(localeObject.emailInvalidText)
| Some(true) => None
| None => Some(localeObject.emailEmptyText)
Expand Down
4 changes: 2 additions & 2 deletions src/utility/logics/PaymentUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ let generatePaymentMethodData = (
~cardHolderName: option<'a>,
~nickname: option<'a>,
) => {
let (month, year) = Validation.getExpiryDates(cardData.expireDate)
let (month, year) = CardExpiryValidation.getExpiryDates(cardData.expireDate)

[
(
prop.payment_method,
[
("card_number", cardData.cardNumber->Validation.clearSpaces->JSON.Encode.string),
("card_number", cardData.cardNumber->ValidationUtils.clearSpaces->JSON.Encode.string),
("card_exp_month", month->JSON.Encode.string),
("card_exp_year", year->JSON.Encode.string),
(
Expand Down
103 changes: 0 additions & 103 deletions src/utility/reusableCodeFromWeb/CardPattern.res

This file was deleted.

Loading
Loading