From 5b6f28324f834ca012420c3f1a3bf051a83c0b4d Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Tue, 12 Nov 2024 22:10:21 +0530 Subject: [PATCH 1/3] fix: paze express checkout for multiple iframe --- src/Utilities/Utils.res | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index cf1ce327..c43e1a7a 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1435,7 +1435,7 @@ let mergeAndFlattenToTuples = (body, requiredFieldsBody) => ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict -let sendMessageToIframe = (~msg, ~componentName, ~eventSource=None, ~mountedIframeRef=None) => { +let handleIframePostMessage = (msg, componentName, sendFallbackMessage) => { let isMessageSent = ref(false) let iframes = Window.querySelectorAll("iframe") @@ -1448,18 +1448,14 @@ let sendMessageToIframe = (~msg, ~componentName, ~eventSource=None, ~mountedIfra }) if !isMessageSent.contents { - switch (eventSource, mountedIframeRef) { - | (Some(source), _) => source->Window.sendPostMessage(msg) - | (None, Some(ref)) => ref->Window.iframePostMessage(msg) - | (None, None) => () - } + sendFallbackMessage() } } let handleApplePayIframePostMessage = (msg, componentName, mountedIframeRef) => { - sendMessageToIframe(~msg, ~componentName, ~mountedIframeRef=Some(mountedIframeRef)) + handleIframePostMessage(msg, componentName, _ => mountedIframeRef->Window.iframePostMessage(msg)) } -let handlePazeIframePostMessage = (msg, componentName, eventSource) => { - sendMessageToIframe(~msg, ~componentName, ~eventSource=Some(eventSource)) +let handlePazeIframePostMessage = (msg, componentName, source) => { + handleIframePostMessage(msg, componentName, _ => source->Window.sendPostMessage(msg)) } From dd9b5e56ca1d3e0b4c23c3901e3ea66df56ed8c0 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Tue, 12 Nov 2024 23:09:41 +0530 Subject: [PATCH 2/3] fix: comments addressed --- src/Utilities/Utils.res | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index c43e1a7a..83614b01 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1435,7 +1435,7 @@ let mergeAndFlattenToTuples = (body, requiredFieldsBody) => ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict -let handleIframePostMessage = (msg, componentName, sendFallbackMessage) => { +let handleIframePostMessage = (~msg, ~componentName, ~sendFallbackMessage) => { let isMessageSent = ref(false) let iframes = Window.querySelectorAll("iframe") @@ -1452,10 +1452,12 @@ let handleIframePostMessage = (msg, componentName, sendFallbackMessage) => { } } -let handleApplePayIframePostMessage = (msg, componentName, mountedIframeRef) => { - handleIframePostMessage(msg, componentName, _ => mountedIframeRef->Window.iframePostMessage(msg)) -} +let handleApplePayIframePostMessage = (msg, componentName, mountedIframeRef) => + handleIframePostMessage(~msg, ~componentName, ~sendFallbackMessage=_ => + mountedIframeRef->Window.iframePostMessage(msg) + ) -let handlePazeIframePostMessage = (msg, componentName, source) => { - handleIframePostMessage(msg, componentName, _ => source->Window.sendPostMessage(msg)) -} +let handlePazeIframePostMessage = (msg, componentName, source) => + handleIframePostMessage(~msg, ~componentName, ~sendFallbackMessage=_ => + source->Window.sendPostMessage(msg) + ) From fa619e8b2ebfe589ee5bd68f2e7ed53db785ec75 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Wed, 13 Nov 2024 13:56:01 +0530 Subject: [PATCH 3/3] fix: comments addressed --- src/Utilities/Utils.res | 14 ++------------ src/hyper-loader/Elements.res | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index 83614b01..c5e82b2d 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1435,7 +1435,7 @@ let mergeAndFlattenToTuples = (body, requiredFieldsBody) => ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict -let handleIframePostMessage = (~msg, ~componentName, ~sendFallbackMessage) => { +let handleIframePostMessageForWallets = (msg, componentName, mountedIframeRef) => { let isMessageSent = ref(false) let iframes = Window.querySelectorAll("iframe") @@ -1448,16 +1448,6 @@ let handleIframePostMessage = (~msg, ~componentName, ~sendFallbackMessage) => { }) if !isMessageSent.contents { - sendFallbackMessage() + mountedIframeRef->Window.iframePostMessage(msg) } } - -let handleApplePayIframePostMessage = (msg, componentName, mountedIframeRef) => - handleIframePostMessage(~msg, ~componentName, ~sendFallbackMessage=_ => - mountedIframeRef->Window.iframePostMessage(msg) - ) - -let handlePazeIframePostMessage = (msg, componentName, source) => - handleIframePostMessage(~msg, ~componentName, ~sendFallbackMessage=_ => - source->Window.sendPostMessage(msg) - ) diff --git a/src/hyper-loader/Elements.res b/src/hyper-loader/Elements.res index cb0d26d1..4eda0f49 100644 --- a/src/hyper-loader/Elements.res +++ b/src/hyper-loader/Elements.res @@ -129,13 +129,15 @@ let make = ( } } - let onPazeCallback = (event: Types.event) => { - let json = event.data->Identity.anyTypeToJson - let dict = json->getDictFromJson - if dict->getBool("isPaze", false) { - let componentName = dict->getString("componentName", "payment") - let msg = [("data", json)]->Dict.fromArray - handlePazeIframePostMessage(msg, componentName, event.source) + let onPazeCallback = mountedIframeRef => { + (event: Types.event) => { + let json = event.data->Identity.anyTypeToJson + let dict = json->getDictFromJson + if dict->getBool("isPaze", false) { + let componentName = dict->getString("componentName", "payment") + let msg = [("data", json)]->Dict.fromArray + handleIframePostMessageForWallets(msg, componentName, mountedIframeRef) + } } } @@ -148,7 +150,7 @@ let make = ( isTaxCalculationEnabled.contents = dict->getDictFromDict("response")->getBool("is_tax_calculation_enabled", false) addSmartEventListener("message", onPlaidCallback(mountedIframeRef), "onPlaidCallback") - addSmartEventListener("message", onPazeCallback, "onPazeCallback") + addSmartEventListener("message", onPazeCallback(mountedIframeRef), "onPazeCallback") let json = dict->getJsonFromDict("response", JSON.Encode.null) let isApplePayPresent = PaymentMethodsRecord.getPaymentMethodTypeFromList( @@ -401,7 +403,7 @@ let make = ( try { let msg = [("applePayCanMakePayments", true->JSON.Encode.bool)]->Dict.fromArray - handleApplePayIframePostMessage(msg, componentName, mountedIframeRef) + handleIframePostMessageForWallets(msg, componentName, mountedIframeRef) } catch { | exn => { let exnString = exn->anyTypeToJson->JSON.stringify @@ -895,13 +897,13 @@ let make = ( ("applePayShippingContact", shippingContact), ]->Dict.fromArray - handleApplePayIframePostMessage(msg, componentName, mountedIframeRef) + handleIframePostMessageForWallets(msg, componentName, mountedIframeRef) } if dict->Dict.get("showApplePayButton")->Option.isSome { let msg = [("showApplePayButton", true->JSON.Encode.bool)]->Dict.fromArray - handleApplePayIframePostMessage(msg, componentName, mountedIframeRef) + handleIframePostMessageForWallets(msg, componentName, mountedIframeRef) } }