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 netecetera customisation props #213

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/components/modules/Netcetera3dsModule.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open ExternalThreeDsTypes

type module_ = {
initialiseNetceteraSDK: (string, string, statusType => unit) => unit,
initialiseNetceteraSDK: (string, string, string, statusType => unit) => unit,
generateAReqParams: (string, string, (statusType, aReqParams) => unit) => unit,
recieveChallengeParamsFromRN: (
string,
Expand Down Expand Up @@ -35,5 +35,5 @@ let (
mod.generateChallenge,
mod.isAvailable,
)
| None => ((_, _, _) => (), (_, _, _) => (), (_, _, _, _, _, _) => (), _ => (), false)
| None => ((_, _, _, _) => (), (_, _, _) => (), (_, _, _, _, _, _) => (), _ => (), false)
}
23 changes: 20 additions & 3 deletions src/hooks/NetceteraThreeDsHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ open ThreeDsUtils
open SdkStatusMessages
let isInitialisedPromiseRef = ref(None)

let initialisedNetceteraOnce = (~netceteraSDKApiKey, ~sdkEnvironment) => {
let initialisedNetceteraOnce = (
~netceteraSDKApiKey,
~sdkEnvironment,
~challengeCustomisationProps,
) => {
switch isInitialisedPromiseRef.contents {
| Some(promiseVal) => promiseVal
| None => {
let promiseVal = Promise.make((resolve, _reject) => {
Netcetera3dsModule.initialiseNetceteraSDK(
netceteraSDKApiKey,
sdkEnvironment->sdkEnvironmentToStrMapper,
challengeCustomisationProps,
status => resolve(status),
)
})
Expand All @@ -22,9 +27,15 @@ let initialisedNetceteraOnce = (~netceteraSDKApiKey, ~sdkEnvironment) => {
}

let useInitNetcetera = () => {
let (nativeProp, _) = React.useContext(NativePropContext.nativePropContext)
let challengeCustomisationProps =
nativeProp.configuration.netceteraChallengeUICustomization
->Utils.getJsonObjectFromRecord
->JSON.stringify

let logger = LoggerHook.useLoggerHook()
(~netceteraSDKApiKey, ~sdkEnvironment: GlobalVars.envType) => {
initialisedNetceteraOnce(~netceteraSDKApiKey, ~sdkEnvironment)
initialisedNetceteraOnce(~netceteraSDKApiKey, ~sdkEnvironment, ~challengeCustomisationProps)
->Promise.then(promiseVal => {
logger(
~logType=INFO,
Expand All @@ -49,6 +60,12 @@ let useExternalThreeDs = () => {
let apiLogWrapper = LoggerHook.useApiLogWrapper()
let (_, setLoading) = React.useContext(LoadingContext.loadingContext)

let (nativeProp, _) = React.useContext(NativePropContext.nativePropContext)
let challengeCustomisationProps =
nativeProp.configuration.netceteraChallengeUICustomization
->Utils.getJsonObjectFromRecord
->JSON.stringify

(
~baseUrl,
~netceteraSDKApiKey,
Expand Down Expand Up @@ -401,7 +418,7 @@ let useExternalThreeDs = () => {
}

let startNetcetera3DSFlow = () => {
initialisedNetceteraOnce(~netceteraSDKApiKey, ~sdkEnvironment)
initialisedNetceteraOnce(~netceteraSDKApiKey, ~sdkEnvironment, ~challengeCustomisationProps)
->Promise.then(statusInfo => {
logger(
~logType=INFO,
Expand Down
157 changes: 157 additions & 0 deletions src/types/NetceteraCustomisationType.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
open Utils

type labelCustomization = {
textFontName?: string,
textColor?: string,
textFontSize?: float,
headingTextFontName?: string,
headingTextColor?: string,
headingTextFontSize?: float,
}

type textBoxCustomization = {
textFontName?: string,
textColor?: string,
textFontSize?: float,
borderWidth?: float,
borderColor?: string,
cornerRadius?: float,
}

type toolbarCustomization = {
textFontName?: string,
textColor?: string,
textFontSize?: string,
backgroundColor?: string,
headerText?: string,
buttonText?: string,
}

type buttonCustomization = {
buttonType: string,
backgroundColor?: string,
cornerRadius?: float,
textFontName?: string,
textFontSize?: string,
textColor?: string,
}

type viewCustomization = {
challengeViewBackgroundColor?: string,
progressViewBackgroundColor?: string,
}

type netceteraChallengeUICustomization = {
labelCustomization?: labelCustomization,
textBoxCustomization?: textBoxCustomization,
toolbarCustomization?: toolbarCustomization,
buttonCustomization?: array<buttonCustomization>,
viewCustomization?: viewCustomization,
}

type netceteraChallengeUICustomizationType = {
locale: string,
lightMode?: option<netceteraChallengeUICustomization>,
darkMode?: option<netceteraChallengeUICustomization>,
}

let fun = netceteraChallengeUICustomization => {
switch netceteraChallengeUICustomization {
| Some(uiObj) =>
let labelObj = getObj(uiObj, "labelCustomization", Dict.make())
let labelCustomization = if labelObj != Dict.make() {
Some({
headingTextFontSize: ?getOptionFloat(labelObj, "headingTextFontSize"),
textFontSize: ?getOptionFloat(labelObj, "textFontSize"),
textFontName: ?getOptionString(labelObj, "textFontName"),
headingTextFontName: ?getOptionString(labelObj, "headingTextFontName"),
headingTextColor: ?getOptionString(labelObj, "headingTextColor"),
textColor: ?getOptionString(labelObj, "textColor"),
})
} else {
None
}

let textBoxObj = getObj(uiObj, "textBoxCustomization", Dict.make())
let textBoxCustomization = if textBoxObj != Dict.make() {
Some({
borderColor: ?getOptionString(textBoxObj, "borderColor"),
borderWidth: ?getOptionFloat(textBoxObj, "borderWidth"),
cornerRadius: ?getOptionFloat(textBoxObj, "cornerRadius"),
textFontName: ?getOptionString(textBoxObj, "textFontName"),
textColor: ?getOptionString(textBoxObj, "textColor"),
textFontSize: ?getOptionFloat(textBoxObj, "textFontSize"),
})
} else {
None
}

let toolbarObj = getObj(uiObj, "toolbarCustomization", Dict.make())
let toolbarCustomization = if toolbarObj != Dict.make() {
Some({
backgroundColor: ?getOptionString(toolbarObj, "backgroundColor"),
textColor: ?getOptionString(toolbarObj, "textColor"),
buttonText: ?getOptionString(toolbarObj, "buttonText"),
headerText: ?getOptionString(toolbarObj, "headerText"),
textFontName: ?getOptionString(toolbarObj, "textFontName"),
textFontSize: ?getOptionString(toolbarObj, "textFontSize"),
})
} else {
None
}

let buttonCustomization = getArrayFromDict(uiObj, "buttonCustomization", [])
let buttonCustomizationArray = buttonCustomization->Array.map(obj => {
let objDict = getDictFromJson(obj)
{
buttonType: getOptionString(objDict, "buttonType")->Option.getOr("SUBMIT"),
backgroundColor: ?getOptionString(objDict, "backgroundColor"),
cornerRadius: ?getOptionFloat(objDict, "cornerRadius"),
textFontName: ?getOptionString(objDict, "textFontName"),
textFontSize: ?getOptionString(objDict, "textFontSize"),
textColor: ?getOptionString(objDict, "textColor"),
}
})

let viewObj = getObj(uiObj, "viewCustomization", Dict.make())
let viewCustomization = if viewObj != Dict.make() {
Some({
challengeViewBackgroundColor: ?getOptionString(viewObj, "challengeViewBackgroundColor"),
progressViewBackgroundColor: ?getOptionString(viewObj, "progressViewBackgroundColor"),
})
} else {
None
}

let finalResult = {
?labelCustomization,
?textBoxCustomization,
?toolbarCustomization,
buttonCustomization: buttonCustomizationArray,
?viewCustomization,
}

Some(finalResult)
| None => None
}
}

let getChallengeCustomisationRecord = (netceteraChallengeUICustomizationDict, locale) => {
let locale = locale->Option.getOr("en")
let lightModeDict =
netceteraChallengeUICustomizationDict
->Option.getOr(Dict.make())
->Dict.get("lightModeCustomization")
->Option.flatMap(JSON.Decode.object)

let darkModeDict =
netceteraChallengeUICustomizationDict
->Option.getOr(Dict.make())
->Dict.get("darkModeCustomization")
->Option.flatMap(JSON.Decode.object)

let lightX = fun(lightModeDict)
let darkX = fun(darkModeDict)

{locale, lightMode: lightX, darkMode: darkX}
}
12 changes: 12 additions & 0 deletions src/types/SdkTypes.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Utils
open NetceteraCustomisationType

type localeTypes =
| En
Expand Down Expand Up @@ -250,6 +251,9 @@ type configurationType = {
netceteraSDKApiKey: option<string>,
displayDefaultSavedPaymentIcon: bool,
enablePartialLoading: bool,
netceteraChallengeUICustomization: option<
NetceteraCustomisationType.netceteraChallengeUICustomizationType,
>,
}

type sdkState =
Expand Down Expand Up @@ -787,6 +791,10 @@ let getAppearanceObj = (
let parseConfigurationDict = (configObj, from) => {
let shippingDetailsDict =
configObj->Dict.get("shippingDetails")->Option.flatMap(JSON.Decode.object)

let netceteraChallengeUICustomizationDict =
configObj->Dict.get("netceteraChallengeUICustomization")->Option.flatMap(JSON.Decode.object)

let billingDetailsDict = getObj(configObj, "defaultBillingDetails", Dict.make())

let _customerDict = configObj->Dict.get("customer")->Option.flatMap(JSON.Decode.object)
Expand All @@ -797,6 +805,7 @@ let parseConfigurationDict = (configObj, from) => {
->String.split(" ")

let appearanceDict = configObj->Dict.get("appearance")->Option.flatMap(JSON.Decode.object)
let locale = getOptionString(appearanceDict->Option.getOr(Dict.make()), "locale")
let appearance = {
from == "rn" || from == "flutter" || WebKit.platform === #web
? switch appearanceDict {
Expand Down Expand Up @@ -857,6 +866,9 @@ let parseConfigurationDict = (configObj, from) => {
savedPaymentScreenHeaderText: getOptionString(configObj, "savedPaymentSheetHeaderLabel"),
displayDefaultSavedPaymentIcon: getBool(configObj, "displayDefaultSavedPaymentIcon", true),
enablePartialLoading: getBool(configObj, "enablePartialLoading", false),
netceteraChallengeUICustomization: Some(
getChallengeCustomisationRecord(netceteraChallengeUICustomizationDict, locale),
),
// customer: switch customerDict {
// | Some(obj) =>
// Some({
Expand Down
Loading