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

feat: added dynamic fields for SEPA #624

Merged
merged 19 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
32 changes: 32 additions & 0 deletions src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,38 @@ let make = () => {
None
}, [logger])

React.useEffect0(() => {
let handleMetaDataPostMessage = (ev: Window.event) => {
let json = ev.data->Utils.safeParse
let dict = json->Utils.getDictFromJson

if dict->Dict.get("metadata")->Option.isSome {
let metadata = dict->Utils.getJsonObjectFromDict("metadata")
let config = metadata->Utils.getDictFromJson->Dict.get("config")

switch config {
| Some(config) => {
let config = CardTheme.itemToObjMapper(
config->Utils.getDictFromJson,
DefaultTheme.default,
DefaultTheme.defaultRules,
logger,
)

CardUtils.generateFontsLink(config.fonts)
let dict = config.appearance.rules->Utils.getDictFromJson
if dict->Dict.toArray->Array.length > 0 {
Utils.generateStyleSheet("", dict, "mystyle")
}
}
| None => ()
}
}
}
Window.addEventListener("message", handleMetaDataPostMessage)
Some(() => Window.removeEventListener("message", handleMetaDataPostMessage))
})

let renderFullscreen = switch paymentMode {
| "paymentMethodCollect" =>
<LoaderController paymentMode setIntegrateErrorError logger initTimestamp>
Expand Down
4 changes: 2 additions & 2 deletions src/CardTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Utils
open ErrorUtils

let getTheme = (val, logger) => {
switch val {
switch val->String.toLowerCase {
| "default" => Default
| "brutal" => Brutal
| "midnight" => Midnight
Expand Down Expand Up @@ -359,7 +359,7 @@ let getAppearance = (
variables: getVariables("variables", json, default, logger),
rules: mergeJsons(rulesJson, getJsonObjectFromDict(json, "rules")),
innerLayout: getWarningString(json, "innerLayout", "spaced", ~logger)->getInnerLayout,
labels: switch getWarningString(json, "labels", "above", ~logger) {
labels: switch getWarningString(json, "labels", "above", ~logger)->String.toLowerCase {
| "above" => Above
| "floating" => Floating
| "none" => Never
Expand Down
2 changes: 1 addition & 1 deletion src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ let cvcNumberInRange = (val, cardBrand) => {
})
cvcLengthInRange
}
let genreateFontsLink = (fonts: array<CardThemeType.fonts>) => {
let generateFontsLink = (fonts: array<CardThemeType.fonts>) => {
if fonts->Array.length > 0 {
fonts
->Array.map(item =>
Expand Down
7 changes: 5 additions & 2 deletions src/Components/AddBankAccount.res
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ToolTip = {
let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom)
<RenderIf condition={openTip}>
<button
className="h-auto max-w-20 w-auto cursor-pointer absolute m-1 px-1 py-2 top-[-3rem] right-[1em]"
className="h-auto max-w-30 w-auto cursor-pointer absolute m-1 px-1 py-2 top-[-3rem] right-[1em]"
style={
background: themeObj.colorBackground,
color: themeObj.colorDanger,
Expand All @@ -30,15 +30,18 @@ module ToolTip = {
@react.component
let make = (~modalData, ~setModalData) => {
let isDataAvailable = modalData->Option.isSome
let {themeObj, localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let {themeObj, localeString, config} = Recoil.useRecoilValueFromAtom(configAtom)
let {iframeId} = Recoil.useRecoilValueFromAtom(keys)
let (openToolTip, setOpenToolTip) = React.useState(_ => false)
let toolTipRef = React.useRef(Nullable.null)

let openModal = () => {
let metaData = [("config", config->Identity.anyTypeToJson)]->getJsonFromArrayOfJson

messageParentWindow([
("fullscreen", true->JSON.Encode.bool),
("iframeId", iframeId->JSON.Encode.string),
("metadata", metaData),
])
}
<div
Expand Down
37 changes: 37 additions & 0 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ let make = (
let line1Ref = React.useRef(Nullable.null)
let line2Ref = React.useRef(Nullable.null)
let cityRef = React.useRef(Nullable.null)
let bankAccountNumberRef = React.useRef(Nullable.null)
let postalRef = React.useRef(Nullable.null)
let (selectedBank, setSelectedBank) = Recoil.useRecoilState(userBank)
let (country, setCountry) = Recoil.useRecoilState(userCountry)

let (bankAccountNumber, setBankAccountNumber) = Recoil.useLoggedRecoilState(
userBankAccountNumber,
"bankAccountNumber",
logger,
)

let defaultCardProps = (
None,
_ => (),
Expand Down Expand Up @@ -462,6 +469,34 @@ let make = (
| PixKey => <PixPaymentInput label="pixKey" />
| PixCPF => <PixPaymentInput label="pixCPF" />
| PixCNPJ => <PixPaymentInput label="pixCNPJ" />
| BankAccountNumber | IBAN =>
<PaymentField
fieldName="IBAN"
setValue={setBankAccountNumber}
value=bankAccountNumber
onChange={ev => {
let value = ReactEvent.Form.target(ev)["value"]
setBankAccountNumber(prev => {
isValid: Some(value !== ""),
value,
errorString: value !== "" ? "" : localeString.ibanEmptyText,
})
}}
onBlur={ev => {
let value = ReactEvent.Focus.target(ev)["value"]
setBankAccountNumber(prev => {
...prev,
errorString: value !== "" ? "" : localeString.ibanEmptyText,
isValid: Some(value !== ""),
})
}}
paymentType
type_="text"
name="bankAccountNumber"
maxLength=42
inputRef=bankAccountNumberRef
placeholder="DE00 0000 0000 0000 0000 00"
/>
| Email
| InfoElement
| Country
Expand Down Expand Up @@ -777,6 +812,8 @@ let make = (
| PhoneCountryCode
| VpaId
| LanguagePreference(_)
| BankAccountNumber
| IBAN
| None => React.null
}}
</div>
Expand Down
17 changes: 13 additions & 4 deletions src/Components/PayNowButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Loader = {
}
}
@react.component
let make = () => {
let make = (~onClickHandler=?, ~label=?) => {
open RecoilAtoms
open Utils
let (showLoader, setShowLoader) = React.useState(() => false)
Expand All @@ -19,8 +19,10 @@ let make = () => {
let {sdkHandleConfirmPayment} = optionAtom->Recoil.useRecoilValueFromAtom

let confirmPayload = sdkHandleConfirmPayment->PaymentBody.confirmPayloadForSDKButton
let buttonText = sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)

let buttonText = switch label {
| Some(val) => val
| None => sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)
}

let handleMessage = (event: Types.event) => {
let json = event.data->Identity.anyTypeToJson->getStringFromJson("")->safeParse
Expand All @@ -35,6 +37,13 @@ let make = () => {
}
}

let onClickHandlerFunc = _ => {
switch onClickHandler {
| Some(fn) => fn()
| None => ()
}
}

let handleOnClick = _ => {
setIsPayNowButtonDisable(_ => true)
setShowLoader(_ => true)
Expand All @@ -45,7 +54,7 @@ let make = () => {
<div className="flex flex-col gap-1 h-auto w-full items-center">
<button
disabled=isPayNowButtonDisable
onClick=handleOnClick
onClick={onClickHandler->Option.isNone ? handleOnClick : onClickHandlerFunc}
className={`w-full flex flex-row justify-center items-center`}
style={
borderRadius: themeObj.buttonBorderRadius,
Expand Down
2 changes: 1 addition & 1 deletion src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
})

React.useEffect(() => {
CardUtils.genreateFontsLink(config.fonts)
CardUtils.generateFontsLink(config.fonts)
let dict = config.appearance.rules->getDictFromJson
if dict->Dict.toArray->Array.length > 0 {
generateStyleSheet("", dict, "themestyle")
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/ArabicLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
accountNumberText: `رقم حساب`,
cvcTextLabel: `رمز الحماية`,
emailLabel: `البريد الإلكتروني`,
ibanEmptyText: `لا يمكن أن يكون رقم IBAN فارغًا`,
emailEmptyText: `لا يمكن أن يكون البريد الإلكتروني فارغًا`,
emailInvalidText: `عنوان البريد الإلكتروني غير صالح`,
fullNameLabel: `الاسم الكامل`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/CatalanLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Nom del titular de la targeta`,
cardNickname: `Sobrenom de la targeta`,
billingNamePlaceholder: `Nom i cognom`,
ibanEmptyText: `L'IBAN no pot estar buit`,
emailEmptyText: `El correu electrònic no pot estar buit`,
emailInvalidText: `adressa de correu invàlida`,
line1EmptyText: `La línia d'adreça 1 no pot estar buida`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/ChineseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
stateEmptyText: `省/州不能为空`,
accountNumberText: `账户号码`,
emailLabel: `电子邮箱`,
ibanEmptyText: `IBAN 不能为空`,
emailEmptyText: `电子邮箱不能为空`,
emailInvalidText: `无效的电子邮箱地址`,
fullNameLabel: `全名`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/DeutschLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
stateEmptyText: `Der Status darf nicht leer sein`,
accountNumberText: `Accountnummer`,
emailLabel: `Email`,
ibanEmptyText: `IBAN darf nicht leer sein`,
emailEmptyText: `E-Mail darf nicht leer sein`,
emailInvalidText: `Ungültige E-Mail-Adresse`,
fullNameLabel: `Vollständiger Name`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/DutchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Naam van de kaarthouder`,
cardNickname: `Kaartbijnaam`,
billingNamePlaceholder: `Voornaam en achternaam`,
ibanEmptyText: `IBAN mag niet leeg zijn`,
emailEmptyText: `E-mail mag niet leeg zijn`,
emailInvalidText: `Ongeldig e-mailadres`,
line1EmptyText: `Adresregel 1 mag niet leeg zijn`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/EnglishGBLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
sortCodeText: "Sort Code",
cvcTextLabel: "CVC",
emailLabel: "Email",
ibanEmptyText: "IBAN cannot be empty",
emailEmptyText: "Email cannot be empty",
emailInvalidText: "Invalid email address",
line1Label: "Address line 1",
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/EnglishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
stateEmptyText: "State cannot be empty",
accountNumberText: "Account Number",
emailLabel: "Email",
ibanEmptyText: "IBAN cannot be empty",
emailEmptyText: "Email cannot be empty",
emailInvalidText: "Invalid email address",
fullNameLabel: "Full name",
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/FrenchBelgiumLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Nom du titulaire`,
cardNickname: `Pseudonyme de la carte`,
billingNamePlaceholder: `Nom et prénom`,
ibanEmptyText: `L'IBAN ne peut pas être vide`,
emailEmptyText: `L'e-mail ne peut pas être vide`,
emailInvalidText: `Adresse e-mail invalide`,
line1EmptyText: `La ligne d'adresse 1 ne peut pas être vide`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/FrenchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
stateEmptyText: `L'état ne peut pas être vide`,
accountNumberText: `Numéro de compte`,
emailLabel: `E-mail`,
ibanEmptyText: `L'IBAN ne peut pas être vide`,
emailEmptyText: `L'e-mail ne peut pas être vide`,
emailInvalidText: "Adresse e-mail invalide",
fullNameLabel: `Nom complet`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/HebrewLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
stateEmptyText: `המדינה לא יכולה להיות ריקה`,
accountNumberText: `מספר חשבון`,
emailLabel: `אימייל`,
ibanEmptyText: `ה-IBAN אינו יכול להיות ריק`,
emailEmptyText: `אימייל לא יכול להיות ריק`,
emailInvalidText: `כתובת אימייל לא חוקית`,
fullNameLabel: `שם מלא`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/ItalianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Nome del titolare della carta`,
cardNickname: `Soprannome della carta`,
billingNamePlaceholder: `Nome e cognome`,
ibanEmptyText: `L'IBAN non può essere vuoto`,
emailEmptyText: `L'e-mail non può essere vuota`,
emailInvalidText: `indirizzo email non valido`,
line1EmptyText: `La riga dell'indirizzo 1 non può essere vuota`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/JapaneseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cvcTextLabel: `セキュリティコード`,
accountNumberText: `口座番号`,
emailLabel: `Eメール`,
ibanEmptyText: `IBANは空にできません`,
emailEmptyText: `電子メールを空にすることはできません`,
emailInvalidText: `無効なメールアドレス`,
fullNameLabel: `フルネーム`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/LocaleStringTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type localeStrings = {
sortCodeText: string,
cvcTextLabel: string,
emailLabel: string,
ibanEmptyText: string,
emailEmptyText: string,
emailInvalidText: string,
accountNumberText: string,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/PolishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Imię i nazwisko posiadacza karty`,
cardNickname: `Przezwisko karty`,
billingNamePlaceholder: `Imię i nazwisko`,
ibanEmptyText: `IBAN nie może być pusty`,
emailEmptyText: `Adres e-mail nie może być pusty`,
emailInvalidText: `Niepoprawny adres email`,
line1EmptyText: `Linia adresu 1 nie może być pusta`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/PortugueseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Nome do titular do cartão`,
cardNickname: `Apelido do cartão`,
billingNamePlaceholder: `Nome e sobrenome`,
ibanEmptyText: `O IBAN não pode estar vazio`,
emailEmptyText: `O e-mail não pode ficar vazio`,
emailInvalidText: `Endereço de email invalido`,
line1EmptyText: `A linha de endereço 1 não pode ficar vazia`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/RussianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Имя держателя карты`,
cardNickname: `Прозвище карты`,
billingNamePlaceholder: `Имя и фамилия`,
ibanEmptyText: `IBAN не может быть пустым`,
emailEmptyText: `Электронная почта не может быть пустой`,
emailInvalidText: `Неверный адрес электронной почты`,
line1EmptyText: `Адресная строка 1 не может быть пустой.`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/SpanishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Nombre del titular de la tarjeta`,
cardNickname: `Apodo de la tarjeta`,
billingNamePlaceholder: `Nombre y apellido`,
ibanEmptyText: `El IBAN no puede estar vacío`,
emailEmptyText: `El correo electrónico no puede estar vacío.`,
emailInvalidText: `Dirección de correo electrónico no válida`,
line1EmptyText: `La línea de dirección 1 no puede estar vacía`,
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/SwedishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHolderName: `Korthållarens namn`,
cardNickname: `Kortets smeknamn`,
billingNamePlaceholder: `Förnamn och efternamn`,
ibanEmptyText: `IBAN får inte vara tomt`,
emailEmptyText: `E-post får inte vara tom`,
emailInvalidText: `Ogiltig e-postadress`,
line1EmptyText: `Adressrad 1 får inte vara tom`,
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/ACHBankDebit.res
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ let make = (~paymentType: CardThemeType.mode) => {
<Surcharge paymentMethod="bank_debit" paymentMethodType="ach" />
<Terms mode=ACHBankDebit />
<FullScreenPortal>
<BankDebitModal setModalData />
<BankDebitModal setModalData paymentType />
</FullScreenPortal>
</div>
</RenderIf>
Expand Down
Loading
Loading