From 037a331ba878fb021bb2d4280b96de7e859cb6f4 Mon Sep 17 00:00:00 2001 From: Riddhi Agrawal Date: Wed, 20 Dec 2023 16:32:45 +0530 Subject: [PATCH] fix: bugfixes for paypal flow --- .../ConnectPayPalFlow/ConnectPayPal.res | 28 +++++++++++++++---- .../ConnectPayPalFlow/PayPalFlowUtils.res | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/ConnectPayPal.res b/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/ConnectPayPal.res index 2b8750a9b..f31d07050 100644 --- a/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/ConnectPayPal.res +++ b/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/ConnectPayPal.res @@ -27,9 +27,21 @@ let preRequisiteList = [ module PayPalCreateNewAccountModal = { @react.component - let make = (~butttonDisplayText, ~actionUrl) => { + let make = (~butttonDisplayText, ~actionUrl, ~setScreenState) => { + let initializePayPalWindow = () => { + try { + Window.payPalCreateAccountWindow() + } catch { + | Js.Exn.Error(e) => + switch Js.Exn.message(e) { + | Some(message) => setScreenState(_ => PageLoaderWrapper.Error(message)) + | None => setScreenState(_ => PageLoaderWrapper.Error("Failed to load paypal window!")) + } + } + } + React.useEffect0(() => { - Window.payPalCreateAccountWindow() + initializePayPalWindow() None }) @@ -173,7 +185,9 @@ module RedirectionToPayPalFlow = { ->React.array}
- +

getStatus()->ignore}> @@ -187,7 +201,7 @@ module RedirectionToPayPalFlow = { module ErrorPage = { @react.component - let make = (~setupAccountStatus, ~actionUrl, ~getStatus) => { + let make = (~setupAccountStatus, ~actionUrl, ~getStatus, ~setScreenState) => { let errorPageDetails = setupAccountStatus->PayPalFlowUtils.getPageDetailsForAutomatic

@@ -207,6 +221,7 @@ module ErrorPage = { Belt.Option.getWithDefault("")} actionUrl + setScreenState /> Belt.Option.isSome}> @@ -318,7 +333,7 @@ let make = ( let connectorId = res->LogicUtils.getDictFromJsonObject->LogicUtils.getString("merchant_connector_id", "") if !isUpdateFlow { - RescriptReactRouter.push(`/connectors/new?name=payPal&connectorId=${connectorId}`) + RescriptReactRouter.push(`/connectors/new?name=paypal&connectorId=${connectorId}`) } setConnectorId(_ => connectorId) setScreenState(_ => Success) @@ -383,6 +398,7 @@ let make = ( if isRedirectedFromPaypalModal { getStatus()->ignore } + RescriptReactRouter.replace("/connectors/new?name=paypal") setSetupAccountStatus(._ => Account_not_found) None }) @@ -468,7 +484,7 @@ let make = ( | Ppcp_custom_denied | More_permissions_needed | Email_not_verified => - + | _ => React.null }}
diff --git a/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/PayPalFlowUtils.res b/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/PayPalFlowUtils.res index 2018b7a0c..f84564cb5 100644 --- a/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/PayPalFlowUtils.res +++ b/src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/PayPalFlowUtils.res @@ -152,7 +152,7 @@ let generateConnectorPayloadPayPal = ( let initialValues = [ ("profile_id", profileId->Js.Json.string), - ("connector_name", connector->Js.String2.toLowerCase->Js.Json.string), + ("connector_name", connector->Js.Json.string), ("connector_type", "payment_processor"->Js.Json.string), ("disabled", true->Js.Json.boolean), ("test_mode", true->Js.Json.boolean),