Skip to content

Commit

Permalink
Refactor: HS-1256: refactored the code to accept BE url (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
prafulkoppalkar authored Nov 4, 2023
1 parent 27b27ca commit b084b4e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -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")
<PreMountLoader publishableKey sessionId clientSecret />
let endpoint =
CardUtils.getQueryParamsDictforKey(url.search, "endpoint")->Js.Global.decodeURIComponent
<PreMountLoader publishableKey sessionId clientSecret endpoint />
}
| "achBankTransfer"
| "bacsBankTransfer"
Expand Down
6 changes: 4 additions & 2 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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") {
Expand Down
8 changes: 4 additions & 4 deletions src/Payments/PreMountLoader.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@react.component
let make = (~sessionId, ~publishableKey, ~clientSecret) => {
let make = (~sessionId, ~publishableKey, ~clientSecret, ~endpoint) => {
open Utils
let logger = OrcaLogger.make(
~sessionId,
Expand All @@ -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,
(),
),
)
Expand Down
1 change: 0 additions & 1 deletion src/Utilities/RecoilAtoms.res
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down
7 changes: 4 additions & 3 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -76,7 +76,7 @@ let make = (
<iframe
id ="orca-payment-element-iframeRef-${localSelectorString}"
name="orca-payment-element-iframeRef-${localSelectorString}"
src="${ApiEndpoint.sdkDomainUrl}/index.html?fullscreenType=${componentType}&publishableKey=${publishableKey}&clientSecret=${clientSecret}&sessionId=${sdkSessionId}"
src="${ApiEndpoint.sdkDomainUrl}/index.html?fullscreenType=${componentType}&publishableKey=${publishableKey}&clientSecret=${clientSecret}&sessionId=${sdkSessionId}&endpoint=${endpoint}"
allow="*"
name="orca-payment"
></iframe>
Expand Down Expand Up @@ -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),
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b084b4e

Please sign in to comment.