Skip to content

Commit

Permalink
feat: added upi collect payment method type
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay committed Jul 10, 2024
1 parent ed46ca0 commit b9ba53d
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 1 deletion.
4 changes: 4 additions & 0 deletions public/icons/orca.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ let make = (
</>
| CryptoCurrencyNetworks => <CryptoCurrencyNetworks />
| DateOfBirth => <DateOfBirth />
| VpaId => <VpaIdPaymentInput paymentType />
| Email
| InfoElement
| Country
Expand Down Expand Up @@ -765,6 +766,7 @@ let make = (
| CryptoCurrencyNetworks
| DateOfBirth
| PhoneCountryCode
| VpaId
| None => React.null
}}
</div>
Expand Down
65 changes: 65 additions & 0 deletions src/Components/VpaIdPaymentInput.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
open RecoilAtoms
open Utils

@react.component
let make = (~paymentType) => {
let {localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom)
let (vpaId, setVpaId) = Recoil.useLoggedRecoilState(userVpaId, "vpaId", loggerState)

let vpaIdRef = React.useRef(Nullable.null)

let changeVpaId = ev => {
let val: string = ReactEvent.Form.target(ev)["value"]
setVpaId(prev => {
value: val,
isValid: val->isVpaIdValid,
errorString: val->isVpaIdValid->Option.getOr(false) ? "" : prev.errorString,
})
}
let onBlur = ev => {
let val = ReactEvent.Focus.target(ev)["value"]
setVpaId(prev => {
...prev,
isValid: val->isVpaIdValid,
})
}

React.useEffect(() => {
setVpaId(prev => {
...prev,
errorString: switch prev.isValid {
| Some(val) => val ? "" : localeString.vpaIdInvalidText
| None => ""
},
})
None
}, [vpaId.isValid])

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
if confirm.doSubmit {
if vpaId.value == "" {
setVpaId(prev => {
...prev,
errorString: localeString.vpaIdEmptyText,
})
}
}
}, [vpaId])
useSubmitPaymentData(submitCallback)

<PaymentField
fieldName=localeString.vpaIdLabel
setValue={setVpaId}
value=vpaId
onChange=changeVpaId
onBlur
paymentType
type_="text"
name="vpaId"
inputRef=vpaIdRef
placeholder="Eg: johndoe@upi"
/>
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/ArabicLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `شبكات العملات`,
expiryPlaceholder: `MM / YY`,
dateOfBirth: `تاريخ الميلاد`,
vpaIdLabel: `معرف VPA`,
vpaIdEmptyText: `لا يمكن أن يكون معرف Vpa فارغًا`,
vpaIdInvalidText: `معرف Vpa غير صالح`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/CatalanLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Xarxes de Monedes`,
expiryPlaceholder: `MM / AA`,
dateOfBirth: `Data de naixement`,
vpaIdLabel: `Vpa Id`,
vpaIdEmptyText: `L'identificador de Vpa no pot estar buit`,
vpaIdInvalidText: `Identificador de VPA no vàlid`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/DeutschLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Währungsnetzwerke`,
expiryPlaceholder: `MM / JJ`,
dateOfBirth: `Geburtsdatum`,
vpaIdLabel: `Vpa-ID`,
vpaIdEmptyText: `Die VPA-ID darf nicht leer sein`,
vpaIdInvalidText: `Ungültige VPA-ID`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/DutchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Valutanetwerken`,
expiryPlaceholder: `MM / JJ`,
dateOfBirth: `Geboortedatum`,
vpaIdLabel: `Vpa-id`,
vpaIdEmptyText: `Vpa-ID mag niet leeg zijn`,
vpaIdInvalidText: `Ongeldige Vpa-ID`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/EnglishGBLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Currency Networks`,
expiryPlaceholder: `MM / YY`,
dateOfBirth: `Date of Birth`,
vpaIdLabel: `Vpa Id`,
vpaIdEmptyText: `Vpa Id cannot be empty`,
vpaIdInvalidText: `Invalid Vpa Id address`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/EnglishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Currency Networks`,
expiryPlaceholder: `MM / YY`,
dateOfBirth: `Date of Birth`,
vpaIdLabel: "Vpa Id",
vpaIdEmptyText: "Vpa Id cannot be empty",
vpaIdInvalidText: "Invalid Vpa Id address",
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/FrenchBelgiumLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Réseaux Monétaires`,
expiryPlaceholder: `MM / AA`,
dateOfBirth: `Date de naissance`,
vpaIdLabel: `Identifiant Vpa`,
vpaIdEmptyText: `L'identifiant Vpa ne peut pas être vide`,
vpaIdInvalidText: `Identifiant Vpa invalide`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/FrenchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Réseaux Monétaires`,
expiryPlaceholder: `MM / AA`,
dateOfBirth: `Date de naissance`,
vpaIdLabel: `Identifiant Vpa`,
vpaIdEmptyText: `L'identifiant Vpa ne peut pas être vide`,
vpaIdInvalidText: `Identifiant Vpa invalide`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/HebrewLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `רשתות מטבעות`,
expiryPlaceholder: `MM / YY`,
dateOfBirth: `תאריך לידה`,
vpaIdLabel: `מזהה VPA`,
vpaIdEmptyText: `מזהה VPA לא יכול להיות ריק`,
vpaIdInvalidText: `מזהה VPA לא חוקי`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/ItalianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Reti Valutarie`,
expiryPlaceholder: `MM / AA`,
dateOfBirth: `Data di nascita`,
vpaIdLabel: `Codice Vpa`,
vpaIdEmptyText: `L'ID Vpa non può essere vuoto`,
vpaIdInvalidText: `ID Vpa non valido`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/JapaneseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `通貨ネットワーク`,
expiryPlaceholder: `MM / YY`,
dateOfBirth: `生年月日`,
vpaIdLabel: `VPA ID`,
vpaIdEmptyText: `VPA ID を空にすることはできません`,
vpaIdInvalidText: `無効な VPA ID`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/LocaleStringTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ type localeStrings = {
currencyNetwork: string,
expiryPlaceholder: string,
dateOfBirth: string,
vpaIdLabel: string,
vpaIdEmptyText: string,
vpaIdInvalidText: string,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/PolishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Sieci Walutowe`,
expiryPlaceholder: `MM / RR`,
dateOfBirth: `Data urodzenia`,
vpaIdLabel: `Identyfikator Vpa`,
vpaIdEmptyText: `Identyfikator Vpa nie może być pusty`,
vpaIdInvalidText: `Nieprawidłowy identyfikator Vpa`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/PortugueseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Redes de Moeda`,
expiryPlaceholder: `MM / AA`,
dateOfBirth: `Data de nascimento`,
vpaIdLabel: `ID VPA`,
vpaIdEmptyText: `O ID Vpa não pode ficar vazio`,
vpaIdInvalidText: `ID Vpa inválido`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/RussianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Валютные сети`,
expiryPlaceholder: `MM / ГГ`,
dateOfBirth: `Дата рождения`,
vpaIdLabel: `Идентификатор ВПА`,
vpaIdEmptyText: `Идентификатор VPA не может быть пустым.`,
vpaIdInvalidText: `Неверный идентификатор VPA`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/SpanishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Redes de Divisas`,
expiryPlaceholder: `MM / AA`,
dateOfBirth: `Fecha de nacimiento`,
vpaIdLabel: `Identificación de Vpa`,
vpaIdEmptyText: `El ID de Vpa no puede estar vacío`,
vpaIdInvalidText: `ID de Vpa no válido`,
}
3 changes: 3 additions & 0 deletions src/LocaleStrings/SwedishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
currencyNetwork: `Valutanätverk`,
expiryPlaceholder: `MM / ÅÅ`,
dateOfBirth: `Födelsedatum`,
vpaIdLabel: `Vpa-id`,
vpaIdEmptyText: `Vpa-id får inte vara tomt`,
vpaIdInvalidText: `Ogiltigt Vpa-ID`,
}
10 changes: 10 additions & 0 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type paymentMethodsFields =
| ShippingAddressCountry(array<string>)
| CryptoCurrencyNetworks
| DateOfBirth
| VpaId

let getPaymentMethodsFieldsOrder = paymentMethodField => {
switch paymentMethodField {
Expand Down Expand Up @@ -524,6 +525,13 @@ let paymentMethodsFields = [
displayName: "Mifinity",
miniIcon: None,
},
{
paymentMethodName: "upi_collect",
fields: [InfoElement],
icon: Some(icon("bhim_upi", ~size=19)),
displayName: "UPI Collect",
miniIcon: None,
},
]

type required_fields = {
Expand Down Expand Up @@ -560,6 +568,7 @@ let getPaymentMethodsFieldTypeFromString = (str, isBancontact) => {
| ("user_crypto_currency_network", _) => CryptoCurrencyNetworks
| ("user_date_of_birth", _) => DateOfBirth
| ("user_phone_number_country_code", _) => PhoneCountryCode
| ("user_vpa_id", _) => VpaId
| _ => None
}
}
Expand Down Expand Up @@ -637,6 +646,7 @@ let dynamicFieldsEnabledPaymentMethods = [
"local_bank_transfer_transfer",
"afterpay_clearpay",
"mifinity",
"upi_collect",
]

let getIsBillingField = requiredFieldType => {
Expand Down
10 changes: 9 additions & 1 deletion src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ let useRequiredFieldsEmptyAndValid = (
~cvcNumber,
) => {
let email = Recoil.useRecoilValueFromAtom(userEmailAddress)
let vpaId = Recoil.useRecoilValueFromAtom(userVpaId)
let fullName = Recoil.useRecoilValueFromAtom(userFullName)
let billingName = Recoil.useRecoilValueFromAtom(userBillingName)
let line1 = Recoil.useRecoilValueFromAtom(userAddressline1)
Expand Down Expand Up @@ -165,6 +166,7 @@ let useRequiredFieldsEmptyAndValid = (
| Some(val) => val->Utils.checkIs18OrAbove
| None => false
}
| VpaId => vpaId.isValid->Option.getOr(false)
| _ => true
}
})
Expand Down Expand Up @@ -225,6 +227,7 @@ let useRequiredFieldsEmptyAndValid = (
dateOfBirth,
(
email,
vpaId,
line2.value,
selectedBank,
phone.value,
Expand Down Expand Up @@ -412,6 +415,7 @@ let useSetInitialRequiredFields = (
| ShippingAddressPincode
| ShippingAddressState
| ShippingAddressCountry(_)
| VpaId
| None => ()
}
})
Expand All @@ -430,6 +434,7 @@ let useRequiredFieldsBody = (
~setRequiredFieldsBody,
) => {
let email = Recoil.useRecoilValueFromAtom(userEmailAddress)
let vpaId = Recoil.useRecoilValueFromAtom(userVpaId)
let fullName = Recoil.useRecoilValueFromAtom(userFullName)
let billingName = Recoil.useRecoilValueFromAtom(userBillingName)
let line1 = Recoil.useRecoilValueFromAtom(userAddressline1)
Expand Down Expand Up @@ -488,6 +493,7 @@ let useRequiredFieldsBody = (
| None => ""
}
| CardCvc => cvcNumber
| VpaId => vpaId.value
| StateAndCity
| CountryAndPincode(_)
| SpecialField(_)
Expand Down Expand Up @@ -565,6 +571,7 @@ let useRequiredFieldsBody = (
}, (
fullName.value,
email.value,
vpaId.value,
line1.value,
line2.value,
city.value,
Expand Down Expand Up @@ -596,7 +603,8 @@ let isFieldTypeToRenderOutsideBilling = (fieldType: PaymentMethodsRecord.payment
| CardExpiryAndCvc
| CryptoCurrencyNetworks
| DateOfBirth
| Currency(_) => true
| Currency(_)
| VpaId => true
| _ => false
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Utilities/RecoilAtoms.res
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ let areRequiredFieldsValid = Recoil.atom("areRequiredFieldsValid", true)
let areRequiredFieldsEmpty = Recoil.atom("areRequiredFieldsEmpty", false)
let dateOfBirth = Recoil.atom("dateOfBirth", Nullable.null)
let userBillingName = Recoil.atom("userBillingName", defaultFieldValues)
let userVpaId = Recoil.atom("userVpaId", defaultFieldValues)

type areOneClickWalletsRendered = {
isGooglePay: bool,
Expand Down
9 changes: 9 additions & 0 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ let isEmailValid = email => {
}
}

let isVpaIdValid = vpaId => {
switch vpaId->String.match(
%re("/^[a-zA-Z0-9]([a-zA-Z0-9.-]{1,50})[a-zA-Z0-9]@[a-zA-Z0-9]{2,}$/"),
) {
| Some(_match) => Some(true)
| None => vpaId->String.length > 0 ? Some(false) : None
}
}

let checkEmailValid = (
email: RecoilAtomTypes.field,
fn: (RecoilAtomTypes.field => RecoilAtomTypes.field) => unit,
Expand Down

0 comments on commit b9ba53d

Please sign in to comment.