Skip to content

Commit

Permalink
fix(elements): added Compatibility for multiple iframes with Premount…
Browse files Browse the repository at this point in the history
… loader
  • Loading branch information
ArushKapoorJuspay committed Apr 18, 2024
1 parent 344a314 commit d567f2d
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let make = (
)
})

let fetchPaymentsList = mountedIframeRef => {
let fetchPaymentsList = (mountedIframeRef, componentType) => {
let handlePaymentMethodsLoaded = (event: Types.event) => {
let json = event.data->Identity.anyTypeToJson
let dict = json->getDictFromJson
Expand Down Expand Up @@ -157,10 +157,14 @@ let make = (
}
}
let msg = [("sendPaymentMethodsResponse", true->JSON.Encode.bool)]->Dict.fromArray
addSmartEventListener("message", handlePaymentMethodsLoaded, "onPaymentMethodsLoaded")
addSmartEventListener(
"message",
handlePaymentMethodsLoaded,
`onPaymentMethodsLoaded-${componentType}`,
)
preMountLoaderIframeDiv->Window.iframePostMessage(msg)
}
let fetchCustomerPaymentMethods = (mountedIframeRef, disableSaveCards) => {
let fetchCustomerPaymentMethods = (mountedIframeRef, disableSaveCards, componentType) => {
if !disableSaveCards {
let handleCustomerPaymentMethodsLoaded = (event: Types.event) => {
let json = event.data->Identity.anyTypeToJson
Expand All @@ -176,7 +180,7 @@ let make = (
addSmartEventListener(
"message",
handleCustomerPaymentMethodsLoaded,
"onCustomerPaymentMethodsLoaded",
`onCustomerPaymentMethodsLoaded-${componentType}`,
)
}
let msg =
Expand Down Expand Up @@ -805,6 +809,14 @@ let make = (
} catch {
| _ => Console.log("Error loading Gpay")
}
} else if wallets.googlePay === Never {
logger.setLogInfo(
~value="GooglePay is set as never by merchant",
~eventName=GOOGLE_PAY_FLOW,
~paymentMethod="GOOGLE_PAY",
~logType=INFO,
(),
)
}

json->resolve
Expand All @@ -815,29 +827,25 @@ let make = (
json->resolve
})
->ignore
} else if wallets.googlePay === Never {
logger.setLogInfo(
~value="GooglePay is set as never by merchant",
~eventName=GOOGLE_PAY_FLOW,
~paymentMethod="GOOGLE_PAY",
~logType=INFO,
(),
)
}
}
let msg = [("sendSessionTokensResponse", true->JSON.Encode.bool)]->Dict.fromArray
addSmartEventListener("message", handleSessionTokensLoaded, "onSessionTokensLoaded")
addSmartEventListener(
"message",
handleSessionTokensLoaded,
`onSessionTokensLoaded-${componentType}`,
)
preMountLoaderIframeDiv->Window.iframePostMessage(msg)
}
preMountLoaderMountedPromise
->then(_ => {
fetchPaymentsList(mountedIframeRef)
fetchPaymentsList(mountedIframeRef, componentType)
if (
newOptions
->getDictFromJson
->getBool("displaySavedPaymentMethods", true)
) {
fetchCustomerPaymentMethods(mountedIframeRef, false)
fetchCustomerPaymentMethods(mountedIframeRef, false, componentType)
}
fetchSessionTokens(mountedIframeRef)
mountedIframeRef->Window.iframePostMessage(message)
Expand Down

0 comments on commit d567f2d

Please sign in to comment.