Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changed post message from parent window to current window #598

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"

ArushKapoorJuspay marked this conversation as resolved.
Show resolved Hide resolved
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
Loading