Skip to content

Commit

Permalink
fix: changed post message from parent window to current window
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay committed Sep 4, 2024
1 parent 65dc747 commit d6f6c5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Hyperswitch-React-Demo-App/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const paymentData = {
authentication_type: "three_ds",
customer_id: "hyperswitch_sdk_demo_id",
email: "[email protected]",
request_external_three_ds_authentication: false,
description: "Hello this is description",
shipping: {
address: {
Expand Down Expand Up @@ -97,7 +98,7 @@ const paymentData = {
}

const profileId = process.env.PROFILE_ID;
if(profileId) {
if (profileId) {
paymentData.profile_id = profileId;
}

Expand Down
13 changes: 8 additions & 5 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@val external document: 'a = "document"
type window
type parent
@val external window: window = "window"
@val @scope("window") external iframeParent: parent = "parent"
@val external window: Dom.element = "window"
@val @scope("window") external iframeParent: Dom.element = "parent"
type event = {data: string}
external dictToObj: Dict.t<'a> => {..} = "%identity"

Expand All @@ -15,12 +13,17 @@ type dateTimeFormat = {resolvedOptions: unit => options}

@send external remove: Dom.element => unit = "remove"

@send external postMessage: (parent, JSON.t, string) => unit = "postMessage"
@send external postMessage: (Dom.element, JSON.t, string) => unit = "postMessage"

open ErrorUtils
let messageParentWindow = (~targetOrigin="*", messageArr) => {
iframeParent->postMessage(messageArr->Dict.fromArray->JSON.Encode.object, targetOrigin)
}

let messageCurrentWindow = (~targetOrigin="*", messageArr) => {
window->postMessage(messageArr->Dict.fromArray->JSON.Encode.object, targetOrigin)
}

let handleOnFocusPostMessage = (~targetOrigin="*") => {
messageParentWindow([("focus", true->JSON.Encode.bool)], ~targetOrigin)
}
Expand Down
14 changes: 7 additions & 7 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
])
Expand All @@ -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),
Expand All @@ -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 => ()
Expand Down

0 comments on commit d6f6c5f

Please sign in to comment.