diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 4bf63d8d4..2e11ab1a6 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -508,11 +508,32 @@ let make = ( } ) + let handleApplePayMounted = (event: Types.event) => { + let json = event.data->eventToJson + let dict = json->getDictFromJson + + if dict->Js.Dict.get("applePayMounted")->Belt.Option.isSome { + switch sessionForApplePay->Js.Nullable.toOption { + | Some(session) => + if session.canMakePayments(.) { + let msg = + [("applePayCanMakePayments", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + } else { + Utils.logInfo(Js.log("CANNOT MAKE PAYMENT USING APPLE PAY")) + } + + | None => () + } + } + } + addSmartEventListener( "message", handleApplePayMessages.contents, "onApplePayMessages", ) + addSmartEventListener("message", handleApplePayMounted, "onApplePayMount") } if componentType === "payment" && googlePayPresent->Belt.Option.isSome { let dict = json->getDictFromJson @@ -634,26 +655,6 @@ let make = ( ->ignore } - let handleApplePayMounted = (event: Types.event) => { - let json = event.data->eventToJson - let dict = json->getDictFromJson - - if dict->Js.Dict.get("applePayMounted")->Belt.Option.isSome { - switch sessionForApplePay->Js.Nullable.toOption { - | Some(session) => - if session.canMakePayments(.) { - let msg = - [("applePayCanMakePayments", true->Js.Json.boolean)]->Js.Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - } else { - Utils.logInfo(Js.log("CANNOT MAKE PAYMENT USING APPLE PAY")) - } - - | None => () - } - } - } - let handleGooglePayThirdPartyFlow = (event: Types.event) => { let json = event.data->eventToJson let dict = json->getDictFromJson @@ -734,9 +735,7 @@ let make = ( | _ => () } } - addSmartEventListener("message", handleApplePayMounted, "onApplePayMount") addSmartEventListener("message", handleGooglePayThirdPartyFlow, "onGooglePayThirdParty") - Window.removeEventListener("message", handleApplePayMessages.contents) } let msg = [("sendSessionTokensResponse", true->Js.Json.boolean)]->Js.Dict.fromArray addSmartEventListener("message", handleSessionTokensLoaded, "onSessionTokensLoaded")