From 1242ce93cc990b8a76f4b520213a0cabbccd40f6 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar Date: Wed, 20 Sep 2023 15:06:32 +0530 Subject: [PATCH 1/9] fix: intent being called even on the session close --- src/Payments/GPay.res | 32 +++----------------------------- src/orca-loader/Elements.res | 2 +- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 0ee319eb4..4239442aa 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -102,6 +102,9 @@ let default = (props: props) => { let body = PaymentBody.gpayBody(~payObj=obj, ~connectors) processPayment(body) } + if dict->Js.Dict.get("gpayError")->Belt.Option.isSome { + Utils.handlePostMessage([("fullscreen", false->Js.Json.boolean)]) + } } Window.addEventListener("message", handle) Some(() => {Window.removeEventListener("message", handle)}) @@ -181,10 +184,7 @@ let default = (props: props) => { ("param", "paymentloader"->Js.Json.string), ("iframeId", iframeId->Js.Json.string), ]) - - // open Promise let paymentDataRequest = getGooglePaymentDataRequest() - // let paymentsClient = getGooglePaymentsClient() loggerState.setLogInfo( ~eventName=GOOGLE_PAY_FLOW, ~logType=DEBUG, @@ -198,32 +198,6 @@ let default = (props: props) => { ("GpayClicked", true->Js.Json.boolean), ("gpayPaymentRequestData", paymentDataRequest->toJson), ]) - // paymentsClient.loadPaymentData(. paymentDataRequest) - // ->then(data => { - // loggerState.setLogInfo( - // ~logType=DEBUG, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~value=data->resToJson->Js.Json.stringify, - // (), - // ) - // let obj = data->resToJson->getDictFromJson->itemToObjMapper - // let body = PaymentBody.gpayBody(~payObj=obj, ~connectors) - // processPayment(body) - // resolve() - // }) - // ->catch(err => { - // loggerState.setLogError( - // ~logType=DEBUG, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~value=err->toJson->Js.Json.stringify, - // (), - // ) - // handlePostMessage([("fullscreen", false->Js.Json.boolean)]) - // resolve() - // }) - // ->ignore } } else { loggerState.setLogInfo( diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index e7f1d9a39..1d15afbcd 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -376,7 +376,7 @@ let make = ( ~logType=DEBUG, (), ) - let msg = [("gpayResponse", err->toJson)]->Js.Dict.fromArray + let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) resolve() }) From c67c0241a11070834cbda9034b7a1d32add2d167 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar Date: Sun, 24 Sep 2023 15:37:35 +0530 Subject: [PATCH 2/9] WIP --- src/Payments/GPay.res | 361 +++++----- src/Utilities/Utils.res | 6 + src/orca-loader/Elements.res | 283 ++++++-- src/orca-loader/LoaderPaymentElement.res | 6 +- src/orca-loader/newfile.txt | 827 +++++++++++++++++++++++ webpack.common.js | 15 +- 6 files changed, 1259 insertions(+), 239 deletions(-) create mode 100644 src/orca-loader/newfile.txt diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 4239442aa..a93ccec37 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -1,10 +1,5 @@ open Utils open RecoilAtoms -let arrayJsonToCamelCase = arr => { - arr->Js.Array2.map(item => { - item->transformKeys(CamelCase) - }) -} type props = { sessionObj: option, @@ -14,20 +9,20 @@ type props = { open GooglePayType -external toJson: 'a => Js.Json.t = "%identity" +// external toJson: 'a => Js.Json.t = "%identity" let default = (props: props) => { let (loggerState, _setLoggerState) = Recoil.useRecoilState(loggerAtom) - let {iframeId} = Recoil.useRecoilValueFromAtom(keys) + // let {iframeId} = Recoil.useRecoilValueFromAtom(keys) let {publishableKey} = Recoil.useRecoilValueFromAtom(keys) let options = Recoil.useRecoilValueFromAtom(optionAtom) let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Gpay) let sync = PaymentHelpers.usePaymentSync(Some(loggerState), Gpay) - let status = CommonHooks.useScript("https://pay.google.com/gp/p/js/pay.js") - let baseRequest = { - apiVersion: 2, - apiVersionMinor: 0, - } + // let status = CommonHooks.useScript("https://pay.google.com/gp/p/js/pay.js") + // let baseRequest = { + // apiVersion: 2, + // apiVersionMinor: 0, + // } let isGooglePaySDKFlow = React.useMemo1(() => { props.sessionObj->Belt.Option.isSome }, [props.sessionObj]) @@ -35,19 +30,19 @@ let default = (props: props) => { props.thirdPartySessionObj->Belt.Option.isSome }, [props.sessionObj]) - let googlePaySessionObj = React.useMemo1(() => { - switch props.sessionObj { - | Some(val) => val - | None => { - walletName: NONE, - token: "", - sessionId: "", - allowed_payment_methods: [], - transaction_info: Js.Json.null, - merchant_info: Js.Json.null, - } - } - }, [props.sessionObj]) + // let googlePaySessionObj = React.useMemo1(() => { + // switch props.sessionObj { + // | Some(val) => val + // | None => { + // walletName: NONE, + // token: "", + // sessionId: "", + // allowed_payment_methods: [], + // transaction_info: Js.Json.null, + // merchant_info: Js.Json.null, + // } + // } + // }, [props.sessionObj]) let googlePayPaymentMethodType = switch PaymentMethodsRecord.getPaymentMethodTypeFromList( ~list=props.list, @@ -71,15 +66,15 @@ let default = (props: props) => { ? props.list->PaymentUtils.getConnectors(Wallets(Gpay(SDK))) : props.list->PaymentUtils.getConnectors(Wallets(Gpay(Redirect))) - let getGoogleIsReadyToPayRequest = () => { - assign( - Js.Dict.empty()->Js.Json.object_, - baseRequest->toJson, - { - "allowedPaymentMethods": googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase, - }->toJson, - ) - } + // let getGoogleIsReadyToPayRequest = () => { + // assign( + // Js.Dict.empty()->Js.Json.object_, + // baseRequest->toJson, + // { + // "allowedPaymentMethods": googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase, + // }->toJson, + // ) + // } let processPayment = (body: array<(string, Js.Json.t)>) => { intent( ~bodyArr=body, @@ -110,27 +105,27 @@ let default = (props: props) => { Some(() => {Window.removeEventListener("message", handle)}) }) - let (_, buttonType, _) = options.wallets.style.type_ - let (_, heightType, _) = options.wallets.style.height - let height = switch heightType { - | GooglePay(val) => val - | _ => 48 - } - let getGooglePaymentDataRequest = () => { - let paymentDataRequest = assign2(Js.Dict.empty()->Js.Json.object_, baseRequest->toJson) + // let (_, buttonType, _) = options.wallets.style.type_ + // let (_, heightType, _) = options.wallets.style.height + // let height = switch heightType { + // | GooglePay(val) => val + // | _ => 48 + // } + // let getGooglePaymentDataRequest = () => { + // let paymentDataRequest = assign2(Js.Dict.empty()->Js.Json.object_, baseRequest->toJson) - paymentDataRequest.allowedPaymentMethods = - googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase + // paymentDataRequest.allowedPaymentMethods = + // googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase - paymentDataRequest.transactionInfo = - googlePaySessionObj.transaction_info->transformKeys(CamelCase) - paymentDataRequest.merchantInfo = googlePaySessionObj.merchant_info->transformKeys(CamelCase) - paymentDataRequest - } + // paymentDataRequest.transactionInfo = + // googlePaySessionObj.transaction_info->transformKeys(CamelCase) + // paymentDataRequest.merchantInfo = googlePaySessionObj.merchant_info->transformKeys(CamelCase) + // paymentDataRequest + // } - let getGooglePaymentsClient = () => { - google({"environment": GlobalVars.isProd ? "PRODUCTION" : "TEST"}->toJson) - } + // let getGooglePaymentsClient = () => { + // google({"environment": GlobalVars.isProd ? "PRODUCTION" : "TEST"}->toJson) + // } let syncPayment = () => { sync( @@ -142,125 +137,147 @@ let default = (props: props) => { (), ) } + // let paymentDataRequest = getGooglePaymentDataRequest() - let onGooglePaymentButtonClicked = () => { - loggerState.setLogInfo( - ~value="GooglePay Button Clicked", - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - (), - ) - if isInvokeSDKFlow { - let isDelayedSessionToken = - props.thirdPartySessionObj - ->Belt.Option.getWithDefault(Js.Json.null) - ->Js.Json.decodeObject - ->Belt.Option.getWithDefault(Js.Dict.empty()) - ->Js.Dict.get("delayed_session_token") - ->Belt.Option.getWithDefault(Js.Json.null) - ->Js.Json.decodeBoolean - ->Belt.Option.getWithDefault(false) + // let onGooglePaymentButtonClicked = () => { + // loggerState.setLogInfo( + // ~value="GooglePay Button Clicked", + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // (), + // ) + // if isInvokeSDKFlow { + // let isDelayedSessionToken = + // props.thirdPartySessionObj + // ->Belt.Option.getWithDefault(Js.Json.null) + // ->Js.Json.decodeObject + // ->Belt.Option.getWithDefault(Js.Dict.empty()) + // ->Js.Dict.get("delayed_session_token") + // ->Belt.Option.getWithDefault(Js.Json.null) + // ->Js.Json.decodeBoolean + // ->Belt.Option.getWithDefault(false) - if isDelayedSessionToken { - loggerState.setLogInfo( - ~logType=DEBUG, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~value="isDelayedSessionToken", - (), - ) - let bodyDict = PaymentBody.gPayThirdPartySdkBody(~connectors) - loggerState.setLogInfo( - ~logType=DEBUG, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~value=bodyDict->toJson->Js.Json.stringify, - (), - ) - processPayment(bodyDict) - } else { - handlePostMessage([ - ("fullscreen", true->Js.Json.boolean), - ("param", "paymentloader"->Js.Json.string), - ("iframeId", iframeId->Js.Json.string), - ]) - let paymentDataRequest = getGooglePaymentDataRequest() - loggerState.setLogInfo( - ~eventName=GOOGLE_PAY_FLOW, - ~logType=DEBUG, - ~paymentMethod="GOOGLE_PAY", - ~value=paymentDataRequest->toJson->Js.Json.stringify, - (), - ) - options.readOnly - ? () - : handlePostMessage([ - ("GpayClicked", true->Js.Json.boolean), - ("gpayPaymentRequestData", paymentDataRequest->toJson), - ]) - } - } else { - loggerState.setLogInfo( - ~logType=DEBUG, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~value="not isInvokeSDKFlow", - (), - ) - let bodyDict = PaymentBody.gpayRedirectBody(~connectors) - processPayment(bodyDict) - } - } - let buttonStyle = { - let obj = { - "onClick": onGooglePaymentButtonClicked, - "buttonType": switch buttonType { - | GooglePay(var) => var->getLabel - | _ => Default->getLabel - }, - "buttonSizeMode": "fill", - "buttonColor": options.wallets.style.theme == Dark ? "black" : "white", - } - obj->toJson - } - let addGooglePayButton = () => { - let paymentClient = getGooglePaymentsClient() + // if isDelayedSessionToken { + // loggerState.setLogInfo( + // ~logType=DEBUG, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~value="isDelayedSessionToken", + // (), + // ) + // let bodyDict = PaymentBody.gPayThirdPartySdkBody(~connectors) + // loggerState.setLogInfo( + // ~logType=DEBUG, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~value=bodyDict->toJson->Js.Json.stringify, + // (), + // ) + // processPayment(bodyDict) + // } else { + // handlePostMessage([ + // ("fullscreen", true->Js.Json.boolean), + // ("param", "paymentloader"->Js.Json.string), + // ("iframeId", iframeId->Js.Json.string), + // ]) + // loggerState.setLogInfo( + // ~eventName=GOOGLE_PAY_FLOW, + // ~logType=DEBUG, + // ~paymentMethod="GOOGLE_PAY", + // ~value=paymentDataRequest->toJson->Js.Json.stringify, + // (), + // ) + // options.readOnly + // ? () + // : { + // handlePostMessage([ + // ("GpayClicked", true->Js.Json.boolean), + // ("gpayPaymentRequestData", paymentDataRequest->toJson), + // ]) + // } - let button = paymentClient.createButton(. buttonStyle) - let gpayWrapper = getElementById(Utils.document, "google-pay-button") - gpayWrapper.innerHTML = "" - gpayWrapper.appendChild(. button) - } + // // open Promise + // // let gPayClient = GooglePayType.google( + // // { + // // "environment": publishableKey->Js.String2.startsWith("pk_prd_") + // // ? "PRODUCTION" + // // : "TEST", + // // }->toJson, + // // ) + // // gPayClient.loadPaymentData(. paymentDataRequest->toJson) + // // ->then(json => { + // // resolve() + // // }) + // // ->catch(err => { + // // handlePostMessage([("fullscreen", false->Js.Json.boolean)]) + // // resolve() + // // }) + // // ->ignore + // // } + // } + // } else { + // loggerState.setLogInfo( + // ~logType=DEBUG, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~value="not isInvokeSDKFlow", + // (), + // ) + // let bodyDict = PaymentBody.gpayRedirectBody(~connectors) + // processPayment(bodyDict) + // } + // } - let onGooglePayLoaded = () => { - open Promise - let paymentsClient = getGooglePaymentsClient() + // let buttonStyle = { + // let obj = { + // "onClick": onGooglePaymentButtonClicked, + // "buttonType": switch buttonType { + // | GooglePay(var) => var->getLabel + // | _ => Default->getLabel + // }, + // "buttonSizeMode": "fill", + // "buttonColor": options.wallets.style.theme == Dark ? "black" : "white", + // } + // obj->toJson + // } + // let addGooglePayButton = () => { + // let paymentClient = getGooglePaymentsClient() - if paymentExperience == PaymentMethodsRecord.RedirectToURL || isGooglePayThirdPartyFlow { - addGooglePayButton() - } else if isInvokeSDKFlow { - paymentsClient.isReadyToPay(. getGoogleIsReadyToPayRequest()) - ->then(_ => { - addGooglePayButton() - resolve() - }) - ->catch(_err => { - resolve() - }) - ->ignore - } - } + // let button = paymentClient.createButton(. buttonStyle) + // let gpayWrapper = getElementById(Utils.document, "google-pay-button") + // gpayWrapper.innerHTML = "" + // gpayWrapper.appendChild(. button) + // } - React.useEffect2(() => { - if status == "ready" { - try { - onGooglePayLoaded() - } catch { - | _err => Utils.logInfo(Js.log("Error loading Gpay")) - } - } - None - }, (status, props)) + // let onGooglePayLoaded = () => { + // open Promise + // let paymentsClient = getGooglePaymentsClient() + + // if paymentExperience == PaymentMethodsRecord.RedirectToURL || isGooglePayThirdPartyFlow { + // addGooglePayButton() + // } else if isInvokeSDKFlow { + // paymentsClient.isReadyToPay(. getGoogleIsReadyToPayRequest()) + // ->then(_ => { + // addGooglePayButton() + // resolve() + // }) + // ->catch(_err => { + // resolve() + // }) + // ->ignore + // } + // } + + // React.useEffect2(() => { + // if status == "ready" { + // try { + // onGooglePayLoaded() + // } catch { + // | _err => Utils.logInfo(Js.log("Error loading Gpay")) + // } + // } + // None + // }, (status, props)) React.useEffect0(() => { let handleGooglePayMessages = (ev: Window.event) => { @@ -286,9 +303,13 @@ let default = (props: props) => { ) }) -
Belt.Int.toString}px`, ())} - id="google-pay-button" - className={`w-full flex flex-row justify-center rounded-md`} - /> + //
Belt.Int.toString}px`, ())} + // id="google-pay-button" + // className={`w-full flex flex-row justify-center rounded-md`} + // /> + let handleClick = _e => { + handlePostMessage([("GpayClicked", true->Js.Json.boolean)]) + } + } diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index 58539257a..37f84a988 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -733,3 +733,9 @@ let delay = timeOut => { }, timeOut)->ignore }) } + +let arrayJsonToCamelCase = arr => { + arr->Js.Array2.map(item => { + item->transformKeys(CamelCase) + }) +} diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 1d15afbcd..8e5aac85b 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -5,6 +5,7 @@ open Utils open EventListenerManager open ApplePayTypes +@val external window: {..} = "window" external objToJson: {..} => Js.Json.t = "%identity" external eventToJson: Types.eventData => Js.Json.t = "%identity" @@ -25,6 +26,10 @@ let make = ( ~handleApplePayMessages, ~logger: option, ) => { + let handleApplePayMessages = ref(_ => ()) + let applePaySessionRef = ref(Js.Nullable.null) + let handleGooglePayMessages = ref(_ => ()) + try { let iframeRef = [] let logger = logger->Belt.Option.getWithDefault(OrcaLogger.defaultLoggerConfig) @@ -338,63 +343,63 @@ let make = ( } | _ => () } - let gpayClicked = - json->OrcaUtils.getOptionalJsonFromJson("GpayClicked")->OrcaUtils.getBoolfromjson(false) - let gpayPaymentRequestData = - json->OrcaUtils.getOptionalJsonFromJson("gpayPaymentRequestData") - if gpayClicked { - let gPayClient = GooglePayType.google( - { - "environment": publishableKey->Js.String2.startsWith("pk_prd_") - ? "PRODUCTION" - : "TEST", - }->toJson, - ) - let data = switch gpayPaymentRequestData { - | Some(json) => json - | None => Js.Dict.empty()->Js.Json.object_ - } - try { - gPayClient.loadPaymentData(. data) - ->then(json => { - logger.setLogInfo( - ~value=json->toJson->Js.Json.stringify, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, - (), - ) - let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - resolve() - }) - ->catch(err => { - logger.setLogInfo( - ~value=err->toJson->Js.Json.stringify, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, - (), - ) - let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - resolve() - }) - ->ignore - } catch { - | err => { - logger.setLogInfo( - ~value=err->toJson->Js.Json.stringify, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, - (), - ) - let msg = [("gpayErorr", err->toJson)]->Js.Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - } - } - } + // let gpayClicked = + // json->OrcaUtils.getOptionalJsonFromJson("GpayClicked")->OrcaUtils.getBoolfromjson(false) + // let gpayPaymentRequestData = + // json->OrcaUtils.getOptionalJsonFromJson("gpayPaymentRequestData") + // if gpayClicked { + // let gPayClient = GooglePayType.google( + // { + // "environment": publishableKey->Js.String2.startsWith("pk_prd_") + // ? "PRODUCTION" + // : "TEST", + // }->toJson, + // ) + // let data = switch gpayPaymentRequestData { + // | Some(json) => json + // | None => Js.Dict.empty()->Js.Json.object_ + // } + // try { + // gPayClient.loadPaymentData(. data) + // ->then(json => { + // logger.setLogInfo( + // ~value=json->toJson->Js.Json.stringify, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~logType=DEBUG, + // (), + // ) + // let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray + // mountedIframeRef->Window.iframePostMessage(msg) + // resolve() + // }) + // ->catch(err => { + // logger.setLogInfo( + // ~value=err->toJson->Js.Json.stringify, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~logType=DEBUG, + // (), + // ) + // let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray + // mountedIframeRef->Window.iframePostMessage(msg) + // resolve() + // }) + // ->ignore + // } catch { + // | err => { + // logger.setLogInfo( + // ~value=err->toJson->Js.Json.stringify, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~logType=DEBUG, + // (), + // ) + // let msg = [("gpayErorr", err->toJson)]->Js.Dict.fromArray + // mountedIframeRef->Window.iframePostMessage(msg) + // } + // } + // } } addSmartEventListener("message", handleApplePayMounted, "onApplePayMount") @@ -419,11 +424,22 @@ let make = ( ->Belt.Option.getWithDefault("") x === "apple_pay" || x === "applepay" }) + let googlePayPresent = sessionsArr->Js.Array2.find(item => { + let x = + item + ->Js.Json.decodeObject + ->Belt.Option.flatMap(x => { + x->Js.Dict.get("wallet_name") + }) + ->Belt.Option.flatMap(Js.Json.decodeString) + ->Belt.Option.getWithDefault("") + x === "google_pay" || x === "googlepay" + }) - (json, applePayPresent)->resolve + (json, applePayPresent, googlePayPresent)->resolve }) ->then(res => { - let (json, applePayPresent) = res + let (json, applePayPresent, googlePayPresent) = res if componentType === "payment" && applePayPresent->Belt.Option.isSome { //do operations here @@ -611,6 +627,154 @@ let make = ( addSmartEventListener("message", handleApplePayMessages.contents, "onApplePayMessages") } + if componentType === "payment" && googlePayPresent->Belt.Option.isSome { + let dict = json->getDictFromJson + Js.log2("ENTERING GOOGLE PAY BLOCK", json) + let sessionObj = SessionsType.itemToObjMapper(dict, Others) + let gPayToken = SessionsType.getPaymentSessionObj(sessionObj.sessionsToken, Gpay) + + let tokenObj = switch gPayToken { + | OtherTokenOptional(optToken) => optToken + | _ => Some(SessionsType.defaultToken) + } + + let gpayobj = switch tokenObj { + | Some(val) => val + | _ => SessionsType.defaultToken + } + + let baseRequest = { + "apiVersion": 2, + "apiVersionMinor": 0, + } + let paymentDataRequest = GooglePayType.assign2( + Js.Dict.empty()->Js.Json.object_, + baseRequest->toJson, + ) + let payRequest = GooglePayType.assign( + Js.Dict.empty()->Js.Json.object_, + baseRequest->toJson, + { + "allowedPaymentMethods": gpayobj.allowed_payment_methods->arrayJsonToCamelCase, + }->toJson, + ) + paymentDataRequest.allowedPaymentMethods = + gpayobj.allowed_payment_methods->arrayJsonToCamelCase + paymentDataRequest.transactionInfo = gpayobj.transaction_info->transformKeys(CamelCase) + paymentDataRequest.merchantInfo = gpayobj.merchant_info->transformKeys(CamelCase) + let gPayClient = GooglePayType.google( + { + "environment": publishableKey->Js.String2.startsWith("pk_prd_") + ? "PRODUCTION" + : "TEST", + }->toJson, + ) + + let onclick = () => { + gPayClient.loadPaymentData(. paymentDataRequest->toJson) + ->then(json => { + Js.log2("RES", json) + logger.setLogInfo( + ~value=json->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + Js.log2("RES", json) + let msg = [ + ("gpayResponse", json->toJson), + ("fullscreen", true->Js.Json.boolean), + ("param", "paymentloader"->Js.Json.string), + // ("iframeId", iframeId->Js.Json.string), + ]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->catch(err => { + Js.log2("ERROR", err) + logger.setLogInfo( + ~value=err->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + + let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->ignore + } + // let buttonStyle = { + // let obj = { + // "onClick": onclick, + // "buttonType": "Buy", + // "buttonSizeMode": "fill", + // "buttonColor": "black", + // } + // obj->toJson + // } + // try { + // gPayClient.isReadyToPay(. payRequest) + // ->then(_ => { + // let button = gPayClient.createButton(. buttonStyle) + // let gpayWrapper = GooglePayType.getElementById(Utils.document, "google-pay-button") + // gpayWrapper.innerHTML = "" + // gpayWrapper.appendChild(. button) + // resolve() + // }) + // ->catch(_err => { + // resolve() + // }) + // ->ignore + // } catch { + // | err => Js.log2("ERROR", err) + // } + + let handleGooglePayMessages = (event: Types.event) => { + Js.log("ENTERING HANDLE FUNCTION") + let evJson = event.data->eventToJson + let gpayClicked = + evJson + ->OrcaUtils.getOptionalJsonFromJson("GpayClicked") + ->OrcaUtils.getBoolfromjson(false) + try { + gPayClient.isReadyToPay(. payRequest) + ->then(_ => { + // let button = gPayClient.createButton(. buttonStyle) + // let gpayWrapper = GooglePayType.getElementById( + // Utils.document, + // "google-pay-button", + // ) + // gpayWrapper.innerHTML = "" + // gpayWrapper.appendChild(. button) + Js.log("READY") + resolve() + }) + ->catch(_err => { + resolve() + }) + ->ignore + } catch { + | err => Js.log2("ERROR", err) + } + + if gpayClicked { + Js.log("ENTERING CLicked") + try { + onclick() + } catch { + | err => Js.log2("ERROR", err) + } + Js.log("FINISHED") + } + } + + addSmartEventListener("message", handleGooglePayMessages, "onApplePayMessages") + } + json->resolve }) ->then(json => { @@ -630,7 +794,6 @@ let make = ( setElementIframeRef, iframeRef, mountPostMessage, - // ~handleApplePayMessages, ) savedPaymentElement->Js.Dict.set(componentType, paymentElement) paymentElement diff --git a/src/orca-loader/LoaderPaymentElement.res b/src/orca-loader/LoaderPaymentElement.res index 008ae7b5d..707161b03 100644 --- a/src/orca-loader/LoaderPaymentElement.res +++ b/src/orca-loader/LoaderPaymentElement.res @@ -327,7 +327,8 @@ let make = (componentType, options, setIframeRef, iframeRef, mountPostMessage) = let classesBase = optionsDict->OrcaUtils.getClasses("base") switch oElement->Js.Nullable.toOption { | Some(elem) => { - let iframeDiv = `
+ let iframeDiv = ` +
-
` +
+ ` elem->Window.innerHTML(iframeDiv) setPaymentIframeRef( Window.querySelector(`#orca-payment-element-iframeRef-${localSelectorString}`), diff --git a/src/orca-loader/newfile.txt b/src/orca-loader/newfile.txt new file mode 100644 index 000000000..c80cfcb5a --- /dev/null +++ b/src/orca-loader/newfile.txt @@ -0,0 +1,827 @@ +open Types +open ErrorUtils + +open Utils +open EventListenerManager + +open ApplePayTypes +@val external window: {..} = "window" + +external objToJson: {..} => Js.Json.t = "%identity" +external eventToJson: Types.eventData => Js.Json.t = "%identity" + +type trustPayFunctions = { + finishApplePaymentV2: (. string, ApplePayTypes.paymentRequestData) => Js.Promise.t, + executeGooglePayment: (. string, GooglePayType.paymentDataRequest) => Js.Promise.t, +} +@new external trustPayApi: Js.Json.t => trustPayFunctions = "TrustPayApi" + +let make = ( + options, + setIframeRef, + ~clientSecretId, + ~sdkSessionId="", + ~publishableKey, + // ~applePaySessionRef, + // ~handleApplePayMessages, + ~logger: option, +) => { + let handleApplePayMessages = ref(_ => ()) + let applePaySessionRef = ref(Js.Nullable.null) + let handleGooglePayMessages = ref(_ => ()) + + try { + let iframeRef = [] + let logger = logger->Belt.Option.getWithDefault(OrcaLogger.defaultLoggerConfig) + let savedPaymentElement = Js.Dict.empty() + let localOptions = options->Js.Json.decodeObject->Belt.Option.getWithDefault(Js.Dict.empty()) + let appearance = + localOptions + ->Js.Dict.get("appearance") + ->Belt.Option.getWithDefault(Js.Dict.empty()->Js.Json.object_) + + let fonts = + localOptions + ->Js.Dict.get("fonts") + ->Belt.Option.flatMap(Js.Json.decodeArray) + ->Belt.Option.getWithDefault([]) + ->Js.Json.array + + let sessionsPromise = PaymentHelpers.useSessions( + ~clientSecret=clientSecretId, + ~publishableKey, + ~optLogger=Some(logger), + (), + ) + let paymentMethodListPromise = PaymentHelpers.usePaymentMethodList( + ~clientSecret=clientSecretId, + ~publishableKey, + ~logger, + ) + + let locale = localOptions->getJsonStringFromDict("locale", "") + let loader = localOptions->getJsonStringFromDict("loader", "") + let clientSecret = localOptions->getRequiredString("clientSecret", "", ~logger) + let clientSecretReMatch = Js.Re.test_(`.+_secret_[A-Za-z0-9]+`->Js.Re.fromString, clientSecret) + let fetchPaymentsList = mountedIframeRef => { + open Promise + paymentMethodListPromise + ->then(json => { + let isApplePayPresent = + PaymentMethodsRecord.getPaymentMethodTypeFromList( + ~list=json->Utils.getDictFromJson->PaymentMethodsRecord.itemToObjMapper, + ~paymentMethod="wallet", + ~paymentMethodType="apple_pay", + )->Belt.Option.isSome + + let isGooglePayPresent = + PaymentMethodsRecord.getPaymentMethodTypeFromList( + ~list=json->Utils.getDictFromJson->PaymentMethodsRecord.itemToObjMapper, + ~paymentMethod="wallet", + ~paymentMethodType="google_pay", + )->Belt.Option.isSome + + if isApplePayPresent || isGooglePayPresent { + if ( + Window.querySelectorAll(`script[src="https://tpgw.trustpay.eu/js/v1.js"]`)->Js.Array2.length === 0 && + Window.querySelectorAll(`script[src="https://test-tpgw.trustpay.eu/js/v1.js"]`)->Js.Array2.length === 0 + ) { + let trustPayScriptURL = + publishableKey->Js.String2.startsWith("pk_prd_") + ? "https://tpgw.trustpay.eu/js/v1.js" + : "https://test-tpgw.trustpay.eu/js/v1.js" + let trustPayScript = Window.createElement("script") + trustPayScript->Window.elementSrc(trustPayScriptURL) + trustPayScript->Window.elementOnerror(err => { + Utils.logInfo(Js.log2("ERROR DURING LOADING TRUSTPAY APPLE PAY", err)) + }) + Window.body->Window.appendChild(trustPayScript) + logger.setLogInfo(~value="TrustPay Script Loaded", ~eventName=TRUSTPAY_SCRIPT, ()) + + if isGooglePayPresent { + if ( + Window.querySelectorAll(`script[src="https://pay.google.com/gp/p/js/pay.js"]`)->Js.Array2.length === 0 + ) { + let goooglePayScriptURL = "https://pay.google.com/gp/p/js/pay.js" + let googlePayScript = Window.createElement("script") + googlePayScript->Window.elementSrc(goooglePayScriptURL) + googlePayScript->Window.elementOnerror(err => { + Utils.logInfo(Js.log2("ERROR DURING LOADING GOOGLE PAY SCRIPT", err)) + }) + Window.body->Window.appendChild(googlePayScript) + logger.setLogInfo( + ~value="GooglePay Script Loaded", + ~eventName=GOOGLE_PAY_SCRIPT, + (), + ) + } + } + } + } + + // Js.Global.setTimeout(() => { + let msg = [("paymentMethodList", json)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + // }, 5000)->ignore + json->resolve + }) + ->ignore + } + let fetchCustomerDetails = mountedIframeRef => { + let customerDetailsPromise = PaymentHelpers.useCustomerDetails( + ~clientSecret=clientSecretId, + ~publishableKey, + ~optLogger=Some(logger), + ) + open Promise + customerDetailsPromise + ->then(json => { + // Js.Global.setTimeout(() => { + let msg = [("customerPaymentMethods", json)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + // }, 5000)->ignore + json->resolve + }) + ->catch(_err => { + let dict = + [("customer_payment_methods", []->Js.Json.array)]->Js.Dict.fromArray->Js.Json.object_ + let msg = [("customerPaymentMethods", dict)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve(msg->Js.Json.object_) + }) + ->ignore + } + + !clientSecretReMatch + ? manageErrorWarning( + INVALID_FORMAT, + ~dynamicStr="clientSecret is expected to be in format ******_secret_*****", + ~logger, + (), + ) + : () + + let setElementIframeRef = ref => { + iframeRef->Js.Array2.push(ref)->ignore + setIframeRef(ref) + } + let getElement = componentName => { + savedPaymentElement->Js.Dict.get(componentName) + } + let update = newOptions => { + let newOptionsDict = newOptions->getDictFromJson + switch newOptionsDict->Js.Dict.get("locale") { + | Some(val) => localOptions->Js.Dict.set("locale", val) + | None => () + } + switch newOptionsDict->Js.Dict.get("appearance") { + | Some(val) => localOptions->Js.Dict.set("appearance", val) + | None => () + } + switch newOptionsDict->Js.Dict.get("clientSecret") { + | Some(val) => localOptions->Js.Dict.set("clientSecret", val) + | None => () + } + + iframeRef->Js.Array2.forEach(iframe => { + let message = + [ + ("ElementsUpdate", true->Js.Json.boolean), + ("options", newOptionsDict->Js.Json.object_), + ]->Js.Dict.fromArray + iframe->Window.iframePostMessage(message) + }) + } + let fetchUpdates = () => { + Js.Promise.make((~resolve, ~reject as _) => { + Js.Global.setTimeout(() => resolve(. Js.Dict.empty()->Js.Json.object_), 1000)->ignore + }) + } + + let create = (componentType, newOptions) => { + componentType == "" + ? manageErrorWarning(REQUIRED_PARAMETER, ~dynamicStr="type", ~logger, ()) + : () + let otherElements = + componentType == "card" || + componentType == "cardNumber" || + componentType == "cardExpiry" || + componentType == "cardCvc" + switch componentType { + | "card" + | "cardNumber" + | "cardExpiry" + | "cardCvc" + | "payment" => () + | str => manageErrorWarning(UNKNOWN_KEY, ~dynamicStr=`${str} type in create`, ~logger, ()) + } + + let mountPostMessage = ( + mountedIframeRef, + selectorString, + sdkHandleConfirmPayment, + disableSaveCards, + ) => { + open Promise + + let widgetOptions = + [ + ("clientSecret", clientSecret->Js.Json.string), + ("appearance", appearance), + ("locale", locale), + ("loader", loader), + ("fonts", fonts), + ] + ->Js.Dict.fromArray + ->Js.Json.object_ + let message = + [ + ("paymentElementCreate", (componentType == "payment")->Js.Json.boolean), + ("otherElements", otherElements->Js.Json.boolean), + ("options", newOptions), + ("componentType", componentType->Js.Json.string), + ("paymentOptions", widgetOptions), + ("iframeId", selectorString->Js.Json.string), + ("publishableKey", publishableKey->Js.Json.string), + ("sdkSessionId", sdkSessionId->Js.Json.string), + ("sdkHandleConfirmPayment", sdkHandleConfirmPayment->Js.Json.boolean), + ("parentURL", "*"->Js.Json.string), + ]->Js.Dict.fromArray + + let handleApplePayMounted = (event: Types.event) => { + let json = event.data->eventToJson + let dict = json->getDictFromJson + + if dict->Js.Dict.get("applePayMounted")->Belt.Option.isSome { + switch sessionForApplePay->Js.Nullable.toOption { + | Some(session) => + if session.canMakePayments(.) { + let msg = [("applePayCanMakePayments", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + } else { + Utils.logInfo(Js.log("CANNOT MAKE PAYMENT USING APPLE PAY")) + } + + | None => () + } + } + } + + let handleGooglePayThirdPartyFlow = (event: Types.event) => { + let json = event.data->eventToJson + let dict = json->getDictFromJson + + switch dict->Js.Dict.get("googlePayThirdPartyFlow") { + | Some(googlePayThirdPartyOptSession) => { + let googlePayThirdPartySession = googlePayThirdPartyOptSession->Utils.getDictFromJson + + let baseDetails = { + "apiVersion": 2, + "apiVersionMinor": 0, + "environment": GlobalVars.isProd ? "PRODUCTION" : "TEST", + } + + let paymentDataRequest = GooglePayType.assign2( + Js.Dict.empty()->Js.Json.object_, + baseDetails->objToJson, + ) + + let googlePayRequest = + paymentDataRequest->GooglePayType.jsonToPaymentRequestDataType( + googlePayThirdPartySession, + ) + let secrets = + googlePayThirdPartySession->Utils.getJsonFromDict("secrets", Js.Json.null) + + let payment = secrets->Utils.getDictFromJson->Utils.getString("payment", "") + + try { + let trustpay = trustPayApi(secrets) + trustpay.executeGooglePayment(. payment, googlePayRequest) + ->then(res => { + logger.setLogInfo( + ~value="TrustPay GooglePay Success Response: " ++ res->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + (), + ) + let msg = [("googlePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->catch(err => { + let exceptionMessage = + err + ->Js.Exn.asJsExn + ->Belt.Option.flatMap(Js.Exn.message) + ->Belt.Option.getWithDefault("TrustPay GooglePay Error") + logger.setLogInfo( + ~value=exceptionMessage, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=ERROR, + ~logCategory=USER_ERROR, + (), + ) + let msg = [("googlePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->ignore + } catch { + | _ => { + logger.setLogInfo( + ~value="TrustPay API initialising error", + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + (), + ) + let msg = [("googlePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + } + } + } + | _ => () + } + // let gpayClicked = + // json->OrcaUtils.getOptionalJsonFromJson("GpayClicked")->OrcaUtils.getBoolfromjson(false) + // let gpayPaymentRequestData = + // json->OrcaUtils.getOptionalJsonFromJson("gpayPaymentRequestData") + // if gpayClicked { + // let gPayClient = GooglePayType.google( + // { + // "environment": publishableKey->Js.String2.startsWith("pk_prd_") + // ? "PRODUCTION" + // : "TEST", + // }->toJson, + // ) + // let data = switch gpayPaymentRequestData { + // | Some(json) => json + // | None => Js.Dict.empty()->Js.Json.object_ + // } + // try { + // gPayClient.loadPaymentData(. data) + // ->then(json => { + // logger.setLogInfo( + // ~value=json->toJson->Js.Json.stringify, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~logType=DEBUG, + // (), + // ) + // let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray + // mountedIframeRef->Window.iframePostMessage(msg) + // resolve() + // }) + // ->catch(err => { + // logger.setLogInfo( + // ~value=err->toJson->Js.Json.stringify, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~logType=DEBUG, + // (), + // ) + // let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray + // mountedIframeRef->Window.iframePostMessage(msg) + // resolve() + // }) + // ->ignore + // } catch { + // | err => { + // logger.setLogInfo( + // ~value=err->toJson->Js.Json.stringify, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~logType=DEBUG, + // (), + // ) + // let msg = [("gpayErorr", err->toJson)]->Js.Dict.fromArray + // mountedIframeRef->Window.iframePostMessage(msg) + // } + // } + // } + } + + addSmartEventListener("message", handleApplePayMounted, "onApplePayMount") + addSmartEventListener("message", handleGooglePayThirdPartyFlow, "onGooglePayThirdParty") + Window.removeEventListener("message", handleApplePayMessages.contents) + sessionsPromise + ->then(json => { + let sessionsArr = + json + ->Js.Json.decodeObject + ->Belt.Option.getWithDefault(Js.Dict.empty()) + ->SessionsType.getSessionsTokenJson("session_token") + + let applePayPresent = sessionsArr->Js.Array2.find(item => { + let x = + item + ->Js.Json.decodeObject + ->Belt.Option.flatMap(x => { + x->Js.Dict.get("wallet_name") + }) + ->Belt.Option.flatMap(Js.Json.decodeString) + ->Belt.Option.getWithDefault("") + x === "apple_pay" || x === "applepay" + }) + let googlePayPresent = sessionsArr->Js.Array2.find(item => { + let x = + item + ->Js.Json.decodeObject + ->Belt.Option.flatMap(x => { + x->Js.Dict.get("wallet_name") + }) + ->Belt.Option.flatMap(Js.Json.decodeString) + ->Belt.Option.getWithDefault("") + x === "google_pay" || x === "googlepay" + }) + + (json, applePayPresent, googlePayPresent)->resolve + }) + ->then(res => { + let (json, applePayPresent, googlePayPresent) = res + if componentType === "payment" && applePayPresent->Belt.Option.isSome { + //do operations here + + let processPayment = (token: Js.Json.t) => { + //let body = PaymentBody.applePayBody(~token) + let msg = [("applePayProcessPayment", token)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + } + + handleApplePayMessages := + ( + (event: Types.event) => { + let json = event.data->eventToJson + let dict = json->getDictFromJson + + switch dict->Js.Dict.get("applePayButtonClicked") { + | Some(val) => + if val->Js.Json.decodeBoolean->Belt.Option.getWithDefault(false) { + let isDelayedSessionToken = + applePayPresent + ->Belt.Option.flatMap(Js.Json.decodeObject) + ->Belt.Option.getWithDefault(Js.Dict.empty()) + ->Js.Dict.get("delayed_session_token") + ->Belt.Option.getWithDefault(Js.Json.null) + ->Js.Json.decodeBoolean + ->Belt.Option.getWithDefault(false) + + if isDelayedSessionToken { + logger.setLogInfo( + ~value="Delayed Session Token Flow", + ~eventName=APPLE_PAY_FLOW, + ~paymentMethod="APPLE_PAY", + (), + ) + + let applePayPresent = + dict + ->Js.Dict.get("applePayPresent") + ->Belt.Option.flatMap(Js.Json.decodeObject) + ->Belt.Option.getWithDefault(Js.Dict.empty()) + + let connector = + applePayPresent + ->Js.Dict.get("connector") + ->Belt.Option.getWithDefault(Js.Json.null) + ->Js.Json.decodeString + ->Belt.Option.getWithDefault("") + + switch connector { + | "trustpay" => + logger.setLogInfo( + ~value="TrustPay Connector Flow", + ~eventName=APPLE_PAY_FLOW, + ~paymentMethod="APPLE_PAY", + (), + ) + let secrets = + applePayPresent + ->Js.Dict.get("session_token_data") + ->Belt.Option.getWithDefault(Js.Json.null) + ->Js.Json.decodeObject + ->Belt.Option.getWithDefault(Js.Dict.empty()) + ->Js.Dict.get("secrets") + ->Belt.Option.getWithDefault(Js.Json.null) + + let paymentRequest = + applePayPresent + ->Js.Dict.get("payment_request_data") + ->Belt.Option.flatMap(Js.Json.decodeObject) + ->Belt.Option.getWithDefault(Js.Dict.empty()) + ->ApplePayTypes.jsonToPaymentRequestDataType + + let payment = + secrets + ->Js.Json.decodeObject + ->Belt.Option.getWithDefault(Js.Dict.empty()) + ->Js.Dict.get("payment") + ->Belt.Option.getWithDefault(Js.Json.null) + ->Js.Json.decodeString + ->Belt.Option.getWithDefault("") + + try { + let trustpay = trustPayApi(secrets) + trustpay.finishApplePaymentV2(. payment, paymentRequest) + ->then(res => { + logger.setLogInfo( + ~value="TrustPay ApplePay Success Response: " ++ + res->Js.Json.stringify, + ~eventName=APPLE_PAY_FLOW, + ~paymentMethod="APPLE_PAY", + (), + ) + let msg = + [("applePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->catch(err => { + let exceptionMessage = + err + ->Js.Exn.asJsExn + ->Belt.Option.flatMap(Js.Exn.message) + ->Belt.Option.getWithDefault("TrustPay ApplePay Error") + logger.setLogInfo( + ~eventName=APPLE_PAY_FLOW, + ~paymentMethod="APPLE_PAY", + ~value=exceptionMessage, + (), + ) + let msg = + [("applePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->ignore + } catch { + | _ => { + logger.setLogInfo( + ~value="TrustPay API initialising error", + ~eventName=APPLE_PAY_FLOW, + ~paymentMethod="APPLE_PAY", + (), + ) + let msg = + [("applePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + } + } + | _ => () + } + } else { + let paymentRequest = + applePayPresent + ->Belt.Option.flatMap(Js.Json.decodeObject) + ->Belt.Option.getWithDefault(Js.Dict.empty()) + ->Js.Dict.get("payment_request_data") + ->Belt.Option.getWithDefault(Js.Dict.empty()->Js.Json.object_) + ->Utils.transformKeys(Utils.CamelCase) + + let ssn = applePaySession(3, paymentRequest) + switch applePaySessionRef.contents->Js.Nullable.toOption { + | Some(session) => + try { + session.abort(.) + } catch { + | error => Js.log2("Abort fail", error) + } + | None => () + } + + ssn.begin(.) + applePaySessionRef := ssn->Js.Nullable.return + + ssn.onvalidatemerchant = _event => { + let merchantSession = + applePayPresent + ->Belt.Option.flatMap(Js.Json.decodeObject) + ->Belt.Option.getWithDefault(Js.Dict.empty()) + ->Js.Dict.get("session_token_data") + ->Belt.Option.getWithDefault(Js.Dict.empty()->Js.Json.object_) + ->Utils.transformKeys(Utils.CamelCase) + ssn.completeMerchantValidation(. merchantSession) + } + + ssn.onpaymentauthorized = event => { + ssn.completePayment(. {"status": ssn.\"STATUS_SUCCESS"}->objToJson) + applePaySessionRef := Js.Nullable.null + processPayment(event.payment.token) + } + ssn.oncancel = _ev => { + let msg = + [("showApplePayButton", true->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + applePaySessionRef := Js.Nullable.null + Utils.logInfo(Js.log("Apple Pay payment cancelled")) + } + } + } else { + () + } + | None => () + } + } + ) + + addSmartEventListener("message", handleApplePayMessages.contents, "onApplePayMessages") + } + if componentType === "payment" && googlePayPresent->Belt.Option.isSome { + let dict = json->getDictFromJson + Js.log2("ENTERING GOOGLE PAY BLOCK", json) + let sessionObj = SessionsType.itemToObjMapper(dict, Others) + let gPayToken = SessionsType.getPaymentSessionObj(sessionObj.sessionsToken, Gpay) + + let tokenObj = switch gPayToken { + | OtherTokenOptional(optToken) => optToken + | _ => Some(SessionsType.defaultToken) + } + + let gpayobj = switch tokenObj { + | Some(val) => val + | _ => SessionsType.defaultToken + } + + let baseRequest = { + "apiVersion": 2, + "apiVersionMinor": 0, + } + let paymentDataRequest = GooglePayType.assign2( + Js.Dict.empty()->Js.Json.object_, + baseRequest->toJson, + ) + let payRequest = GooglePayType.assign( + Js.Dict.empty()->Js.Json.object_, + baseRequest->toJson, + { + "allowedPaymentMethods": gpayobj.allowed_payment_methods->arrayJsonToCamelCase, + }->toJson, + ) + paymentDataRequest.allowedPaymentMethods = + gpayobj.allowed_payment_methods->arrayJsonToCamelCase + paymentDataRequest.transactionInfo = gpayobj.transaction_info->transformKeys(CamelCase) + paymentDataRequest.merchantInfo = gpayobj.merchant_info->transformKeys(CamelCase) + let gPayClient = GooglePayType.google( + { + "environment": publishableKey->Js.String2.startsWith("pk_prd_") + ? "PRODUCTION" + : "TEST", + }->toJson, + ) + + let onclick = () => { + gPayClient.loadPaymentData(. paymentDataRequest) + ->then(json => { + Js.log2("RES", json) + logger.setLogInfo( + ~value=json->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + Js.log2("RES", json) + let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->catch(err => { + Js.log2("ERROR", err) + logger.setLogInfo( + ~value=err->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + + let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->ignore + } + let buttonStyle = { + let obj = { + "onClick": onclick, + "buttonType": "Buy", + "buttonSizeMode": "fill", + "buttonColor": "black", + } + obj->toJson + } + + let handleGooglePayMessages = (event: Types.event) => { + Js.log("ENTERING HANDLE FUNCTION") + let evJson = event.data->eventToJson + let gpayClicked = + evJson + ->OrcaUtils.getOptionalJsonFromJson("GpayClicked") + ->OrcaUtils.getBoolfromjson(false) + // let handleGpayClick = () => { + try { + gPayClient.isReadyToPay(. payRequest) + ->then(_ => { + let button = gPayClient.createButton(. buttonStyle) + let gpayWrapper = GooglePayType.getElementById( + Utils.document, + "google-pay-button", + ) + gpayWrapper.innerHTML = "" + gpayWrapper.appendChild(. button) + resolve() + }) + ->catch(_err => { + resolve() + }) + ->ignore + } catch { + | err => Js.log2("ERROR", err) + } + // } + // window["gpayHandleClick"] = handleGpayClick + + if gpayClicked { + Js.log("ENTERING CLicked") + try { + // Js.log2( + // "CALLING", + // gPayClient.loadPaymentData(. paymentDataRequest)->then(res => { + // Js.log2("RESPONSE LOG", res) + // resolve() + // }), + // ) + gPayClient.loadPaymentData(. paymentDataRequest) + ->then(json => { + Js.log2("RES", json) + logger.setLogInfo( + ~value=json->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + Js.log2("RES", json) + let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->catch(err => { + Js.log2("ERROR", err) + logger.setLogInfo( + ~value=err->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + + let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->ignore + } catch { + | err => Js.log2("ERROR", err) + } + Js.log("FINISHED") + } + } + + addSmartEventListener("message", handleGooglePayMessages, "onApplePayMessages") + } + + json->resolve + }) + ->then(json => { + let msg = [("sessions", json)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + json->resolve + }) + ->ignore + fetchPaymentsList(mountedIframeRef) + disableSaveCards ? () : fetchCustomerDetails(mountedIframeRef) + mountedIframeRef->Window.iframePostMessage(message) + } + + let paymentElement = LoaderPaymentElement.make( + componentType, + newOptions, + setElementIframeRef, + iframeRef, + mountPostMessage, + ) + savedPaymentElement->Js.Dict.set(componentType, paymentElement) + paymentElement + } + { + getElement: getElement, + update: update, + fetchUpdates: fetchUpdates, + create: create, + } + } catch { + | _e => defaultElement + } +} diff --git a/webpack.common.js b/webpack.common.js index e33ab5799..7a4714f61 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -76,6 +76,7 @@ module.exports = (publicPath = "auto") => { headers: { "Cache-Control": "max-age=31536000,must-revalidate", }, + // allowedHosts: ["laevus.serveo.net"], }, plugins: [ new MiniCssExtractPlugin(), @@ -95,13 +96,13 @@ module.exports = (publicPath = "auto") => { // new webpack.HTMLInjectPlugin({ // publicPath: JSON.stringify(repoVersion), // }), - sentryWebpackPlugin({ - org: "sentry", - project: "hyperswitch-react-sdk", - authToken: - "23d916c8cfa647c6b977ec2e276f4c95b01ea36e311b4c1cb82ac2c65570b95d", - url: "https://sentry.internal.svc.k8s.jarvis.mum.juspay.net/", - }), + // sentryWebpackPlugin({ + // org: "sentry", + // project: "hyperswitch-react-sdk", + // authToken: + // "23d916c8cfa647c6b977ec2e276f4c95b01ea36e311b4c1cb82ac2c65570b95d", + // url: "https://sentry.internal.svc.k8s.jarvis.mum.juspay.net/", + // }), ], module: { rules: [ From 0546e48de2fa18f33ec75e338588e00ee3e4ebd7 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar Date: Sun, 24 Sep 2023 18:19:19 +0530 Subject: [PATCH 3/9] hotfix to make gpay work on all platforms --- src/Payments/GPay.res | 349 ++++++++++++++++------------------- src/orca-loader/Elements.res | 176 ++++-------------- 2 files changed, 193 insertions(+), 332 deletions(-) diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index a93ccec37..5cfc1a3e8 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -13,16 +13,16 @@ open GooglePayType let default = (props: props) => { let (loggerState, _setLoggerState) = Recoil.useRecoilState(loggerAtom) - // let {iframeId} = Recoil.useRecoilValueFromAtom(keys) + let {iframeId} = Recoil.useRecoilValueFromAtom(keys) let {publishableKey} = Recoil.useRecoilValueFromAtom(keys) let options = Recoil.useRecoilValueFromAtom(optionAtom) let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Gpay) let sync = PaymentHelpers.usePaymentSync(Some(loggerState), Gpay) - // let status = CommonHooks.useScript("https://pay.google.com/gp/p/js/pay.js") - // let baseRequest = { - // apiVersion: 2, - // apiVersionMinor: 0, - // } + let status = CommonHooks.useScript("https://pay.google.com/gp/p/js/pay.js") + let baseRequest = { + apiVersion: 2, + apiVersionMinor: 0, + } let isGooglePaySDKFlow = React.useMemo1(() => { props.sessionObj->Belt.Option.isSome }, [props.sessionObj]) @@ -30,19 +30,19 @@ let default = (props: props) => { props.thirdPartySessionObj->Belt.Option.isSome }, [props.sessionObj]) - // let googlePaySessionObj = React.useMemo1(() => { - // switch props.sessionObj { - // | Some(val) => val - // | None => { - // walletName: NONE, - // token: "", - // sessionId: "", - // allowed_payment_methods: [], - // transaction_info: Js.Json.null, - // merchant_info: Js.Json.null, - // } - // } - // }, [props.sessionObj]) + let googlePaySessionObj = React.useMemo1(() => { + switch props.sessionObj { + | Some(val) => val + | None => { + walletName: NONE, + token: "", + sessionId: "", + allowed_payment_methods: [], + transaction_info: Js.Json.null, + merchant_info: Js.Json.null, + } + } + }, [props.sessionObj]) let googlePayPaymentMethodType = switch PaymentMethodsRecord.getPaymentMethodTypeFromList( ~list=props.list, @@ -66,15 +66,15 @@ let default = (props: props) => { ? props.list->PaymentUtils.getConnectors(Wallets(Gpay(SDK))) : props.list->PaymentUtils.getConnectors(Wallets(Gpay(Redirect))) - // let getGoogleIsReadyToPayRequest = () => { - // assign( - // Js.Dict.empty()->Js.Json.object_, - // baseRequest->toJson, - // { - // "allowedPaymentMethods": googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase, - // }->toJson, - // ) - // } + let getGoogleIsReadyToPayRequest = () => { + assign( + Js.Dict.empty()->Js.Json.object_, + baseRequest->toJson, + { + "allowedPaymentMethods": googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase, + }->toJson, + ) + } let processPayment = (body: array<(string, Js.Json.t)>) => { intent( ~bodyArr=body, @@ -105,27 +105,27 @@ let default = (props: props) => { Some(() => {Window.removeEventListener("message", handle)}) }) - // let (_, buttonType, _) = options.wallets.style.type_ - // let (_, heightType, _) = options.wallets.style.height - // let height = switch heightType { - // | GooglePay(val) => val - // | _ => 48 - // } - // let getGooglePaymentDataRequest = () => { - // let paymentDataRequest = assign2(Js.Dict.empty()->Js.Json.object_, baseRequest->toJson) + let (_, buttonType, _) = options.wallets.style.type_ + let (_, heightType, _) = options.wallets.style.height + let height = switch heightType { + | GooglePay(val) => val + | _ => 48 + } + let getGooglePaymentDataRequest = () => { + let paymentDataRequest = assign2(Js.Dict.empty()->Js.Json.object_, baseRequest->toJson) - // paymentDataRequest.allowedPaymentMethods = - // googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase + paymentDataRequest.allowedPaymentMethods = + googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase - // paymentDataRequest.transactionInfo = - // googlePaySessionObj.transaction_info->transformKeys(CamelCase) - // paymentDataRequest.merchantInfo = googlePaySessionObj.merchant_info->transformKeys(CamelCase) - // paymentDataRequest - // } + paymentDataRequest.transactionInfo = + googlePaySessionObj.transaction_info->transformKeys(CamelCase) + paymentDataRequest.merchantInfo = googlePaySessionObj.merchant_info->transformKeys(CamelCase) + paymentDataRequest + } - // let getGooglePaymentsClient = () => { - // google({"environment": GlobalVars.isProd ? "PRODUCTION" : "TEST"}->toJson) - // } + let getGooglePaymentsClient = () => { + google({"environment": GlobalVars.isProd ? "PRODUCTION" : "TEST"}->toJson) + } let syncPayment = () => { sync( @@ -137,147 +137,120 @@ let default = (props: props) => { (), ) } - // let paymentDataRequest = getGooglePaymentDataRequest() + let paymentDataRequest = getGooglePaymentDataRequest() - // let onGooglePaymentButtonClicked = () => { - // loggerState.setLogInfo( - // ~value="GooglePay Button Clicked", - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // (), - // ) - // if isInvokeSDKFlow { - // let isDelayedSessionToken = - // props.thirdPartySessionObj - // ->Belt.Option.getWithDefault(Js.Json.null) - // ->Js.Json.decodeObject - // ->Belt.Option.getWithDefault(Js.Dict.empty()) - // ->Js.Dict.get("delayed_session_token") - // ->Belt.Option.getWithDefault(Js.Json.null) - // ->Js.Json.decodeBoolean - // ->Belt.Option.getWithDefault(false) + let onGooglePaymentButtonClicked = () => { + loggerState.setLogInfo( + ~value="GooglePay Button Clicked", + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + (), + ) + if isInvokeSDKFlow { + let isDelayedSessionToken = + props.thirdPartySessionObj + ->Belt.Option.getWithDefault(Js.Json.null) + ->Js.Json.decodeObject + ->Belt.Option.getWithDefault(Js.Dict.empty()) + ->Js.Dict.get("delayed_session_token") + ->Belt.Option.getWithDefault(Js.Json.null) + ->Js.Json.decodeBoolean + ->Belt.Option.getWithDefault(false) - // if isDelayedSessionToken { - // loggerState.setLogInfo( - // ~logType=DEBUG, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~value="isDelayedSessionToken", - // (), - // ) - // let bodyDict = PaymentBody.gPayThirdPartySdkBody(~connectors) - // loggerState.setLogInfo( - // ~logType=DEBUG, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~value=bodyDict->toJson->Js.Json.stringify, - // (), - // ) - // processPayment(bodyDict) - // } else { - // handlePostMessage([ - // ("fullscreen", true->Js.Json.boolean), - // ("param", "paymentloader"->Js.Json.string), - // ("iframeId", iframeId->Js.Json.string), - // ]) - // loggerState.setLogInfo( - // ~eventName=GOOGLE_PAY_FLOW, - // ~logType=DEBUG, - // ~paymentMethod="GOOGLE_PAY", - // ~value=paymentDataRequest->toJson->Js.Json.stringify, - // (), - // ) - // options.readOnly - // ? () - // : { - // handlePostMessage([ - // ("GpayClicked", true->Js.Json.boolean), - // ("gpayPaymentRequestData", paymentDataRequest->toJson), - // ]) - // } + if isDelayedSessionToken { + loggerState.setLogInfo( + ~logType=DEBUG, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~value="isDelayedSessionToken", + (), + ) + let bodyDict = PaymentBody.gPayThirdPartySdkBody(~connectors) + loggerState.setLogInfo( + ~logType=DEBUG, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~value=bodyDict->toJson->Js.Json.stringify, + (), + ) + processPayment(bodyDict) + } else { + handlePostMessage([ + ("fullscreen", true->Js.Json.boolean), + ("param", "paymentloader"->Js.Json.string), + ("iframeId", iframeId->Js.Json.string), + ]) + loggerState.setLogInfo( + ~eventName=GOOGLE_PAY_FLOW, + ~logType=DEBUG, + ~paymentMethod="GOOGLE_PAY", + ~value=paymentDataRequest->toJson->Js.Json.stringify, + (), + ) + options.readOnly ? () : handlePostMessage([("GpayClicked", true->Js.Json.boolean)]) + } + } else { + loggerState.setLogInfo( + ~logType=DEBUG, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~value="not isInvokeSDKFlow", + (), + ) + let bodyDict = PaymentBody.gpayRedirectBody(~connectors) + processPayment(bodyDict) + } + } - // // open Promise - // // let gPayClient = GooglePayType.google( - // // { - // // "environment": publishableKey->Js.String2.startsWith("pk_prd_") - // // ? "PRODUCTION" - // // : "TEST", - // // }->toJson, - // // ) - // // gPayClient.loadPaymentData(. paymentDataRequest->toJson) - // // ->then(json => { - // // resolve() - // // }) - // // ->catch(err => { - // // handlePostMessage([("fullscreen", false->Js.Json.boolean)]) - // // resolve() - // // }) - // // ->ignore - // // } - // } - // } else { - // loggerState.setLogInfo( - // ~logType=DEBUG, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~value="not isInvokeSDKFlow", - // (), - // ) - // let bodyDict = PaymentBody.gpayRedirectBody(~connectors) - // processPayment(bodyDict) - // } - // } + let buttonStyle = { + let obj = { + "onClick": onGooglePaymentButtonClicked, + "buttonType": switch buttonType { + | GooglePay(var) => var->getLabel + | _ => Default->getLabel + }, + "buttonSizeMode": "fill", + "buttonColor": options.wallets.style.theme == Dark ? "black" : "white", + } + obj->toJson + } + let addGooglePayButton = () => { + let paymentClient = getGooglePaymentsClient() - // let buttonStyle = { - // let obj = { - // "onClick": onGooglePaymentButtonClicked, - // "buttonType": switch buttonType { - // | GooglePay(var) => var->getLabel - // | _ => Default->getLabel - // }, - // "buttonSizeMode": "fill", - // "buttonColor": options.wallets.style.theme == Dark ? "black" : "white", - // } - // obj->toJson - // } - // let addGooglePayButton = () => { - // let paymentClient = getGooglePaymentsClient() + let button = paymentClient.createButton(. buttonStyle) + let gpayWrapper = getElementById(Utils.document, "google-pay-button") + gpayWrapper.innerHTML = "" + gpayWrapper.appendChild(. button) + } - // let button = paymentClient.createButton(. buttonStyle) - // let gpayWrapper = getElementById(Utils.document, "google-pay-button") - // gpayWrapper.innerHTML = "" - // gpayWrapper.appendChild(. button) - // } + let onGooglePayLoaded = () => { + open Promise + let paymentsClient = getGooglePaymentsClient() - // let onGooglePayLoaded = () => { - // open Promise - // let paymentsClient = getGooglePaymentsClient() + if paymentExperience == PaymentMethodsRecord.RedirectToURL || isGooglePayThirdPartyFlow { + addGooglePayButton() + } else if isInvokeSDKFlow { + paymentsClient.isReadyToPay(. getGoogleIsReadyToPayRequest()) + ->then(_ => { + addGooglePayButton() + resolve() + }) + ->catch(_err => { + resolve() + }) + ->ignore + } + } - // if paymentExperience == PaymentMethodsRecord.RedirectToURL || isGooglePayThirdPartyFlow { - // addGooglePayButton() - // } else if isInvokeSDKFlow { - // paymentsClient.isReadyToPay(. getGoogleIsReadyToPayRequest()) - // ->then(_ => { - // addGooglePayButton() - // resolve() - // }) - // ->catch(_err => { - // resolve() - // }) - // ->ignore - // } - // } + React.useEffect0(() => { + try { + onGooglePayLoaded() + } catch { + | _err => Utils.logInfo(Js.log("Error loading Gpay")) + } - // React.useEffect2(() => { - // if status == "ready" { - // try { - // onGooglePayLoaded() - // } catch { - // | _err => Utils.logInfo(Js.log("Error loading Gpay")) - // } - // } - // None - // }, (status, props)) + None + }) React.useEffect0(() => { let handleGooglePayMessages = (ev: Window.event) => { @@ -303,13 +276,13 @@ let default = (props: props) => { ) }) - //
Belt.Int.toString}px`, ())} - // id="google-pay-button" - // className={`w-full flex flex-row justify-center rounded-md`} - // /> - let handleClick = _e => { - handlePostMessage([("GpayClicked", true->Js.Json.boolean)]) - } - +
Belt.Int.toString}px`, ())} + id="google-pay-button" + className={`w-full flex flex-row justify-center rounded-md`} + /> + // let handleClick = _e => { + // handlePostMessage([("GpayClicked", true->Js.Json.boolean)]) + // } + // } diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 8e5aac85b..12ae688fd 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -343,63 +343,6 @@ let make = ( } | _ => () } - // let gpayClicked = - // json->OrcaUtils.getOptionalJsonFromJson("GpayClicked")->OrcaUtils.getBoolfromjson(false) - // let gpayPaymentRequestData = - // json->OrcaUtils.getOptionalJsonFromJson("gpayPaymentRequestData") - // if gpayClicked { - // let gPayClient = GooglePayType.google( - // { - // "environment": publishableKey->Js.String2.startsWith("pk_prd_") - // ? "PRODUCTION" - // : "TEST", - // }->toJson, - // ) - // let data = switch gpayPaymentRequestData { - // | Some(json) => json - // | None => Js.Dict.empty()->Js.Json.object_ - // } - // try { - // gPayClient.loadPaymentData(. data) - // ->then(json => { - // logger.setLogInfo( - // ~value=json->toJson->Js.Json.stringify, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~logType=DEBUG, - // (), - // ) - // let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray - // mountedIframeRef->Window.iframePostMessage(msg) - // resolve() - // }) - // ->catch(err => { - // logger.setLogInfo( - // ~value=err->toJson->Js.Json.stringify, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~logType=DEBUG, - // (), - // ) - // let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray - // mountedIframeRef->Window.iframePostMessage(msg) - // resolve() - // }) - // ->ignore - // } catch { - // | err => { - // logger.setLogInfo( - // ~value=err->toJson->Js.Json.stringify, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~logType=DEBUG, - // (), - // ) - // let msg = [("gpayErorr", err->toJson)]->Js.Dict.fromArray - // mountedIframeRef->Window.iframePostMessage(msg) - // } - // } - // } } addSmartEventListener("message", handleApplePayMounted, "onApplePayMount") @@ -670,111 +613,56 @@ let make = ( }->toJson, ) - let onclick = () => { - gPayClient.loadPaymentData(. paymentDataRequest->toJson) - ->then(json => { - Js.log2("RES", json) - logger.setLogInfo( - ~value=json->toJson->Js.Json.stringify, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, - (), - ) - Js.log2("RES", json) - let msg = [ - ("gpayResponse", json->toJson), - ("fullscreen", true->Js.Json.boolean), - ("param", "paymentloader"->Js.Json.string), - // ("iframeId", iframeId->Js.Json.string), - ]->Js.Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - resolve() - }) - ->catch(err => { - Js.log2("ERROR", err) - logger.setLogInfo( - ~value=err->toJson->Js.Json.stringify, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, - (), - ) + let onGpayclick = () => { + Js.log("ENTERED CLicked") + Js.Global.setTimeout(() => { + gPayClient.loadPaymentData(. paymentDataRequest->toJson) + ->then(json => { + logger.setLogInfo( + ~value=json->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->catch(err => { + logger.setLogInfo( + ~value=err->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) - let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - resolve() - }) - ->ignore + let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->ignore + }, 1)->ignore } - // let buttonStyle = { - // let obj = { - // "onClick": onclick, - // "buttonType": "Buy", - // "buttonSizeMode": "fill", - // "buttonColor": "black", - // } - // obj->toJson - // } - // try { - // gPayClient.isReadyToPay(. payRequest) - // ->then(_ => { - // let button = gPayClient.createButton(. buttonStyle) - // let gpayWrapper = GooglePayType.getElementById(Utils.document, "google-pay-button") - // gpayWrapper.innerHTML = "" - // gpayWrapper.appendChild(. button) - // resolve() - // }) - // ->catch(_err => { - // resolve() - // }) - // ->ignore - // } catch { - // | err => Js.log2("ERROR", err) - // } let handleGooglePayMessages = (event: Types.event) => { Js.log("ENTERING HANDLE FUNCTION") let evJson = event.data->eventToJson + let gpayClicked = evJson ->OrcaUtils.getOptionalJsonFromJson("GpayClicked") ->OrcaUtils.getBoolfromjson(false) - try { - gPayClient.isReadyToPay(. payRequest) - ->then(_ => { - // let button = gPayClient.createButton(. buttonStyle) - // let gpayWrapper = GooglePayType.getElementById( - // Utils.document, - // "google-pay-button", - // ) - // gpayWrapper.innerHTML = "" - // gpayWrapper.appendChild(. button) - Js.log("READY") - resolve() - }) - ->catch(_err => { - resolve() - }) - ->ignore - } catch { - | err => Js.log2("ERROR", err) - } if gpayClicked { Js.log("ENTERING CLicked") - try { - onclick() - } catch { - | err => Js.log2("ERROR", err) - } + onGpayclick() Js.log("FINISHED") } } - addSmartEventListener("message", handleGooglePayMessages, "onApplePayMessages") } - json->resolve }) ->then(json => { From f8847960b0f4f28962ab610ac0f1a66324bc4a8a Mon Sep 17 00:00:00 2001 From: Praful Koppalkar Date: Sun, 24 Sep 2023 18:26:51 +0530 Subject: [PATCH 4/9] added comments --- src/Payments/GPay.res | 15 ++++++++------- src/orca-loader/Elements.res | 32 +++++++++++++++++++++----------- src/orca-loader/Hyper.res | 4 ---- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 5cfc1a3e8..3f7f22580 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -242,15 +242,16 @@ let default = (props: props) => { } } - React.useEffect0(() => { - try { - onGooglePayLoaded() - } catch { - | _err => Utils.logInfo(Js.log("Error loading Gpay")) + React.useEffect2(() => { + if status == "ready" { + try { + onGooglePayLoaded() + } catch { + | _err => Utils.logInfo(Js.log("Error loading Gpay")) + } } - None - }) + }, (status, props)) React.useEffect0(() => { let handleGooglePayMessages = (ev: Window.event) => { diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 12ae688fd..3a68ecb51 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -22,13 +22,10 @@ let make = ( ~clientSecretId, ~sdkSessionId="", ~publishableKey, - ~applePaySessionRef, - ~handleApplePayMessages, ~logger: option, ) => { let handleApplePayMessages = ref(_ => ()) let applePaySessionRef = ref(Js.Nullable.null) - let handleGooglePayMessages = ref(_ => ()) try { let iframeRef = [] @@ -594,13 +591,14 @@ let make = ( Js.Dict.empty()->Js.Json.object_, baseRequest->toJson, ) - let payRequest = GooglePayType.assign( - Js.Dict.empty()->Js.Json.object_, - baseRequest->toJson, - { - "allowedPaymentMethods": gpayobj.allowed_payment_methods->arrayJsonToCamelCase, - }->toJson, - ) + + // let payRequest = GooglePayType.assign( + // Js.Dict.empty()->Js.Json.object_, + // baseRequest->toJson, + // { + // "allowedPaymentMethods": gpayobj.allowed_payment_methods->arrayJsonToCamelCase, + // }->toJson, + // ) paymentDataRequest.allowedPaymentMethods = gpayobj.allowed_payment_methods->arrayJsonToCamelCase paymentDataRequest.transactionInfo = gpayobj.transaction_info->transformKeys(CamelCase) @@ -649,11 +647,23 @@ let make = ( let handleGooglePayMessages = (event: Types.event) => { Js.log("ENTERING HANDLE FUNCTION") let evJson = event.data->eventToJson - let gpayClicked = evJson ->OrcaUtils.getOptionalJsonFromJson("GpayClicked") ->OrcaUtils.getBoolfromjson(false) + // try { + // gPayClient.isReadyToPay(. payRequest) + // ->then(_ => { + // Js.log("READY") + // resolve() + // }) + // ->catch(_err => { + // resolve() + // }) + // ->ignore + // } catch { + // | err => Js.log2("ERROR", err) + // } if gpayClicked { Js.log("ENTERING CLicked") diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res index 4294c733a..535622209 100644 --- a/src/orca-loader/Hyper.res +++ b/src/orca-loader/Hyper.res @@ -113,12 +113,10 @@ let make = (publishableKey, _options: option, analyticsInfo: option ()) let clientSecret = ref("") let setIframeRef = ref => { iframeRef.contents->Js.Array2.push(ref)->ignore } - let applePaySessionRef = ref(Js.Nullable.null) let retrievePaymentIntentFn = clientSecret => { let headers = { @@ -277,8 +275,6 @@ let make = (publishableKey, _options: option, analyticsInfo: option Date: Mon, 25 Sep 2023 14:56:53 +0530 Subject: [PATCH 5/9] hotfix complete --- src/LoaderController.res | 10 +++ src/Payments/GPay.res | 104 +------------------------ src/Types/GooglePayType.res | 2 +- src/Utilities/RecoilAtoms.res | 1 + src/orca-loader/Elements.res | 142 ++++++++++++++++++++-------------- webpack.common.js | 14 ++-- 6 files changed, 108 insertions(+), 165 deletions(-) diff --git a/src/LoaderController.res b/src/LoaderController.res index acb307002..128e88dd5 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -37,6 +37,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => { let (options, setOptions) = Recoil.useRecoilState(elementOptions) let (optionsPayment, setOptionsPayment) = Recoil.useRecoilState(optionAtom) let setSessionId = Recoil.useSetRecoilState(sessionId) + let setIsGooglePayReady = Recoil.useSetRecoilState(isGooglePayReady) let (divH, setDivH) = React.useState(_ => 0.0) let {showCardFormByDefault, paymentMethodOrder} = optionsPayment @@ -272,6 +273,15 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => { if dict->getDictIsSome("sessions") { setSessions(._ => Loaded(dict->getJsonObjectFromDict("sessions"))) } + if dict->getDictIsSome("isReadyToPay") { + Js.log("INSIDE") + setIsGooglePayReady(._ => + dict + ->getJsonObjectFromDict("isReadyToPay") + ->Js.Json.decodeBoolean + ->Belt.Option.getWithDefault(false) + ) + } if dict->getDictIsSome("paymentMethodList") { let list = dict->getJsonObjectFromDict("paymentMethodList") list == Js.Dict.empty()->Js.Json.object_ diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 3f7f22580..d45015764 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -9,8 +9,6 @@ type props = { open GooglePayType -// external toJson: 'a => Js.Json.t = "%identity" - let default = (props: props) => { let (loggerState, _setLoggerState) = Recoil.useRecoilState(loggerAtom) let {iframeId} = Recoil.useRecoilValueFromAtom(keys) @@ -18,11 +16,8 @@ let default = (props: props) => { let options = Recoil.useRecoilValueFromAtom(optionAtom) let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Gpay) let sync = PaymentHelpers.usePaymentSync(Some(loggerState), Gpay) + let isGPayReady = Recoil.useRecoilValueFromAtom(isGooglePayReady) let status = CommonHooks.useScript("https://pay.google.com/gp/p/js/pay.js") - let baseRequest = { - apiVersion: 2, - apiVersionMinor: 0, - } let isGooglePaySDKFlow = React.useMemo1(() => { props.sessionObj->Belt.Option.isSome }, [props.sessionObj]) @@ -30,20 +25,6 @@ let default = (props: props) => { props.thirdPartySessionObj->Belt.Option.isSome }, [props.sessionObj]) - let googlePaySessionObj = React.useMemo1(() => { - switch props.sessionObj { - | Some(val) => val - | None => { - walletName: NONE, - token: "", - sessionId: "", - allowed_payment_methods: [], - transaction_info: Js.Json.null, - merchant_info: Js.Json.null, - } - } - }, [props.sessionObj]) - let googlePayPaymentMethodType = switch PaymentMethodsRecord.getPaymentMethodTypeFromList( ~list=props.list, ~paymentMethod="wallet", @@ -66,15 +47,6 @@ let default = (props: props) => { ? props.list->PaymentUtils.getConnectors(Wallets(Gpay(SDK))) : props.list->PaymentUtils.getConnectors(Wallets(Gpay(Redirect))) - let getGoogleIsReadyToPayRequest = () => { - assign( - Js.Dict.empty()->Js.Json.object_, - baseRequest->toJson, - { - "allowedPaymentMethods": googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase, - }->toJson, - ) - } let processPayment = (body: array<(string, Js.Json.t)>) => { intent( ~bodyArr=body, @@ -111,17 +83,6 @@ let default = (props: props) => { | GooglePay(val) => val | _ => 48 } - let getGooglePaymentDataRequest = () => { - let paymentDataRequest = assign2(Js.Dict.empty()->Js.Json.object_, baseRequest->toJson) - - paymentDataRequest.allowedPaymentMethods = - googlePaySessionObj.allowed_payment_methods->arrayJsonToCamelCase - - paymentDataRequest.transactionInfo = - googlePaySessionObj.transaction_info->transformKeys(CamelCase) - paymentDataRequest.merchantInfo = googlePaySessionObj.merchant_info->transformKeys(CamelCase) - paymentDataRequest - } let getGooglePaymentsClient = () => { google({"environment": GlobalVars.isProd ? "PRODUCTION" : "TEST"}->toJson) @@ -137,7 +98,6 @@ let default = (props: props) => { (), ) } - let paymentDataRequest = getGooglePaymentDataRequest() let onGooglePaymentButtonClicked = () => { loggerState.setLogInfo( @@ -158,21 +118,7 @@ let default = (props: props) => { ->Belt.Option.getWithDefault(false) if isDelayedSessionToken { - loggerState.setLogInfo( - ~logType=DEBUG, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~value="isDelayedSessionToken", - (), - ) let bodyDict = PaymentBody.gPayThirdPartySdkBody(~connectors) - loggerState.setLogInfo( - ~logType=DEBUG, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~value=bodyDict->toJson->Js.Json.stringify, - (), - ) processPayment(bodyDict) } else { handlePostMessage([ @@ -180,23 +126,9 @@ let default = (props: props) => { ("param", "paymentloader"->Js.Json.string), ("iframeId", iframeId->Js.Json.string), ]) - loggerState.setLogInfo( - ~eventName=GOOGLE_PAY_FLOW, - ~logType=DEBUG, - ~paymentMethod="GOOGLE_PAY", - ~value=paymentDataRequest->toJson->Js.Json.stringify, - (), - ) options.readOnly ? () : handlePostMessage([("GpayClicked", true->Js.Json.boolean)]) } } else { - loggerState.setLogInfo( - ~logType=DEBUG, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~value="not isInvokeSDKFlow", - (), - ) let bodyDict = PaymentBody.gpayRedirectBody(~connectors) processPayment(bodyDict) } @@ -222,36 +154,12 @@ let default = (props: props) => { gpayWrapper.innerHTML = "" gpayWrapper.appendChild(. button) } - - let onGooglePayLoaded = () => { - open Promise - let paymentsClient = getGooglePaymentsClient() - - if paymentExperience == PaymentMethodsRecord.RedirectToURL || isGooglePayThirdPartyFlow { + React.useEffect3(() => { + if status == "ready" && isGPayReady { addGooglePayButton() - } else if isInvokeSDKFlow { - paymentsClient.isReadyToPay(. getGoogleIsReadyToPayRequest()) - ->then(_ => { - addGooglePayButton() - resolve() - }) - ->catch(_err => { - resolve() - }) - ->ignore - } - } - - React.useEffect2(() => { - if status == "ready" { - try { - onGooglePayLoaded() - } catch { - | _err => Utils.logInfo(Js.log("Error loading Gpay")) - } } None - }, (status, props)) + }, (status, props, isGPayReady)) React.useEffect0(() => { let handleGooglePayMessages = (ev: Window.event) => { @@ -282,8 +190,4 @@ let default = (props: props) => { id="google-pay-button" className={`w-full flex flex-row justify-center rounded-md`} /> - // let handleClick = _e => { - // handlePostMessage([("GpayClicked", true->Js.Json.boolean)]) - // } - // } diff --git a/src/Types/GooglePayType.res b/src/Types/GooglePayType.res index 4fbe0c041..6620ef8f0 100644 --- a/src/Types/GooglePayType.res +++ b/src/Types/GooglePayType.res @@ -24,7 +24,7 @@ type document @val external document: document = "document" @send external getElementById: (document, string) => element = "getElementById" type client = { - isReadyToPay: (. Js.Json.t) => Js.Promise.t, + isReadyToPay: (. Js.Json.t) => Js.Promise.t, createButton: (. Js.Json.t) => Dom.element, loadPaymentData: (. Js.Json.t) => Js.Promise.t, } diff --git a/src/Utilities/RecoilAtoms.res b/src/Utilities/RecoilAtoms.res index 05027af65..e13c6a96f 100644 --- a/src/Utilities/RecoilAtoms.res +++ b/src/Utilities/RecoilAtoms.res @@ -33,6 +33,7 @@ let userPhoneNumber = Recoil.atom(. errorString: "", }, ) +let isGooglePayReady = Recoil.atom(. "isGooglePayReady", false) let userCountry = Recoil.atom(. "userCountry", "") let userBank = Recoil.atom(. "userBank", "") let userAddressline1 = Recoil.atom(. "userAddressline1", defaultFieldValues) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 3a68ecb51..933daf97d 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -592,13 +592,13 @@ let make = ( baseRequest->toJson, ) - // let payRequest = GooglePayType.assign( - // Js.Dict.empty()->Js.Json.object_, - // baseRequest->toJson, - // { - // "allowedPaymentMethods": gpayobj.allowed_payment_methods->arrayJsonToCamelCase, - // }->toJson, - // ) + let payRequest = GooglePayType.assign( + Js.Dict.empty()->Js.Json.object_, + baseRequest->toJson, + { + "allowedPaymentMethods": gpayobj.allowed_payment_methods->arrayJsonToCamelCase, + }->toJson, + ) paymentDataRequest.allowedPaymentMethods = gpayobj.allowed_payment_methods->arrayJsonToCamelCase paymentDataRequest.transactionInfo = gpayobj.transaction_info->transformKeys(CamelCase) @@ -610,65 +610,93 @@ let make = ( : "TEST", }->toJson, ) - - let onGpayclick = () => { - Js.log("ENTERED CLicked") - Js.Global.setTimeout(() => { - gPayClient.loadPaymentData(. paymentDataRequest->toJson) - ->then(json => { - logger.setLogInfo( - ~value=json->toJson->Js.Json.stringify, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, - (), - ) - let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - resolve() - }) - ->catch(err => { - logger.setLogInfo( - ~value=err->toJson->Js.Json.stringify, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, - (), - ) - - let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray - mountedIframeRef->Window.iframePostMessage(msg) - resolve() - }) - ->ignore - }, 1)->ignore - } + // let onGpayclick = () => { + // Js.log("ENTERED CLicked") + // // Js.Global.setTimeout(() => { + // Js.Promise.make((~resolve, ~reject as _) => { + // resolve(. gPayClient.loadPaymentData(. paymentDataRequest->toJson)) + // }) + // ->then(json => { + // logger.setLogInfo( + // ~value=json->toJson->Js.Json.stringify, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~logType=DEBUG, + // (), + // ) + // Js.log2("RES", json->toJson) + // let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray + // mountedIframeRef->Window.iframePostMessage(msg) + // Promise.resolve() + // }) + // ->catch(err => { + // Js.log2("ERROR", err->toJson) + // logger.setLogInfo( + // ~value=err->toJson->Js.Json.stringify, + // ~eventName=GOOGLE_PAY_FLOW, + // ~paymentMethod="GOOGLE_PAY", + // ~logType=DEBUG, + // (), + // ) + + // let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray + // mountedIframeRef->Window.iframePostMessage(msg) + // Promise.reject(err) + // }) + // ->ignore + + // // }, 0)->ignore + // } + gPayClient.isReadyToPay(. payRequest) + ->then(res => { + let dict = res->getDictFromJson + let isReadyToPay = getBool(dict, "result", false) + let msg = [("isReadyToPay", isReadyToPay->Js.Json.boolean)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->catch(err => { + reject(err) + }) + ->ignore let handleGooglePayMessages = (event: Types.event) => { - Js.log("ENTERING HANDLE FUNCTION") let evJson = event.data->eventToJson let gpayClicked = evJson ->OrcaUtils.getOptionalJsonFromJson("GpayClicked") ->OrcaUtils.getBoolfromjson(false) - // try { - // gPayClient.isReadyToPay(. payRequest) - // ->then(_ => { - // Js.log("READY") - // resolve() - // }) - // ->catch(_err => { - // resolve() - // }) - // ->ignore - // } catch { - // | err => Js.log2("ERROR", err) - // } if gpayClicked { - Js.log("ENTERING CLicked") - onGpayclick() - Js.log("FINISHED") + Js.Global.setTimeout(() => { + gPayClient.loadPaymentData(. paymentDataRequest->toJson) + ->then(json => { + logger.setLogInfo( + ~value=json->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + resolve() + }) + ->catch(err => { + logger.setLogInfo( + ~value=err->toJson->Js.Json.stringify, + ~eventName=GOOGLE_PAY_FLOW, + ~paymentMethod="GOOGLE_PAY", + ~logType=DEBUG, + (), + ) + + let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + reject(err) + }) + ->ignore + }, 0)->ignore } } addSmartEventListener("message", handleGooglePayMessages, "onApplePayMessages") diff --git a/webpack.common.js b/webpack.common.js index 7a4714f61..346800dfe 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -96,13 +96,13 @@ module.exports = (publicPath = "auto") => { // new webpack.HTMLInjectPlugin({ // publicPath: JSON.stringify(repoVersion), // }), - // sentryWebpackPlugin({ - // org: "sentry", - // project: "hyperswitch-react-sdk", - // authToken: - // "23d916c8cfa647c6b977ec2e276f4c95b01ea36e311b4c1cb82ac2c65570b95d", - // url: "https://sentry.internal.svc.k8s.jarvis.mum.juspay.net/", - // }), + sentryWebpackPlugin({ + org: "sentry", + project: "hyperswitch-react-sdk", + authToken: + "23d916c8cfa647c6b977ec2e276f4c95b01ea36e311b4c1cb82ac2c65570b95d", + url: "https://sentry.internal.svc.k8s.jarvis.mum.juspay.net/", + }), ], module: { rules: [ From 437d97113ee54d7cc509a6985c45f5d598a6aedc Mon Sep 17 00:00:00 2001 From: Praful Koppalkar Date: Mon, 25 Sep 2023 15:08:20 +0530 Subject: [PATCH 6/9] removed comments --- src/orca-loader/Elements.res | 39 +- src/orca-loader/LoaderPaymentElement.res | 3 +- src/orca-loader/newfile.txt | 827 ----------------------- 3 files changed, 2 insertions(+), 867 deletions(-) delete mode 100644 src/orca-loader/newfile.txt diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 933daf97d..59f403dc4 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -5,7 +5,6 @@ open Utils open EventListenerManager open ApplePayTypes -@val external window: {..} = "window" external objToJson: {..} => Js.Json.t = "%identity" external eventToJson: Types.eventData => Js.Json.t = "%identity" @@ -610,43 +609,7 @@ let make = ( : "TEST", }->toJson, ) - // let onGpayclick = () => { - // Js.log("ENTERED CLicked") - // // Js.Global.setTimeout(() => { - // Js.Promise.make((~resolve, ~reject as _) => { - // resolve(. gPayClient.loadPaymentData(. paymentDataRequest->toJson)) - // }) - // ->then(json => { - // logger.setLogInfo( - // ~value=json->toJson->Js.Json.stringify, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~logType=DEBUG, - // (), - // ) - // Js.log2("RES", json->toJson) - // let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray - // mountedIframeRef->Window.iframePostMessage(msg) - // Promise.resolve() - // }) - // ->catch(err => { - // Js.log2("ERROR", err->toJson) - // logger.setLogInfo( - // ~value=err->toJson->Js.Json.stringify, - // ~eventName=GOOGLE_PAY_FLOW, - // ~paymentMethod="GOOGLE_PAY", - // ~logType=DEBUG, - // (), - // ) - - // let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray - // mountedIframeRef->Window.iframePostMessage(msg) - // Promise.reject(err) - // }) - // ->ignore - - // // }, 0)->ignore - // } + gPayClient.isReadyToPay(. payRequest) ->then(res => { let dict = res->getDictFromJson diff --git a/src/orca-loader/LoaderPaymentElement.res b/src/orca-loader/LoaderPaymentElement.res index 707161b03..df2a63772 100644 --- a/src/orca-loader/LoaderPaymentElement.res +++ b/src/orca-loader/LoaderPaymentElement.res @@ -327,8 +327,7 @@ let make = (componentType, options, setIframeRef, iframeRef, mountPostMessage) = let classesBase = optionsDict->OrcaUtils.getClasses("base") switch oElement->Js.Nullable.toOption { | Some(elem) => { - let iframeDiv = ` -
+ let iframeDiv = `
-
- ` +
` elem->Window.innerHTML(iframeDiv) setPaymentIframeRef( Window.querySelector(`#orca-payment-element-iframeRef-${localSelectorString}`),