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 +
Int.toString}> + {switch name { + | "merchant_business_country" => + + | _ => + + }} +
+ }) + ->React.array + +
+ +
+ } + sectionHeight="!h-screen"> +
+ {samsungPayFields} +
+
+
+ +
+} diff --git a/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegrationTypes.res b/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegrationTypes.res new file mode 100644 index 000000000..d8890cff5 --- /dev/null +++ b/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegrationTypes.res @@ -0,0 +1,6 @@ +type samsungPay = { + merchant_business_country: string, + merchant_display_name: string, + service_id: string, + allowed_brands: array, +} diff --git a/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegrationUtils.res b/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegrationUtils.res new file mode 100644 index 000000000..4cc5ed517 --- /dev/null +++ b/src/screens/Connectors/ConnectorMetaData/SamsungPay/SamsungPayIntegrationUtils.res @@ -0,0 +1,47 @@ +open SamsungPayIntegrationTypes +open LogicUtils + +let samsungPayRequest = dict => { + merchant_business_country: dict->getString("merchant_business_country", ""), + merchant_display_name: dict->getString("merchant_display_name", ""), + service_id: dict->getString("service_id", ""), + allowed_brands: dict->getStrArrayFromDict( + "allowed_brands", + ["visa", "masterCard", "amex", "discover"], + ), +} + +let samsungPayNameMapper = (~name) => { + `connector_wallets_details.samsung_pay.merchant_credentials.${name}` +} + +let samsungPayValueInput = (~samsungPayField: CommonConnectorTypes.inputField, ~fill) => { + open CommonConnectorHelper + let {\"type", name} = samsungPayField + let formName = samsungPayNameMapper(~name) + + { + switch \"type" { + | Text => textInput(~field={samsungPayField}, ~formName) + | Select => selectInput(~field={samsungPayField}, ~formName) + | MultiSelect => multiSelectInput(~field={samsungPayField}, ~formName) + | Radio => radioInput(~field={samsungPayField}, ~formName, ~fill, ()) + | _ => textInput(~field={samsungPayField}, ~formName) + } + } +} + +let validateSamsungPay = (json: JSON.t) => { + let {merchant_business_country, merchant_display_name, service_id, allowed_brands} = + getDictFromJsonObject(json) + ->getDictfromDict("connector_wallets_details") + ->getDictfromDict("samsung_pay") + ->getDictfromDict("merchant_credentials") + ->samsungPayRequest + merchant_business_country->isNonEmptyString && + merchant_display_name->isNonEmptyString && + service_id->isNonEmptyString && + allowed_brands->Array.length > 0 + ? Button.Normal + : Button.Disabled +} diff --git a/src/screens/Connectors/ConnectorPaymentMethod.res b/src/screens/Connectors/ConnectorPaymentMethod.res index 03928dbfe..81f800eae 100644 --- a/src/screens/Connectors/ConnectorPaymentMethod.res +++ b/src/screens/Connectors/ConnectorPaymentMethod.res @@ -56,7 +56,7 @@ let make = ( let mixpanelEventName = isUpdateFlow ? "processor_step2_onUpdate" : "processor_step2" - let onSubmit = async () => { + let onSubmit = async (values, _form: ReactFinalForm.formApi) => { mixpanelEvent(~eventName=mixpanelEventName) try { setScreenState(_ => Loading) @@ -66,7 +66,7 @@ let make = ( metadata: metaData, } let body = - constructConnectorRequestBody(obj, initialValues)->ignoreFields( + constructConnectorRequestBody(obj, values)->ignoreFields( connectorID->Option.getOr(""), connectorIgnoredField, ) @@ -98,10 +98,11 @@ let make = ( } } } + Nullable.null } -
+
@@ -111,7 +112,7 @@ let make = (
-
diff --git a/src/screens/Connectors/ConnectorTypes.res b/src/screens/Connectors/ConnectorTypes.res index 7753a9ff7..689459782 100644 --- a/src/screens/Connectors/ConnectorTypes.res +++ b/src/screens/Connectors/ConnectorTypes.res @@ -131,6 +131,7 @@ type paymentMethodTypes = | Debit | GooglePay | ApplePay + | SamsungPay | PayPal | BankDebit | OpenBankingPIS diff --git a/src/screens/Connectors/ConnectorUIUtils/PaymentMethod.res b/src/screens/Connectors/ConnectorUIUtils/PaymentMethod.res index ec20c16f4..7a5ecc953 100644 --- a/src/screens/Connectors/ConnectorUIUtils/PaymentMethod.res +++ b/src/screens/Connectors/ConnectorUIUtils/PaymentMethod.res @@ -36,8 +36,12 @@ module CardRenderer = { ReactFinalForm.useFormSubscription(["values"])->Nullable.make, ) let form = ReactFinalForm.useForm() - let initalFormValue = React.useMemo(() => { - formState.values->getDictFromJsonObject->getDictfromDict("metadata") + let (meteDataInitialValues, connectorWalletsInitialValues) = React.useMemo(() => { + let formValues = formState.values->getDictFromJsonObject + ( + formValues->getDictfromDict("metadata"), + formValues->getDictfromDict("connector_wallets_details"), + ) }, []) let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom let {globalUIConfig: {font: {textColor}}} = React.useContext(ThemeProvider.themeContext) @@ -87,7 +91,9 @@ module CardRenderer = { } let showSideModal = methodVariant => { - ((methodVariant === GooglePay || methodVariant === ApplePay) && + ((methodVariant === GooglePay || + methodVariant === ApplePay || + methodVariant === SamsungPay) && { switch connector->getConnectorNameTypeFromString { | Processors(TRUSTPAY) @@ -177,7 +183,12 @@ module CardRenderer = { let p2RegularTextStyle = `${HSwitchUtils.getTextClass((P2, Medium))} text-grey-700 opacity-50` let removeSelectedWallet = () => { - form.change("metadata", initalFormValue->Identity.genericTypeToJson) + form.change("metadata", meteDataInitialValues->Identity.genericTypeToJson) + form.change( + "connector_wallets_details", + connectorWalletsInitialValues->Identity.genericTypeToJson, + ) + setSelectedWallet(_ => Dict.make()->itemProviderMapper) } @@ -286,6 +297,7 @@ module CardRenderer = { condition={selectedWallet.payment_method_type->getPaymentMethodTypeFromString === ApplePay || selectedWallet.payment_method_type->getPaymentMethodTypeFromString === GooglePay || + selectedWallet.payment_method_type->getPaymentMethodTypeFromString === SamsungPay || (paymentMethod->getPaymentMethodFromString === BankDebit && shouldShowPMAuthSidebar)}> { | "apple_pay" => ApplePay | "paypal" => PayPal | "open_banking_pis" => OpenBankingPIS + | "samsung_pay" => SamsungPay | _ => UnknownPaymentMethodType(paymentMethodType) } } @@ -920,6 +921,7 @@ let configKeysToIgnore = [ "metadata", "connector_webhook_details", "additional_merchant_data", + "connector_wallets_details", ] let verifyConnectorIgnoreField = [ @@ -1435,6 +1437,12 @@ let constructConnectorRequestBody = (wasmRequest: wasmRequest, payload: JSON.t) ? JSON.Encode.null : dict->getDictfromDict("pm_auth_config")->JSON.Encode.object, ), + ( + "connector_wallets_details", + dict->getDictfromDict("connector_wallets_details")->isEmptyDict + ? JSON.Encode.null + : dict->getDictfromDict("connector_wallets_details")->JSON.Encode.object, + ), ]) values diff --git a/src/screens/Connectors/PaymentMethodAdditionalDetails/AdditionalDetailsSidebar.res b/src/screens/Connectors/PaymentMethodAdditionalDetails/AdditionalDetailsSidebar.res index c2ec07ab1..abf9f607b 100644 --- a/src/screens/Connectors/PaymentMethodAdditionalDetails/AdditionalDetailsSidebar.res +++ b/src/screens/Connectors/PaymentMethodAdditionalDetails/AdditionalDetailsSidebar.res @@ -47,6 +47,13 @@ module AdditionalDetailsSidebarComp = { + | SamsungPay => + | _ => React.null }}