Skip to content

Commit

Permalink
feat: language preference for mifinity added (#502)
Browse files Browse the repository at this point in the history
Co-authored-by: Pritish Budhiraja <[email protected]>
  • Loading branch information
sakksham7 and PritishBudhiraja authored Jul 17, 2024
1 parent 74ffd68 commit f9f15ca
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ let make = () => {
"hyperComponentName",
)->Types.getHyperComponentNameFromStr

<PreMountLoader publishableKey sessionId clientSecret endpoint ephemeralKey hyperComponentName />
<PreMountLoader
publishableKey sessionId clientSecret endpoint ephemeralKey hyperComponentName
/>
}
| "achBankTransfer"
| "bacsBankTransfer"
Expand Down
2 changes: 1 addition & 1 deletion src/CardTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type recoilConfig = {
let getLocaleObject = async string => {
try {
let locale = if string == "auto" {
navigator["language"]
Window.language
} else {
string
}
Expand Down
2 changes: 2 additions & 0 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ let make = (
| ShippingAddressPincode
| ShippingAddressState
| PhoneCountryCode
| LanguagePreference(_)
| ShippingAddressCountry(_) => React.null
}}
</div>
Expand Down Expand Up @@ -767,6 +768,7 @@ let make = (
| DateOfBirth
| PhoneCountryCode
| VpaId
| LanguagePreference(_)
| None => React.null
}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
setConfig(_ => {
config: {
appearance,
locale: config.locale,
locale: config.locale === "auto" ? Window.language : config.locale,
fonts: config.fonts,
clientSecret: config.clientSecret,
ephemeralKey: config.ephemeralKey,
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ let make = (
isCustomerAcceptanceRequired,
nickname,
isCardBrandValid,
isManualRetryEnabled
isManualRetryEnabled,
))
useSubmitPaymentData(submitCallback)

Expand Down
25 changes: 15 additions & 10 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Utils

type paymentFlow = InvokeSDK | RedirectToURL | QrFlow

type paymentFlowWithConnector = array<(paymentFlow, array<string>)>
Expand Down Expand Up @@ -38,6 +40,7 @@ type paymentMethodsFields =
| CryptoCurrencyNetworks
| DateOfBirth
| VpaId
| LanguagePreference(array<string>)

let getPaymentMethodsFieldsOrder = paymentMethodField => {
switch paymentMethodField {
Expand Down Expand Up @@ -574,7 +577,7 @@ let getPaymentMethodsFieldTypeFromString = (str, isBancontact) => {
}

let getOptionsFromPaymentMethodFieldType = (dict, key, ~isAddressCountry=true) => {
let options = dict->Utils.getArrayValFromJsonDict(key, "options")
let options = dict->getArrayValFromJsonDict(key, "options")
switch options->Array.get(0)->Option.getOr("") {
| "" => None
| "ALL" => {
Expand All @@ -598,7 +601,7 @@ let getPaymentMethodsFieldTypeFromDict = dict => {
let key = keysArr->Array.get(0)->Option.getOr("")
switch key {
| "user_currency" => {
let options = dict->Utils.getArrayValFromJsonDict("user_currency", "options")
let options = dict->getArrayValFromJsonDict("user_currency", "options")
Currency(options)
}
| "user_country" => dict->getOptionsFromPaymentMethodFieldType("user_country")
Expand All @@ -608,6 +611,10 @@ let getPaymentMethodsFieldTypeFromDict = dict => {
"user_shipping_address_country",
~isAddressCountry=false,
)
| "language_preference" => {
let options = dict->getArrayValFromJsonDict("language_preference", "options")
LanguagePreference(options)
}
| _ => None
}
}
Expand Down Expand Up @@ -788,8 +795,6 @@ type paymentMethodList = {
merchant_name: string,
}

open Utils

let defaultPaymentMethodType = {
payment_method_type: "",
payment_experience: [],
Expand Down Expand Up @@ -913,17 +918,17 @@ let getAchConnectors = (dict, str) => {

let getDynamicFieldsFromJsonDict = (dict, isBancontact) => {
let requiredFields =
Utils.getJsonFromDict(dict, "required_fields", JSON.Encode.null)
->Utils.getDictFromJson
getJsonFromDict(dict, "required_fields", JSON.Encode.null)
->getDictFromJson
->Dict.valuesToArray

requiredFields->Array.map(requiredField => {
let requiredFieldsDict = requiredField->Utils.getDictFromJson
let requiredFieldsDict = requiredField->getDictFromJson
{
required_field: requiredFieldsDict->Utils.getString("required_field", ""),
display_name: requiredFieldsDict->Utils.getString("display_name", ""),
required_field: requiredFieldsDict->getString("required_field", ""),
display_name: requiredFieldsDict->getString("display_name", ""),
field_type: requiredFieldsDict->getFieldType(isBancontact),
value: requiredFieldsDict->Utils.getString("value", ""),
value: requiredFieldsDict->getString("value", ""),
}
})
}
Expand Down
1 change: 0 additions & 1 deletion src/Types/CardThemeType.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ type theme = Default | Brutal | Midnight | Soft | Charcoal | NONE

type innerLayout = Spaced | Compressed

@val external navigator: 'a = "navigator"
type showLoader = Auto | Always | Never

type mode =
Expand Down
8 changes: 8 additions & 0 deletions src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ let useSetInitialRequiredFields = (
}
| None => ()
}
| LanguagePreference(_)
| SpecialField(_)
| InfoElement
| CardNumber
Expand Down Expand Up @@ -433,6 +434,7 @@ let useRequiredFieldsBody = (
~isAllStoredCardsHaveName,
~setRequiredFieldsBody,
) => {
let configValue = Recoil.useRecoilValueFromAtom(configAtom)
let email = Recoil.useRecoilValueFromAtom(userEmailAddress)
let vpaId = Recoil.useRecoilValueFromAtom(userVpaId)
let fullName = Recoil.useRecoilValueFromAtom(userFullName)
Expand Down Expand Up @@ -464,6 +466,12 @@ let useRequiredFieldsBody = (
| PhoneCountryCode => phone.countryCode->Option.getOr("")
| Currency(_) => currency
| Country => country
| LanguagePreference(languageOptions) =>
languageOptions->Array.includes(
configValue.config.locale->String.toUpperCase->String.split("-")->Array.joinWith("_"),
)
? configValue.config.locale
: "en"
| Bank =>
(
Bank.getBanks(paymentMethodType)
Expand Down
3 changes: 3 additions & 0 deletions src/Window.res
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ external userAgent: string = "userAgent"
@val @scope("navigator")
external sendBeacon: (string, string) => unit = "sendBeacon"

@val @scope("navigator")
external language: string = "language"

@val @scope(("window", "location"))
external hostname: string = "hostname"

Expand Down

0 comments on commit f9f15ca

Please sign in to comment.