From faaf49e923cc1dcb167dd5cf62ffe444415e7c14 Mon Sep 17 00:00:00 2001 From: Shiva Nandan Date: Tue, 20 Aug 2024 12:27:29 +0530 Subject: [PATCH 1/2] chore: rename handlePostMessage to messageParentWindow --- rescript.json | 2 +- src/Components/AddBankAccount.res | 2 +- src/Components/FullScreenDivDriver.res | 2 +- src/Components/InputField.res | 2 +- src/Components/Modal.res | 4 ++-- src/Components/PayNowButton.res | 2 +- src/Components/PaymentLoader.res | 2 +- src/Components/SavedPaymentManagement.res | 6 +++--- src/LoaderController.res | 8 ++++---- src/PaymentElement.res | 4 ++-- src/Payments/AddBankDetails.res | 2 +- src/Payments/BankTransfersPopup.res | 7 +++++-- src/Payments/GPay.res | 2 +- src/Payments/KlarnaSDK.res | 4 ++-- src/Payments/PaypalSDK.res | 2 +- src/Payments/PaypalSDKHelpers.res | 4 ++-- src/Payments/PlaidSDKIframe.res | 8 ++++---- src/Payments/PreMountLoader.res | 8 ++++---- src/Payments/QRCodeDisplay.res | 2 +- src/Payments/VoucherDisplay.res | 2 +- src/SingleLineCardPayment.res | 2 +- src/ThreeDSAuth.res | 4 ++-- src/ThreeDSMethod.res | 6 +++--- src/Utilities/ApplePayHelpers.res | 4 ++-- src/Utilities/GooglePayHelpers.res | 6 +++--- src/Utilities/PaymentHelpers.res | 22 +++++++++++----------- src/Utilities/Utils.res | 18 +++++++++--------- src/orca-loader/Elements.res | 12 ++++++------ src/orca-log-catcher/ErrorBoundary.res | 2 +- 29 files changed, 77 insertions(+), 74 deletions(-) diff --git a/rescript.json b/rescript.json index 0fc408fe2..294471c26 100644 --- a/rescript.json +++ b/rescript.json @@ -14,7 +14,7 @@ "namespace": true, "ppx-flags": [], "package-specs": { - "module": "es6", + "module": "esmodule", "in-source": true }, "bs-dependencies": [ diff --git a/src/Components/AddBankAccount.res b/src/Components/AddBankAccount.res index b87462ac0..b89e379a2 100644 --- a/src/Components/AddBankAccount.res +++ b/src/Components/AddBankAccount.res @@ -36,7 +36,7 @@ let make = (~modalData, ~setModalData) => { let toolTipRef = React.useRef(Nullable.null) let openModal = () => { - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("iframeId", iframeId->JSON.Encode.string), ]) diff --git a/src/Components/FullScreenDivDriver.res b/src/Components/FullScreenDivDriver.res index 57e8c8f22..5b64ada39 100644 --- a/src/Components/FullScreenDivDriver.res +++ b/src/Components/FullScreenDivDriver.res @@ -1,7 +1,7 @@ @react.component let make = () => { React.useEffect0(() => { - Utils.handlePostMessage([("driverMounted", true->JSON.Encode.bool)]) + Utils.messageParentWindow([("driverMounted", true->JSON.Encode.bool)]) None })
diff --git a/src/Components/InputField.res b/src/Components/InputField.res index fc3859e98..590a86a3b 100644 --- a/src/Components/InputField.res +++ b/src/Components/InputField.res @@ -109,7 +109,7 @@ let make = ( let concatString = Array.joinWith([cardEmpty, cardComplete, cardInvalid, cardFocused], "") React.useEffect(() => { - Utils.handlePostMessage([ + Utils.messageParentWindow([ ("id", iframeId->JSON.Encode.string), ("concatedString", concatString->JSON.Encode.string), ]) diff --git a/src/Components/Modal.res b/src/Components/Modal.res index 7cc38c4ae..d9ed44c8e 100644 --- a/src/Components/Modal.res +++ b/src/Components/Modal.res @@ -1,7 +1,7 @@ let close = setOpenModal => { setOpenModal(_ => false) setTimeout(() => { - Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + Utils.messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) }, 450)->ignore } @@ -21,7 +21,7 @@ let make = ( switch closeCallback { | Some(fn) => fn() | None => setTimeout(() => { - Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + Utils.messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) }, 450)->ignore } } diff --git a/src/Components/PayNowButton.res b/src/Components/PayNowButton.res index eb2207f50..b2f6edd0b 100644 --- a/src/Components/PayNowButton.res +++ b/src/Components/PayNowButton.res @@ -39,7 +39,7 @@ let make = () => { setIsPayNowButtonDisable(_ => true) setShowLoader(_ => true) EventListenerManager.addSmartEventListener("message", handleMessage, "onSubmitSuccessful") - handlePostMessage([("handleSdkConfirm", confirmPayload)]) + messageParentWindow([("handleSdkConfirm", confirmPayload)]) }
diff --git a/src/Components/PaymentLoader.res b/src/Components/PaymentLoader.res index c8cb5fc55..b8340766d 100644 --- a/src/Components/PaymentLoader.res +++ b/src/Components/PaymentLoader.res @@ -4,7 +4,7 @@ let make = () => { let (branding, setBranding) = React.useState(_ => "auto") React.useEffect0(() => { - handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) + messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { let json = ev.data->safeParse let dict = json->getDictFromJson diff --git a/src/Components/SavedPaymentManagement.res b/src/Components/SavedPaymentManagement.res index 6b68a4f7b..05fc9f16b 100644 --- a/src/Components/SavedPaymentManagement.res +++ b/src/Components/SavedPaymentManagement.res @@ -18,7 +18,7 @@ let make = (~savedMethods: array, ~setSavedMethods) } let handleDelete = (paymentItem: PaymentType.customerMethods) => { - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), @@ -44,7 +44,7 @@ let make = (~savedMethods: array, ~setSavedMethods) } else { logger.setLogError(~value=res->JSON.stringify, ~eventName=DELETE_SAVED_PAYMENT_METHOD) } - handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) resolve() }) ->catch(err => { @@ -53,7 +53,7 @@ let make = (~savedMethods: array, ~setSavedMethods) ~value=`Error Deleting Saved Payment Method: ${exceptionMessage}`, ~eventName=DELETE_SAVED_PAYMENT_METHOD, ) - handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) resolve() }) ->ignore diff --git a/src/LoaderController.res b/src/LoaderController.res index 1ab00aaf1..af25ede5c 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -24,7 +24,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime let {config} = configAtom let {iframeId} = keys - let handlePostMessage = data => handlePostMessage(data, ~targetOrigin=keys.parentURL) + let messageParentWindow = data => messageParentWindow(data, ~targetOrigin=keys.parentURL) let setUserFullName = Recoil.useLoggedSetRecoilState(userFullName, "fullName", logger) let setUserEmail = Recoil.useLoggedSetRecoilState(userEmailAddress, "email", logger) @@ -141,8 +141,8 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime } React.useEffect0(() => { - handlePostMessage([("iframeMounted", true->JSON.Encode.bool)]) - handlePostMessage([("applePayMounted", true->JSON.Encode.bool)]) + messageParentWindow([("iframeMounted", true->JSON.Encode.bool)]) + messageParentWindow([("applePayMounted", true->JSON.Encode.bool)]) logger.setLogInitiated() let updatedState: PaymentType.loadType = switch paymentMethodList { | Loading => @@ -553,7 +553,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime React.useEffect(() => { let iframeHeight = divH->Float.equal(0.0) ? divH : divH +. 1.0 - handlePostMessage([ + messageParentWindow([ ("iframeHeight", iframeHeight->JSON.Encode.float), ("iframeId", iframeId->JSON.Encode.string), ]) diff --git a/src/PaymentElement.res b/src/PaymentElement.res index fe3509fed..afa3e8b4a 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -369,7 +369,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod let evalMethodsList = () => switch paymentMethodList { | SemiLoaded | LoadError(_) | Loaded(_) => - handlePostMessage([("ready", true->JSON.Encode.bool)]) + messageParentWindow([("ready", true->JSON.Encode.bool)]) | _ => () } if !displaySavedPaymentMethods { @@ -379,7 +379,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod | LoadingSavedCards => () | LoadedSavedCards(list, _) => list->Array.length > 0 - ? handlePostMessage([("ready", true->JSON.Encode.bool)]) + ? messageParentWindow([("ready", true->JSON.Encode.bool)]) : evalMethodsList() | NoResult(_) => evalMethodsList() } diff --git a/src/Payments/AddBankDetails.res b/src/Payments/AddBankDetails.res index ec6c02070..eb92be75f 100644 --- a/src/Payments/AddBankDetails.res +++ b/src/Payments/AddBankDetails.res @@ -45,7 +45,7 @@ let make = (~paymentMethodType) => { ~optLogger=Some(logger), ) ->then(_ => { - handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) setShowFields(_ => false) JSON.Encode.null->resolve }) diff --git a/src/Payments/BankTransfersPopup.res b/src/Payments/BankTransfersPopup.res index 23561daec..9f8cd9c55 100644 --- a/src/Payments/BankTransfersPopup.res +++ b/src/Payments/BankTransfersPopup.res @@ -44,11 +44,14 @@ let make = (~transferType) => { keys ->Array.map(item => `${item->snakeToTitleCase} : ${getKeyValue(json, item)}`) ->Array.joinWith(`\n`) - handlePostMessage([("copy", true->JSON.Encode.bool), ("copyDetails", text->JSON.Encode.string)]) + messageParentWindow([ + ("copy", true->JSON.Encode.bool), + ("copyDetails", text->JSON.Encode.string), + ]) setIsCopied(_ => true) } React.useEffect0(() => { - handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) + messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { let json = ev.data->safeParse let dict = json->Utils.getDictFromJson diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 18d307bee..92e008ec9 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -108,7 +108,7 @@ let make = ( if result { if isInvokeSDKFlow { if isDelayedSessionToken { - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), diff --git a/src/Payments/KlarnaSDK.res b/src/Payments/KlarnaSDK.res index db2466c64..b5b80397d 100644 --- a/src/Payments/KlarnaSDK.res +++ b/src/Payments/KlarnaSDK.res @@ -30,7 +30,7 @@ let make = (~sessionObj: SessionsType.token) => { } let handleCloseLoader = () => { - Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + Utils.messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) } let paymentMethodTypes = DynamicFieldsUtils.usePaymentMethodTypeFromList( @@ -69,7 +69,7 @@ let make = (~sessionObj: SessionsType.token) => { result => { let result = result->JSON.Decode.bool->Option.getOr(false) if result { - Utils.handlePostMessage([ + Utils.messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), diff --git a/src/Payments/PaypalSDK.res b/src/Payments/PaypalSDK.res index 2ddc0cbba..7763a6fd7 100644 --- a/src/Payments/PaypalSDK.res +++ b/src/Payments/PaypalSDK.res @@ -42,7 +42,7 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) = | _ => 48 }, } - let handleCloseLoader = () => Utils.handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + let handleCloseLoader = () => Utils.messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) let isGuestCustomer = UtilityHooks.useIsGuestCustomer() let paymentMethodTypes = DynamicFieldsUtils.usePaymentMethodTypeFromList( diff --git a/src/Payments/PaypalSDKHelpers.res b/src/Payments/PaypalSDKHelpers.res index 7d0edf51c..7738c4236 100644 --- a/src/Payments/PaypalSDKHelpers.res +++ b/src/Payments/PaypalSDKHelpers.res @@ -37,7 +37,7 @@ let loadPaypalSDK = ( style: buttonStyle, fundingSource: paypal["FUNDING"]["PAYPAL"], createOrder: () => { - Utils.handlePostMessage([ + Utils.messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), @@ -169,7 +169,7 @@ let loadBraintreePaypalSdk = ( fundingSource: paypal["FUNDING"]["PAYPAL"], createBillingAgreement: () => { //Paypal Clicked - Utils.handlePostMessage([ + Utils.messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), diff --git a/src/Payments/PlaidSDKIframe.res b/src/Payments/PlaidSDKIframe.res index 43a66bf4c..4e2d68cc4 100644 --- a/src/Payments/PlaidSDKIframe.res +++ b/src/Payments/PlaidSDKIframe.res @@ -31,7 +31,7 @@ let make = () => { } } Window.addEventListener("message", handle) - handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) + messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)]) Some(() => {Window.removeEventListener("message", handle)}) }) @@ -80,7 +80,7 @@ let make = () => { ~message="Payment is processing. Try again later!", ) } - handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) resolve(json) }) ->then(_ => { @@ -101,7 +101,7 @@ let make = () => { logger.setLogInfo(~value="Plaid SDK Loaded", ~eventName=PLAID_SDK) }, onSuccess: (publicToken, _) => { - handlePostMessage([ + messageParentWindow([ ("isPlaid", true->JSON.Encode.bool), ("publicToken", publicToken->JSON.Encode.string), ]) @@ -113,7 +113,7 @@ let make = () => { if isForceSync { callbackOnSuccessOfPlaidPaymentsFlow() } else { - handlePostMessage([ + messageParentWindow([ ("fullscreen", false->JSON.Encode.bool), ("isPlaid", true->JSON.Encode.bool), ("isExited", true->JSON.Encode.bool), diff --git a/src/Payments/PreMountLoader.res b/src/Payments/PreMountLoader.res index 81c8ceda7..4e3abf9a7 100644 --- a/src/Payments/PreMountLoader.res +++ b/src/Payments/PreMountLoader.res @@ -91,7 +91,7 @@ let make = ( open Promise promise ->then(res => { - handlePostMessage([("response", res), ("data", key->JSON.Encode.string)]) + messageParentWindow([("response", res), ("data", key->JSON.Encode.string)]) switch key { | "payment_methods" => setPaymentMethodsResponseSent(_ => true) | "session_tokens" => setSessionTokensResponseSent(_ => true) @@ -102,7 +102,7 @@ let make = ( resolve() }) ->catch(_err => { - handlePostMessage([("response", JSON.Encode.null), ("data", key->JSON.Encode.string)]) + messageParentWindow([("response", JSON.Encode.null), ("data", key->JSON.Encode.string)]) resolve() }) ->ignore @@ -124,7 +124,7 @@ let make = ( React.useEffect0(() => { Window.addEventListener("message", handle) - handlePostMessage([("preMountLoaderIframeMountedCallback", true->JSON.Encode.bool)]) + messageParentWindow([("preMountLoaderIframeMountedCallback", true->JSON.Encode.bool)]) Some( () => { Window.removeEventListener("message", handle) @@ -134,7 +134,7 @@ let make = ( React.useEffect4(() => { let handleUnmount = () => { - handlePostMessage([("preMountLoaderIframeUnMount", true->JSON.Encode.bool)]) + messageParentWindow([("preMountLoaderIframeUnMount", true->JSON.Encode.bool)]) Window.removeEventListener("message", handle) } diff --git a/src/Payments/QRCodeDisplay.res b/src/Payments/QRCodeDisplay.res index 212c826a1..c73727eff 100644 --- a/src/Payments/QRCodeDisplay.res +++ b/src/Payments/QRCodeDisplay.res @@ -19,7 +19,7 @@ let make = () => { let switchToCustomPod = Recoil.useRecoilValueFromAtom(RecoilAtoms.switchToCustomPod) React.useEffect0(() => { - handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) + messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { let json = ev.data->safeParse let dict = json->Utils.getDictFromJson diff --git a/src/Payments/VoucherDisplay.res b/src/Payments/VoucherDisplay.res index a50e917e0..43419eeee 100644 --- a/src/Payments/VoucherDisplay.res +++ b/src/Payments/VoucherDisplay.res @@ -21,7 +21,7 @@ let make = () => { }, [loader]) React.useEffect0(() => { - handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) + messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { let json = ev.data->safeParse let dict = json->Utils.getDictFromJson diff --git a/src/SingleLineCardPayment.res b/src/SingleLineCardPayment.res index f2821dc02..5a118442c 100644 --- a/src/SingleLineCardPayment.res +++ b/src/SingleLineCardPayment.res @@ -106,7 +106,7 @@ let make = ( let concatString = Array.joinWith([cardEmpty, cardComplete, cardInvalid, cardFocused], "") React.useEffect(() => { - Utils.handlePostMessage([ + Utils.messageParentWindow([ ("id", iframeId->JSON.Encode.string), ("concatedString", concatString->JSON.Encode.string), ]) diff --git a/src/ThreeDSAuth.res b/src/ThreeDSAuth.res index 91262087c..e836219b0 100644 --- a/src/ThreeDSAuth.res +++ b/src/ThreeDSAuth.res @@ -22,7 +22,7 @@ let make = () => { } React.useEffect0(() => { - handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) + messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { let json = ev.data->safeParse let dict = json->getDictFromJson @@ -64,7 +64,7 @@ let make = () => { let dict = json->getDictFromJson if dict->Dict.get("error")->Option.isSome { let errorObj = PaymentError.itemToObjMapper(dict) - handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) postFailedSubmitResponse( ~errortype=errorObj.error.type_, ~message=errorObj.error.message, diff --git a/src/ThreeDSMethod.res b/src/ThreeDSMethod.res index 9a46ffb08..1d4e9de4e 100644 --- a/src/ThreeDSMethod.res +++ b/src/ThreeDSMethod.res @@ -19,7 +19,7 @@ let make = () => { ~value="Y", ~paymentMethod="CARD", ) - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", `3dsAuth`->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), @@ -54,7 +54,7 @@ let make = () => { } React.useEffect0(() => { - handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)]) + messageParentWindow([("iframeMountedCallback", true->JSON.Encode.bool)]) let handle = (ev: Window.event) => { let json = ev.data->safeParse let dict = json->Utils.getDictFromJson @@ -97,7 +97,7 @@ let make = () => { ~logType=ERROR, ) metadata->Utils.getDictFromJson->Dict.set("3dsMethodComp", "N"->JSON.Encode.string) - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", `3dsAuth`->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), diff --git a/src/Utilities/ApplePayHelpers.res b/src/Utilities/ApplePayHelpers.res index 830951c46..d23f0ae2c 100644 --- a/src/Utilities/ApplePayHelpers.res +++ b/src/Utilities/ApplePayHelpers.res @@ -217,7 +217,7 @@ let useHandleApplePayResponse = ( Window.addEventListener("message", handleApplePayMessages) Some( () => { - handlePostMessage([("applePaySessionAbort", true->JSON.Encode.bool)]) + messageParentWindow([("applePaySessionAbort", true->JSON.Encode.bool)]) Window.removeEventListener("message", handleApplePayMessages) }, ) @@ -237,7 +237,7 @@ let handleApplePayButtonClicked = (~sessionObj, ~componentName) => { ("applePayButtonClicked", true->JSON.Encode.bool), ("applePayPaymentRequest", paymentRequest), ] - handlePostMessage(message) + messageParentWindow(message) } let useSubmitCallback = (~isWallet, ~sessionObj, ~componentName) => { diff --git a/src/Utilities/GooglePayHelpers.res b/src/Utilities/GooglePayHelpers.res index dd11e5b91..04b9c9ef6 100644 --- a/src/Utilities/GooglePayHelpers.res +++ b/src/Utilities/GooglePayHelpers.res @@ -140,7 +140,7 @@ let useHandleGooglePayResponse = ( ) } if dict->Dict.get("gpayError")->Option.isSome { - handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) if isSavedMethodsFlow || !isWallet { postFailedSubmitResponse(~errortype="server_error", ~message="Something went wrong") } @@ -153,13 +153,13 @@ let useHandleGooglePayResponse = ( let handleGooglePayClicked = (~sessionObj, ~componentName, ~iframeId, ~readOnly) => { let paymentDataRequest = GooglePayType.getPaymentDataFromSession(~sessionObj, ~componentName) - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), ]) if !readOnly { - handlePostMessage([ + messageParentWindow([ ("GpayClicked", true->JSON.Encode.bool), ("GpayPaymentDataRequest", paymentDataRequest->Identity.anyTypeToJson), ]) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 253f1a17b..34532a849 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -21,7 +21,7 @@ let getPaymentType = paymentMethodType => | _ => Other } -let closePaymentLoaderIfAny = () => handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) +let closePaymentLoaderIfAny = () => messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) type paymentIntent = ( ~handleUserError: bool=?, @@ -267,7 +267,7 @@ let rec pollStatus = ( if status === "completed" { resolve(json) } else if count === 0 { - handlePostMessage([("fullscreen", false->JSON.Encode.bool)]) + messageParentWindow([("fullscreen", false->JSON.Encode.bool)]) openUrl(returnUrl) } else { delay(interval) @@ -368,7 +368,7 @@ let rec intentCall = ( let url = urlSearch(confirmParam.return_url) url.searchParams.set("payment_intent_client_secret", clientSecret) url.searchParams.set("status", "failed") - handlePostMessage([("confirmParams", confirmParam->Identity.anyTypeToJson)]) + messageParentWindow([("confirmParams", confirmParam->Identity.anyTypeToJson)]) if statusCode->String.charAt(0) !== "2" { res @@ -557,7 +557,7 @@ let rec intentCall = ( ~paymentMethod, ) if !isPaymentSession { - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", `${intent.payment_method_type}BankTransfer`->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), @@ -592,7 +592,7 @@ let rec intentCall = ( ~paymentMethod, ) if !isPaymentSession { - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", `qrData`->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), @@ -639,7 +639,7 @@ let rec intentCall = ( ) if do3dsMethodCall { - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", `3ds`->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), @@ -647,7 +647,7 @@ let rec intentCall = ( ]) } else { metaData->Dict.set("3dsMethodComp", "U"->JSON.Encode.string) - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", `3dsAuth`->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), @@ -681,7 +681,7 @@ let rec intentCall = ( ~eventName=DISPLAY_VOUCHER, ~paymentMethod, ) - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", `voucherData`->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), @@ -724,7 +724,7 @@ let rec intentCall = ( } if !isPaymentSession { - handlePostMessage(message) + messageParentWindow(message) } resolve(data) } else if intent.nextAction.type_ === "invoke_sdk_client" { @@ -778,7 +778,7 @@ let rec intentCall = ( } if !isPaymentSession { - handlePostMessage(message) + messageParentWindow(message) } } else { handleProcessingStatus(paymentType, sdkHandleOneClickConfirmPayment) @@ -1713,7 +1713,7 @@ let callAuthLink = ( ("isForceSync", false->JSON.Encode.bool), ]->getJsonFromArrayOfJson - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "plaidSDK"->JSON.Encode.string), ("iframeId", iframeId->JSON.Encode.string), diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index cf45cae07..deb9d3fa6 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -17,27 +17,27 @@ type dateTimeFormat = {resolvedOptions: unit => options} @send external postMessage: (parent, JSON.t, string) => unit = "postMessage" open ErrorUtils -let handlePostMessage = (~targetOrigin="*", messageArr) => { +let messageParentWindow = (~targetOrigin="*", messageArr) => { iframeParent->postMessage(messageArr->Dict.fromArray->JSON.Encode.object, targetOrigin) } let handleOnFocusPostMessage = (~targetOrigin="*") => { - handlePostMessage([("focus", true->JSON.Encode.bool)], ~targetOrigin) + messageParentWindow([("focus", true->JSON.Encode.bool)], ~targetOrigin) } let handleOnBlurPostMessage = (~targetOrigin="*") => { - handlePostMessage([("blur", true->JSON.Encode.bool)], ~targetOrigin) + messageParentWindow([("blur", true->JSON.Encode.bool)], ~targetOrigin) } let handleOnClickPostMessage = (~targetOrigin="*", ev) => { - handlePostMessage( + messageParentWindow( [("clickTriggered", true->JSON.Encode.bool), ("event", ev->JSON.stringify->JSON.Encode.string)], ~targetOrigin, ) } let handleOnConfirmPostMessage = (~targetOrigin="*", ~isOneClick=false) => { let message = isOneClick ? "oneClickConfirmTriggered" : "confirmTriggered" - handlePostMessage([(message, true->JSON.Encode.bool)], ~targetOrigin) + messageParentWindow([(message, true->JSON.Encode.bool)], ~targetOrigin) } let getOptionString = (dict, key) => { dict->Dict.get(key)->Option.flatMap(JSON.Decode.string) @@ -281,13 +281,13 @@ let postFailedSubmitResponse = (~errortype, ~message) => { ("type", errortype->JSON.Encode.string), ("message", message->JSON.Encode.string), ]->Dict.fromArray - handlePostMessage([ + messageParentWindow([ ("submitSuccessful", false->JSON.Encode.bool), ("error", errorDict->JSON.Encode.object), ]) } let postSubmitResponse = (~jsonData, ~url) => { - handlePostMessage([ + messageParentWindow([ ("submitSuccessful", true->JSON.Encode.bool), ("data", jsonData), ("url", url->JSON.Encode.string), @@ -593,7 +593,7 @@ let generateStyleSheet = (classname, dict, id) => { } } let openUrl = url => { - handlePostMessage([("openurl", url->JSON.Encode.string)]) + messageParentWindow([("openurl", url->JSON.Encode.string)]) } let getArrofJsonString = (arr: array) => { @@ -678,7 +678,7 @@ let handlePostMessageEvents = ( "Payment Data Filled" ++ (savedMethod ? ": Saved Payment Method" : ": New Payment Method") loggerState.setLogInfo(~value, ~eventName=PAYMENT_DATA_FILLED, ~paymentMethod=paymentType) } - handlePostMessage([ + messageParentWindow([ ("elementType", "payment"->JSON.Encode.string), ("complete", complete->JSON.Encode.bool), ("empty", empty->JSON.Encode.bool), diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 32679f401..1537c2370 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -613,7 +613,7 @@ let make = ( } switch eventDataObject->getOptionalJsonFromJson("poll_status") { | Some(val) => { - handlePostMessage([ + messageParentWindow([ ("fullscreen", true->JSON.Encode.bool), ("param", "paymentloader"->JSON.Encode.string), ("iframeId", selectorString->JSON.Encode.string), @@ -651,7 +651,7 @@ let make = ( ) resolve(JSON.Encode.null) } else { - handlePostMessage([ + messageParentWindow([ ("fullscreen", false->JSON.Encode.bool), ("submitSuccessful", true->JSON.Encode.bool), ("data", json), @@ -663,7 +663,7 @@ let make = ( if redirect.contents === "always" { Window.Location.replace(url) } - handlePostMessage([ + messageParentWindow([ ("submitSuccessful", false->JSON.Encode.bool), ("error", err->Identity.anyTypeToJson), ]) @@ -692,17 +692,17 @@ let make = ( ~isForceSync=true, ) ->then(json => { - handlePostMessage([("submitSuccessful", true->JSON.Encode.bool), ("data", json)]) + messageParentWindow([("submitSuccessful", true->JSON.Encode.bool), ("data", json)]) resolve(json) }) ->catch(err => { - handlePostMessage([ + messageParentWindow([ ("submitSuccessful", false->JSON.Encode.bool), ("error", err->Identity.anyTypeToJson), ]) resolve(err->Identity.anyTypeToJson) }) - ->finally(_ => handlePostMessage([("fullscreen", false->JSON.Encode.bool)])) + ->finally(_ => messageParentWindow([("fullscreen", false->JSON.Encode.bool)])) }->ignore | None => () diff --git a/src/orca-log-catcher/ErrorBoundary.res b/src/orca-log-catcher/ErrorBoundary.res index aee7de189..b05080046 100644 --- a/src/orca-log-catcher/ErrorBoundary.res +++ b/src/orca-log-catcher/ErrorBoundary.res @@ -184,7 +184,7 @@ module ErrorCard = { React.useEffect(() => { switch level { | Top => - Utils.handlePostMessage([ + Utils.messageParentWindow([ ("iframeHeight", (divH +. 1.0)->JSON.Encode.float), ("iframeId", iframeId->JSON.Encode.string), ]) From 7d24049910fd2a68c160821f66003d6b96f12d86 Mon Sep 17 00:00:00 2001 From: Shiva Nandan Date: Tue, 20 Aug 2024 12:49:03 +0530 Subject: [PATCH 2/2] chore: use promise instead of Promise.t --- src/Components/AddressPaymentInput.res | 2 +- src/Payments/KlarnaSDKTypes.res | 2 +- src/Types/GooglePayType.res | 4 ++-- src/Types/PaypalSDKTypes.res | 4 ++-- src/Types/PostalCodeType.res | 2 +- src/Types/ThemeImporter.res | 2 +- src/Utilities/PaymentHelpers.res | 2 +- src/libraries/Promise.res | 2 +- src/orca-loader/Elements.res | 4 ++-- src/orca-loader/LoaderPaymentElement.res | 2 +- src/orca-loader/Types.res | 24 ++++++++++++------------ 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Components/AddressPaymentInput.res b/src/Components/AddressPaymentInput.res index 6588dda36..df5dff24f 100644 --- a/src/Components/AddressPaymentInput.res +++ b/src/Components/AddressPaymentInput.res @@ -7,7 +7,7 @@ type addressType = Line1 | Line2 | City | Postal | State | Country type dataModule = {states: JSON.t} @val -external importStates: string => Promise.t = "import" +external importStates: string => promise = "import" let getShowType = str => { switch str { diff --git a/src/Payments/KlarnaSDKTypes.res b/src/Payments/KlarnaSDKTypes.res index f8db1adf7..2f5e1c906 100644 --- a/src/Payments/KlarnaSDKTypes.res +++ b/src/Payments/KlarnaSDKTypes.res @@ -37,7 +37,7 @@ type loadType = { payment_method_category?: string, theme?: string, shape?: string, - on_click?: authorize => Promise.t, + on_click?: authorize => promise, } type some = { init: token => unit, diff --git a/src/Types/GooglePayType.res b/src/Types/GooglePayType.res index f018a61e0..a2d99aaf6 100644 --- a/src/Types/GooglePayType.res +++ b/src/Types/GooglePayType.res @@ -26,9 +26,9 @@ type document @val external document: document = "document" @send external getElementById: (document, string) => element = "getElementById" type client = { - isReadyToPay: JSON.t => Promise.t, + isReadyToPay: JSON.t => promise, createButton: JSON.t => Dom.element, - loadPaymentData: JSON.t => Promise.t, + loadPaymentData: JSON.t => promise, } @new external google: JSON.t => client = "google.payments.api.PaymentsClient" let getLabel = (var: PaymentType.googlePayStyleType) => { diff --git a/src/Types/PaypalSDKTypes.res b/src/Types/PaypalSDKTypes.res index c525de989..854cfae44 100644 --- a/src/Types/PaypalSDKTypes.res +++ b/src/Types/PaypalSDKTypes.res @@ -2,7 +2,7 @@ type clientErr = bool type clientInstance type paypalCheckoutErr = {message: string} type data -type order = {get: unit => RescriptCore.Promise.t} +type order = {get: unit => promise} type actions = {order: order} type err type vault = {vault: bool} @@ -75,7 +75,7 @@ type buttons = { style: style, fundingSource: string, createBillingAgreement?: unit => unit, - createOrder?: unit => RescriptCore.Promise.t, + createOrder?: unit => promise, onApprove: (data, actions) => unit, onCancel: data => unit, onError?: err => unit, diff --git a/src/Types/PostalCodeType.res b/src/Types/PostalCodeType.res index 90ab3d25d..10884e9b0 100644 --- a/src/Types/PostalCodeType.res +++ b/src/Types/PostalCodeType.res @@ -12,4 +12,4 @@ let defaultPostalCode = { type themeDataModule = {default: array} @val -external importPostalCode: string => Promise.t = "import" +external importPostalCode: string => promise = "import" diff --git a/src/Types/ThemeImporter.res b/src/Types/ThemeImporter.res index f9f1becc4..a9d9503c4 100644 --- a/src/Types/ThemeImporter.res +++ b/src/Types/ThemeImporter.res @@ -4,4 +4,4 @@ type themeDataModule = { } @val -external importTheme: string => Promise.t = "import" +external importTheme: string => promise = "import" diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 34532a849..36e85ad34 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -313,7 +313,7 @@ let rec intentCall = ( ~bodyStr: string=?, ~headers: Dict.t=?, ~method: Fetch.method, - ) => Promise.t, + ) => promise, ~uri, ~headers, ~bodyStr, diff --git a/src/libraries/Promise.res b/src/libraries/Promise.res index 8b7707576..bb99f6f05 100644 --- a/src/libraries/Promise.res +++ b/src/libraries/Promise.res @@ -1,4 +1,4 @@ -type t<+'a> = Promise.t<'a> +type t<+'a> = promise<'a> exception JsError(Exn.t) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 1537c2370..9723d7d8e 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -6,8 +6,8 @@ open EventListenerManager open ApplePayTypes type trustPayFunctions = { - finishApplePaymentV2: (string, paymentRequestData) => Promise.t, - executeGooglePayment: (string, GooglePayType.paymentDataRequest) => Promise.t, + finishApplePaymentV2: (string, paymentRequestData) => promise, + executeGooglePayment: (string, GooglePayType.paymentDataRequest) => promise, } @new external trustPayApi: JSON.t => trustPayFunctions = "TrustPayApi" diff --git a/src/orca-loader/LoaderPaymentElement.res b/src/orca-loader/LoaderPaymentElement.res index 7c6bdf2bc..94f7a1c33 100644 --- a/src/orca-loader/LoaderPaymentElement.res +++ b/src/orca-loader/LoaderPaymentElement.res @@ -4,7 +4,7 @@ open EventListenerManager open Identity @val @scope(("navigator", "clipboard")) -external writeText: string => Promise.t<'a> = "writeText" +external writeText: string => promise<'a> = "writeText" let make = ( componentType, diff --git a/src/orca-loader/Types.res b/src/orca-loader/Types.res index 3617051c0..5186769da 100644 --- a/src/orca-loader/Types.res +++ b/src/orca-loader/Types.res @@ -13,7 +13,7 @@ type eventData = { type event = {key: string, data: eventData, source: Dom.element} type eventParam = Event(event) | EventData(eventData) | Empty type eventHandler = option => unit -@send external onload: (Dom.element, unit => Promise.t<'a>) => Promise.t<'a> = "onload" +@send external onload: (Dom.element, unit => promise<'a>) => promise<'a> = "onload" module This = { type t @get @@ -35,25 +35,25 @@ type paymentElement = { type element = { getElement: string => option, update: JSON.t => unit, - fetchUpdates: unit => Promise.t, + fetchUpdates: unit => promise, create: (string, JSON.t) => paymentElement, } type getCustomerSavedPaymentMethods = { getCustomerDefaultSavedPaymentMethodData: unit => JSON.t, getCustomerLastUsedPaymentMethodData: unit => JSON.t, - confirmWithCustomerDefaultPaymentMethod: JSON.t => Promise.t, - confirmWithLastUsedPaymentMethod: JSON.t => Promise.t, + confirmWithCustomerDefaultPaymentMethod: JSON.t => promise, + confirmWithLastUsedPaymentMethod: JSON.t => promise, } type getPaymentManagementMethods = { - getSavedPaymentManagementMethodsList: unit => Promise.t, - deleteSavedPaymentMethod: JSON.t => Promise.t, + getSavedPaymentManagementMethodsList: unit => promise, + deleteSavedPaymentMethod: JSON.t => promise, } type initPaymentSession = { - getCustomerSavedPaymentMethods: unit => Promise.t, - getPaymentManagementMethods: unit => Promise.t, + getCustomerSavedPaymentMethods: unit => promise, + getPaymentManagementMethods: unit => promise, } type confirmParams = {return_url: string} @@ -64,11 +64,11 @@ type confirmPaymentParams = { } type hyperInstance = { - confirmOneClickPayment: (JSON.t, bool) => Promise.t, - confirmPayment: JSON.t => Promise.t, + confirmOneClickPayment: (JSON.t, bool) => promise, + confirmPayment: JSON.t => promise, elements: JSON.t => element, - confirmCardPayment: (string, option, option) => Promise.t, - retrievePaymentIntent: string => Promise.t, + confirmCardPayment: (string, option, option) => promise, + retrievePaymentIntent: string => promise, widgets: JSON.t => element, paymentRequest: JSON.t => JSON.t, initPaymentSession: JSON.t => initPaymentSession,