From b084b4e15ff775749fcbab6860500d43d1b916fe Mon Sep 17 00:00:00 2001 From: Praful Koppalkar <126236898+prafulkoppalkar@users.noreply.github.com> Date: Sat, 4 Nov 2023 23:56:28 +0530 Subject: [PATCH] Refactor: HS-1256: refactored the code to accept BE url (#5) --- src/App.res | 4 +++- src/LoaderController.res | 6 ++++-- src/Payments/PreMountLoader.res | 8 ++++---- src/Utilities/RecoilAtoms.res | 1 - src/orca-loader/Elements.res | 7 ++++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/App.res b/src/App.res index eec7af27a..77bf24807 100644 --- a/src/App.res +++ b/src/App.res @@ -22,7 +22,9 @@ let make = () => { let clientSecret = CardUtils.getQueryParamsDictforKey(url.search, "clientSecret") let sessionId = CardUtils.getQueryParamsDictforKey(url.search, "sessionId") let publishableKey = CardUtils.getQueryParamsDictforKey(url.search, "publishableKey") - + let endpoint = + CardUtils.getQueryParamsDictforKey(url.search, "endpoint")->Js.Global.decodeURIComponent + } | "achBankTransfer" | "bacsBankTransfer" diff --git a/src/LoaderController.res b/src/LoaderController.res index dc83b9fcc..013ad025c 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -4,7 +4,6 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => { open RecoilAtoms //<...>// let (configAtom, setConfig) = Recoil.useRecoilState(configAtom) - let setApiEndpoint = Recoil.useSetRecoilState(endPoint) let (keys, setKeys) = Recoil.useRecoilState(keys) let (paymentlist, setList) = Recoil.useRecoilState(list) let (_, setSessions) = Recoil.useRecoilState(sessions) @@ -169,7 +168,10 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => { if dict->getDictIsSome("publishableKey") { let publishableKey = dict->getString("publishableKey", "") logger.setMerchantId(publishableKey) - setApiEndpoint(._ => ApiEndpoint.getApiEndPoint(~publishableKey, ())) + } + if dict->getDictIsSome("endpoint") { + let endpoint = dict->getString("endpoint", "") + ApiEndpoint.setApiEndPoint(endpoint) } if dict->getDictIsSome("paymentOptions") { diff --git a/src/Payments/PreMountLoader.res b/src/Payments/PreMountLoader.res index c93ee7d9c..de4c0328a 100644 --- a/src/Payments/PreMountLoader.res +++ b/src/Payments/PreMountLoader.res @@ -1,5 +1,5 @@ @react.component -let make = (~sessionId, ~publishableKey, ~clientSecret) => { +let make = (~sessionId, ~publishableKey, ~clientSecret, ~endpoint) => { open Utils let logger = OrcaLogger.make( ~sessionId, @@ -20,21 +20,21 @@ let make = (~sessionId, ~publishableKey, ~clientSecret) => { ~publishableKey, ~logger, ~switchToCustomPod=false, - ~endpoint=ApiEndpoint.getApiEndPoint(~publishableKey, ()), + ~endpoint, ), PaymentHelpers.useCustomerDetails( ~clientSecret, ~publishableKey, ~optLogger=Some(logger), ~switchToCustomPod=false, - ~endpoint=ApiEndpoint.getApiEndPoint(~publishableKey, ()), + ~endpoint, ), PaymentHelpers.useSessions( ~clientSecret, ~publishableKey, ~optLogger=Some(logger), ~switchToCustomPod=false, - ~endpoint=ApiEndpoint.getApiEndPoint(~publishableKey, ()), + ~endpoint, (), ), ) diff --git a/src/Utilities/RecoilAtoms.res b/src/Utilities/RecoilAtoms.res index 1e7936c91..f112f325b 100644 --- a/src/Utilities/RecoilAtoms.res +++ b/src/Utilities/RecoilAtoms.res @@ -45,7 +45,6 @@ let userAddressPincode = Recoil.atom(. "userAddressPincode", defaultFieldValues) let userAddressState = Recoil.atom(. "userAddressState", defaultFieldValues) let userAddressCountry = Recoil.atom(. "userAddressCountry", defaultFieldValues) let userBlikCode = Recoil.atom(. "userBlikCode", defaultFieldValues) -let endPoint = Recoil.atom(. "endpoint", GlobalVars.backendEndPoint) let fieldsComplete = Recoil.atom(. "fieldsComplete", false) let isManualRetryEnabled = Recoil.atom(. "isManualRetryEnabled", false) let userCurrency = Recoil.atom(. "userCurrency", "") diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 9ecfb37d1..596074a69 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -57,7 +57,7 @@ let make = ( ->Belt.Option.flatMap(Js.Json.decodeBoolean) ->Belt.Option.getWithDefault(false) : false - let endpoint = ApiEndpoint.getApiEndPoint(~publishableKey, ()) + let endpoint = ApiEndpoint.getApiEndPoint(~publishableKey, ())->Js.Global.encodeURIComponent let localSelectorString = "hyper-preMountLoader-iframe" let mountPreMountLoaderIframe = () => { @@ -76,7 +76,7 @@ let make = ( @@ -274,6 +274,7 @@ let make = ( ] ->Js.Dict.fromArray ->Js.Json.object_ + let endpoint = ApiEndpoint.getApiEndPoint(~publishableKey, ()) let message = [ ("paymentElementCreate", (componentType == "payment")->Js.Json.boolean), @@ -287,6 +288,7 @@ let make = ( ("sdkHandleConfirmPayment", sdkHandleConfirmPayment->Js.Json.boolean), ("AOrcaBBlockPConfirm", blockConfirm->Js.Json.boolean), ("switchToCustomPodABP", switchToCustomPod->Js.Json.boolean), + ("endpoint", endpoint->Js.Json.string), ("parentURL", "*"->Js.Json.string), ]->Js.Dict.fromArray @@ -441,7 +443,6 @@ let make = ( ->then(res => { let (json, applePayPresent, googlePayPresent) = res if componentType === "payment" && applePayPresent->Belt.Option.isSome { - let processPayment = (token: Js.Json.t) => { let msg = [("applePayProcessPayment", token)]->Js.Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg)