diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index deb9d3fa6..90489189a 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -16,11 +16,17 @@ type dateTimeFormat = {resolvedOptions: unit => options} @send external remove: Dom.element => unit = "remove" @send external postMessage: (parent, JSON.t, string) => unit = "postMessage" +@val @scope("window") external windowPostMessage: (JSON.t, string) => unit = "postMessage" + open ErrorUtils let messageParentWindow = (~targetOrigin="*", messageArr) => { iframeParent->postMessage(messageArr->Dict.fromArray->JSON.Encode.object, targetOrigin) } +let messageCurrentWindow = (~targetOrigin="*", messageArr) => { + windowPostMessage(messageArr->Dict.fromArray->JSON.Encode.object, targetOrigin) +} + let handleOnFocusPostMessage = (~targetOrigin="*") => { messageParentWindow([("focus", true->JSON.Encode.bool)], ~targetOrigin) } diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 96bb201cd..691372db5 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -612,7 +612,7 @@ let make = ( } switch eventDataObject->getOptionalJsonFromJson("poll_status") { | Some(val) => { - messageParentWindow([ + messageCurrentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", selectorString->JSON.Encode.string), @@ -650,7 +650,7 @@ let make = ( ) resolve(JSON.Encode.null) } else { - messageParentWindow([ + messageCurrentWindow([ ("fullscreen", false->JSON.Encode.bool), ("submitSuccessful", true->JSON.Encode.bool), ("data", json), @@ -662,7 +662,7 @@ let make = ( if redirect.contents === "always" { Window.Location.replace(url) } - messageParentWindow([ + messageCurrentWindow([ ("submitSuccessful", false->JSON.Encode.bool), ("error", err->Identity.anyTypeToJson), ]) @@ -679,7 +679,7 @@ let make = ( switch eventDataObject->getOptionalJsonFromJson("openurl_if_required") { | Some(val) => - messageParentWindow([ + messageCurrentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", selectorString->JSON.Encode.string), @@ -696,17 +696,17 @@ let make = ( ~isForceSync=true, ) ->then(json => { - messageParentWindow([("submitSuccessful", true->JSON.Encode.bool), ("data", json)]) + messageCurrentWindow([("submitSuccessful", true->JSON.Encode.bool), ("data", json)]) resolve(json) }) ->catch(err => { - messageParentWindow([ + messageCurrentWindow([ ("submitSuccessful", false->JSON.Encode.bool), ("error", err->Identity.anyTypeToJson), ]) resolve(err->Identity.anyTypeToJson) }) - ->finally(_ => messageParentWindow([("fullscreen", false->JSON.Encode.bool)])) + ->finally(_ => messageCurrentWindow([("fullscreen", false->JSON.Encode.bool)])) }->ignore | None => ()