diff --git a/src/screens/Connectors/Common/CommonConnectorUtils.res b/src/screens/Connectors/Common/CommonConnectorUtils.res index 80ecdbe09..860ff908d 100644 --- a/src/screens/Connectors/Common/CommonConnectorUtils.res +++ b/src/screens/Connectors/Common/CommonConnectorUtils.res @@ -5,6 +5,7 @@ let inputTypeMapperr = ipType => { | "Toggle" => Toggle | "Select" => Select | "MultiSelect" => MultiSelect + | "Radio" => Radio | _ => Text } } diff --git a/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegration.res b/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegration.res new file mode 100644 index 000000000..f3f0a0bae --- /dev/null +++ b/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegration.res @@ -0,0 +1,142 @@ +@react.component +let make = (~connector, ~setShowWalletConfigurationModal, ~update, ~onCloseClickCustomFun) => { + open APIUtils + open LogicUtils + open SamsungPayIntegrationUtils + let getURL = useGetURL() + let fetchDetails = useGetMethod() + let (merchantBusinessCountry, setMerchantBusinessCountry) = React.useState(_ => []) + let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Success) + let formState: ReactFinalForm.formState = ReactFinalForm.useFormState( + ReactFinalForm.useFormSubscription(["values"])->Nullable.make, + ) + let form = ReactFinalForm.useForm() + let {globalUIConfig: {font: {textColor}}} = React.useContext(ThemeProvider.themeContext) + let samsungPayFields = React.useMemo(() => { + try { + if connector->isNonEmptyString { + let samsungPayInputFields = + Window.getConnectorConfig(connector) + ->getDictFromJsonObject + ->getDictfromDict("connector_wallets_details") + ->getArrayFromDict("samsung_pay", []) + + samsungPayInputFields + } else { + [] + } + } catch { + | Exn.Error(e) => { + Js.log2("FAILED TO LOAD CONNECTOR CONFIG", e) + [] + } + } + }, [connector]) + + let setSamsungFormData = () => { + let initalFormValue = + formState.values + ->getDictFromJsonObject + ->getDictfromDict("connector_wallets_details") + ->getDictfromDict("samsung_pay") + ->getDictfromDict("merchant_credentials") + + form.change( + "connector_wallets_details.samsung_pay.merchant_credentials", + initalFormValue->samsungPayRequest->Identity.genericTypeToJson, + ) + } + + let getProcessorDetails = async () => { + try { + setScreenState(_ => Loading) + let paymentMethoConfigUrl = getURL(~entityName=PAYMENT_METHOD_CONFIG, ~methodType=Get) + let res = await fetchDetails( + `${paymentMethoConfigUrl}?connector=${connector}&paymentMethodType=samsung_pay`, + ) + let countries = + res + ->getDictFromJsonObject + ->getArrayFromDict("countries", []) + ->Array.map(item => { + let dict = item->getDictFromJsonObject + let countryList: SelectBox.dropdownOption = { + label: dict->getString("name", ""), + value: dict->getString("code", ""), + } + countryList + }) + + setMerchantBusinessCountry(_ => countries) + setSamsungFormData() + setScreenState(_ => Success) + } catch { + | _ => setScreenState(_ => Success) + } + } + + React.useEffect(() => { + if connector->LogicUtils.isNonEmptyString { + getProcessorDetails()->ignore + } + None + }, [connector]) + let onSubmit = () => { + update() + setShowWalletConfigurationModal(_ => false) + } + + let onCancel = () => { + onCloseClickCustomFun() + setShowWalletConfigurationModal(_ => false) + } + let samsungPayFields = + samsungPayFields + ->Array.mapWithIndex((field, index) => { + let samsungPayField = field->convertMapObjectToDict->CommonConnectorUtils.inputFieldMapper + let {name} = samsungPayField +