diff --git a/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/ConnectPayPal.res b/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/ConnectPayPal.res index ada412677..b82e66e32 100644 --- a/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/ConnectPayPal.res +++ b/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/ConnectPayPal.res @@ -387,7 +387,7 @@ let make = ( // And whenever we are changing the flow from Manual to Automatic or vice-versa // To check if the flow is changed we are using auth type (BodyKey for Manual and SignatureKey for Automatic) // It deletes the old tracking id associated with the connector id and deletes the connector credentials - + setScreenState(_ => Loading) let _ = await deleteTrackingDetails(connectorId, connector) let _ = await updateConnectorDetails(values) @@ -395,53 +395,58 @@ let make = ( | Automatic => setSetupAccountStatus(._ => Redirecting_to_paypal) | Manual | _ => setCurrentStep(_ => ConnectorTypes.IntegFields) } + setScreenState(_ => Success) } catch { - | Js.Exn.Error(_e) => () + | Js.Exn.Error(_e) => setScreenState(_ => Error("Unable to change the configuartion")) } } - let handleOnSubmitRevamp = async (values, _) => { + let handleOnSubmit = async (values, _) => { open PayPalFlowUtils - let authType = initialValues->getAuthTypeFromConnectorDetails - - // create flow - if !isUpdateFlow { - switch configuartionType { - | Automatic => { - await updateConnectorDetails(values) - setSetupAccountStatus(._ => Redirecting_to_paypal) - } + try { + let authType = initialValues->getAuthTypeFromConnectorDetails + + // create flow + if !isUpdateFlow { + switch configuartionType { + | Automatic => { + await updateConnectorDetails(values) + setSetupAccountStatus(._ => Redirecting_to_paypal) + } - | Manual | _ => - setConnectorAsActive(values) - setCurrentStep(_ => ConnectorTypes.IntegFields) - } - } // update flow if body type is changed - else if ( - authType !== - PayPalFlowUtils.getBodyType(isUpdateFlow, configuartionType) - ->String.toLowerCase - ->ConnectorUtils.mapAuthType - ) { - showPopUp({ - popUpType: (Warning, WithIcon), - heading: "Warning changing configuration", - description: React.string(`Modifying the configuration will result in the loss of existing details associated with this connector. Are you certain you want to continue?`), - handleConfirm: { - text: "Proceed", - onClick: {_ => handleChangeAuthType(values)->ignore}, - }, - handleCancel: {text: "Cancel"}, - }) - } else { - // update flow if body type is not changed - switch configuartionType { - | Automatic => setCurrentStep(_ => ConnectorTypes.PaymentMethods) - | Manual | _ => { + | Manual | _ => setConnectorAsActive(values) setCurrentStep(_ => ConnectorTypes.IntegFields) } + } // update flow if body type is changed + else if ( + authType !== + PayPalFlowUtils.getBodyType(isUpdateFlow, configuartionType) + ->String.toLowerCase + ->ConnectorUtils.mapAuthType + ) { + showPopUp({ + popUpType: (Warning, WithIcon), + heading: "Warning changing configuration", + description: React.string(`Modifying the configuration will result in the loss of existing details associated with this connector. Are you certain you want to continue?`), + handleConfirm: { + text: "Proceed", + onClick: {_ => handleChangeAuthType(values)->ignore}, + }, + handleCancel: {text: "Cancel"}, + }) + } else { + // update flow if body type is not changed + switch configuartionType { + | Automatic => setCurrentStep(_ => ConnectorTypes.PaymentMethods) + | Manual | _ => { + setConnectorAsActive(values) + setCurrentStep(_ => ConnectorTypes.IntegFields) + } + } } + } catch { + | _ => setScreenState(_ => Error("Failed to submit")) } Js.Nullable.null } @@ -471,7 +476,7 @@ let make = (
+ onSubmit={handleOnSubmit}>
{ + open HeadlessUI + let showPopUp = PopUpState.useShowPopUp() + let showToast = ToastState.useShowToast() + let deleteTrackingDetails = PayPalFlowUtils.useDeleteTrackingDetails() + let updateConnectorAccountDetails = PayPalFlowUtils.useDeleteConnectorAccountDetails() + let setSetupAccountStatus = Recoil.useSetRecoilState(HyperswitchAtom.paypalAccountStatusAtom) + let connectorInfo = connectorInfoDict->ConnectorTableUtils.getProcessorPayloadType + + let openConfirmationPopUp = _ => { + showPopUp({ + popUpType: (Warning, WithIcon), + heading: "Confirm Action ? ", + description: `You are about to ${isConnectorDisabled + ? "Enable" + : "Disable"->String.toLowerCase} this connector. This might impact your desired routing configurations. Please confirm to proceed.`->React.string, + handleConfirm: { + text: "Confirm", + onClick: _ => disableConnector(isConnectorDisabled)->ignore, + }, + handleCancel: {text: "Cancel"}, + }) + } + + let connectorStatusAvailableToSwitch = isConnectorDisabled ? "Enable" : "Disable" + + let updateConnectorAuthType = async values => { + try { + setScreenState(_ => PageLoaderWrapper.Loading) + let res = await updateConnectorAccountDetails( + values, + connectorInfo.merchant_connector_id, + connectorInfo.connector_name, + isUpdateFlow, + true, + "inactive", + ) + setInitialValues(_ => res) + setScreenState(_ => Success) + } catch { + | Js.Exn.Error(e) => { + let err = Js.Exn.message(e)->Option.getWithDefault("Something went wrong!") + Js.Exn.raiseError(err) + } + } + } + + let handleNewPayPalAccount = async () => { + try { + await deleteTrackingDetails(connectorInfo.merchant_connector_id, connectorInfo.connector_name) + await updateConnectorAuthType(connectorInfoDict->Js.Json.object_) + } catch { + | Js.Exn.Error(e) => { + let err = Js.Exn.message(e)->Option.getWithDefault("Something went wrong!") + showToast(~message=err, ~toastType=ToastError, ()) + } + } + } + + let popupForNewPayPalAccount = _ => { + showPopUp({ + popUpType: (Warning, WithIcon), + heading: "Confirm Action ?", + description: `By changing this the old account details will be lost `->React.string, + handleConfirm: { + text: "Confirm", + onClick: _ => { + handleNewPayPalAccount()->ignore + setCurrentStep(_ => ConnectorTypes.AutomaticFlow) + setSetupAccountStatus(._ => PayPalFlowTypes.Redirecting_to_paypal) + }, + }, + handleCancel: {text: "Cancel"}, + }) + } + + + {popoverProps => <> + {buttonProps => } + + {panelProps => { +
+ {<> + ConnectorUtils.mapAuthType === + #SignatureKey}> + popupForNewPayPalAccount()} + /> + + { + setCurrentStep(_ => ConnectorTypes.AutomaticFlow) + setSetupAccountStatus(._ => PayPalFlowTypes.Connect_paypal_landing) + }} + /> + ConnectorUtils.mapAuthType === + #BodyKey}> + { + setCurrentStep(_ => ConnectorTypes.IntegFields) + setSetupAccountStatus(._ => PayPalFlowTypes.Manual_setup_flow) + }} + /> + + ConnectorUtils.mapAuthType === + #SignatureKey}> + { + setCurrentStep(_ => updateStepValue) + }} + /> + + { + openConfirmationPopUp() + }} + /> + } +
+ }} +
+ } +
+} diff --git a/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/PayPalFlowUtils.res b/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/PayPalFlowUtils.res index f789fec5e..b64c82087 100644 --- a/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/PayPalFlowUtils.res +++ b/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/PayPalFlowUtils.res @@ -186,7 +186,7 @@ let useDeleteTrackingDetails = () => { let _res = await updateDetails(url, body, Post, ()) } catch { | Js.Exn.Error(e) => { - let err = Js.Exn.message(e)->Belt.Option.getWithDefault("Failed to Fetch!") + let err = Js.Exn.message(e)->Belt.Option.getWithDefault("Failed to update!") Js.Exn.raiseError(err) } } diff --git a/src/screens/HyperSwitch/Connectors/ConnectorAccountDetails.res b/src/screens/HyperSwitch/Connectors/ConnectorAccountDetails.res index fc17d3e50..b6ca3eca7 100644 --- a/src/screens/HyperSwitch/Connectors/ConnectorAccountDetails.res +++ b/src/screens/HyperSwitch/Connectors/ConnectorAccountDetails.res @@ -2,10 +2,11 @@ let make = (~setCurrentStep, ~setInitialValues, ~initialValues, ~isUpdateFlow, ~isPayoutFlow) => { open ConnectorUtils open APIUtils + open LogicUtils open ConnectorAccountDetailsHelper let url = RescriptReactRouter.useUrl() let showToast = ToastState.useShowToast() - let connector = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("name", "") + let connector = UrlUtils.useGetFilterDictFromUrl("")->getString("name", "") let connectorID = url.path->Belt.List.toArray->Belt.Array.get(1)->Option.getWithDefault("") let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading) let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom @@ -58,20 +59,17 @@ let make = (~setCurrentStep, ~setInitialValues, ~initialValues, ~isUpdateFlow, ~ let (showModal, setShowModal) = React.useState(_ => false) let updatedInitialVal = React.useMemo1(() => { - let initialValuesToDict = initialValues->LogicUtils.getDictFromJsonObject + let initialValuesToDict = initialValues->getDictFromJsonObject if !isUpdateFlow { if connector === "paypal" { initialValuesToDict->Dict.set( "connector_label", - initialValues - ->LogicUtils.getDictFromJsonObject - ->LogicUtils.getString("connector_label", "") - ->Js.Json.string, + initialValues->getDictFromJsonObject->getString("connector_label", "")->Js.Json.string, ) initialValuesToDict->Js.Dict.set( "profile_id", - initialValuesToDict->LogicUtils.getString("profile_id", "")->Js.Json.string, + initialValuesToDict->getString("profile_id", "")->Js.Json.string, ) } else if connector->String.length > 0 { initialValuesToDict->Dict.set( @@ -183,7 +181,7 @@ let make = (~setCurrentStep, ~setInitialValues, ~initialValues, ~isUpdateFlow, ~ let validateMandatoryField = values => { let errors = Dict.make() let valuesFlattenJson = values->JsonFlattenUtils.flattenObject(true) - let profileId = valuesFlattenJson->LogicUtils.getString("profile_id", "") + let profileId = valuesFlattenJson->getString("profile_id", "") if profileId->String.length === 0 { Dict.set(errors, "Profile Id", `Please select your business profile`->Js.Json.string) } diff --git a/src/screens/HyperSwitch/Connectors/ConnectorHome.res b/src/screens/HyperSwitch/Connectors/ConnectorHome.res index c722a358f..dad1a93d1 100644 --- a/src/screens/HyperSwitch/Connectors/ConnectorHome.res +++ b/src/screens/HyperSwitch/Connectors/ConnectorHome.res @@ -131,7 +131,7 @@ let make = (~isPayoutFlow=false, ~showStepIndicator=true, ~showBreadCrumb=true) let borderWidth = isPayoutFlow ? "w-8/12" : "w-9/12" let setSetupAccountStatus = Recoil.useSetRecoilState(HyperswitchAtom.paypalAccountStatusAtom) - let getPayPalStatus = React.useCallback2(async () => { + let getPayPalStatus = React.useCallback3(async () => { open PayPalFlowUtils open LogicUtils try { @@ -163,12 +163,11 @@ let make = (~isPayoutFlow=false, ~showStepIndicator=true, ~showBreadCrumb=true) } setScreenState(_ => PageLoaderWrapper.Success) } catch { - // TODO: check error cases | _ => setScreenState(_ => PageLoaderWrapper.Custom) } - }, (setInitialValues, setSetupAccountStatus)) + }, (connector, setInitialValues, setSetupAccountStatus)) - let customUI = + let customUiForPaypal = - +
{ - open HeadlessUI - let showPopUp = PopUpState.useShowPopUp() - let deleteTrackingDetails = PayPalFlowUtils.useDeleteTrackingDetails() - let updateConnectorAccountDetails = PayPalFlowUtils.useDeleteConnectorAccountDetails() - let setSetupAccountStatus = Recoil.useSetRecoilState(HyperswitchAtom.paypalAccountStatusAtom) - let connectorInfo = connectorInfoDict->ConnectorTableUtils.getProcessorPayloadType - - let openConfirmationPopUp = _ => { - showPopUp({ - popUpType: (Warning, WithIcon), - heading: "Confirm Action ? ", - description: `You are about to ${isConnectorDisabled - ? "Enable" - : "Disable"->String.toLowerCase} this connector. This might impact your desired routing configurations. Please confirm to proceed.`->React.string, - handleConfirm: { - text: "Confirm", - onClick: _ => disableConnector(isConnectorDisabled)->ignore, - }, - handleCancel: {text: "Cancel"}, - }) - } - - let connectorStatusAvailableToSwitch = isConnectorDisabled ? "Enable" : "Disable" - - let updateConnectorAuthType = async values => { - try { - setScreenState(_ => PageLoaderWrapper.Loading) - let res = await updateConnectorAccountDetails( - values, - connectorInfo.merchant_connector_id, - connectorInfo.connector_name, - isUpdateFlow, - true, - "inactive", - ) - setInitialValues(_ => res) - setScreenState(_ => Success) - } catch { - | Js.Exn.Error(_e) => () - } - } - - let handleNewPayPalAccount = async () => { - try { - await deleteTrackingDetails( - connectorInfo.merchant_connector_id, - connectorInfo.connector_name, - ) - await updateConnectorAuthType(connectorInfoDict->Js.Json.object_) - } catch { - | _ => () - } - } - - - {popoverProps => <> - {buttonProps => } - - {panelProps => { -
- {<> - ConnectorUtils.mapAuthType === - #SignatureKey}> - { - handleNewPayPalAccount()->ignore - setCurrentStep(_ => ConnectorTypes.AutomaticFlow) - setSetupAccountStatus(._ => PayPalFlowTypes.Redirecting_to_paypal) - }} - /> - - { - setCurrentStep(_ => ConnectorTypes.AutomaticFlow) - setSetupAccountStatus(._ => PayPalFlowTypes.Connect_paypal_landing) - }} - /> - ConnectorUtils.mapAuthType === - #BodyKey}> - { - setCurrentStep(_ => ConnectorTypes.IntegFields) - setSetupAccountStatus(._ => PayPalFlowTypes.Manual_setup_flow) - }} - /> - - ConnectorUtils.mapAuthType === - #SignatureKey}> - { - setCurrentStep(_ => updateStepValue) - }} - /> - - { - openConfirmationPopUp() - }} - /> - } -
- }} -
- } -
- } -} - module ConnectorSummaryGrid = { open PageLoaderWrapper @react.component