From 1f754b6f4023709752ef892c0e2861d34aa4f2fe Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Wed, 24 Apr 2024 19:36:01 +0530 Subject: [PATCH] fix: added breakpoints to debug --- src/Payments/ApplePay.res | 3 ++- src/orca-loader/Elements.res | 49 ++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/Payments/ApplePay.res b/src/Payments/ApplePay.res index a3a985a23..c10026aa5 100644 --- a/src/Payments/ApplePay.res +++ b/src/Payments/ApplePay.res @@ -309,7 +309,8 @@ let make = ( postFailedSubmitResponse(~errortype="server_error", ~message="Something went wrong") } } else if dict->Dict.get("applePaySyncPayment")->Option.isSome { - syncPayment() + () + // syncPayment(breakpoint) } } catch { | _ => Utils.logInfo(Console.log("Error in parsing Apple Pay Data")) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 37716fc43..6c206410c 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -4,6 +4,7 @@ open Identity open Utils open EventListenerManager open ApplePayTypes +@send external alert: ('t, string) => unit = "alert" type trustPayFunctions = { finishApplePaymentV2: (string, paymentRequestData) => Promise.t, @@ -462,7 +463,6 @@ let make = ( addSmartEventListener("message", handleApplePayMounted, "onApplePayMount") addSmartEventListener("message", handlePollStatusMessage, "onPollStatusMsg") addSmartEventListener("message", handleGooglePayThirdPartyFlow, "onGooglePayThirdParty") - Window.removeEventListener("message", handleApplePayMessages.contents) let fetchSessionTokens = mountedIframeRef => { let handleSessionTokensLoaded = (event: Types.event) => { @@ -536,6 +536,11 @@ let make = ( ->JSON.Decode.bool ->Belt.Option.getWithDefault(false) + Window.window->alert( + "isDelayedSessionToken: " ++ + isDelayedSessionToken->anyTypeToJson->JSON.stringify, + ) + if isDelayedSessionToken { logger.setLogInfo( ~value="Delayed Session Token Flow", @@ -544,19 +549,28 @@ let make = ( (), ) - let applePayPresent = + let applePaySessionTokenData = dict ->Dict.get("applePayPresent") ->Belt.Option.flatMap(JSON.Decode.object) ->Belt.Option.getWithDefault(Dict.make()) + Window.window->alert( + "applePaySessionTokenData: " ++ + applePaySessionTokenData->anyTypeToJson->JSON.stringify, + ) + let connector = - applePayPresent + applePaySessionTokenData ->Dict.get("connector") ->Belt.Option.getWithDefault(JSON.Encode.null) ->JSON.Decode.string ->Belt.Option.getWithDefault("") + Window.window->alert( + "connector: " ++ connector->anyTypeToJson->JSON.stringify, + ) + switch connector { | "trustpay" => logger.setLogInfo( @@ -566,7 +580,7 @@ let make = ( (), ) let secrets = - applePayPresent + applePaySessionTokenData ->Dict.get("session_token_data") ->Belt.Option.getWithDefault(JSON.Encode.null) ->JSON.Decode.object @@ -574,13 +588,22 @@ let make = ( ->Dict.get("secrets") ->Belt.Option.getWithDefault(JSON.Encode.null) + Window.window->alert( + "secrets: " ++ secrets->anyTypeToJson->JSON.stringify, + ) + let paymentRequest = - applePayPresent + applePaySessionTokenData ->Dict.get("payment_request_data") ->Belt.Option.flatMap(JSON.Decode.object) ->Belt.Option.getWithDefault(Dict.make()) ->ApplePayTypes.jsonToPaymentRequestDataType + Window.window->alert( + "paymentRequest: " ++ + paymentRequest->anyTypeToJson->JSON.stringify, + ) + let payment = secrets ->JSON.Decode.object @@ -590,10 +613,17 @@ let make = ( ->JSON.Decode.string ->Belt.Option.getWithDefault("") + Window.window->alert( + "payment: " ++ payment->anyTypeToJson->JSON.stringify, + ) + try { let trustpay = trustPayApi(secrets) trustpay.finishApplePaymentV2(payment, paymentRequest) ->then(res => { + Window.window->alert( + "res: " ++ res->anyTypeToJson->JSON.stringify, + ) logger.setLogInfo( ~value="TrustPay ApplePay Success Response", ~internalMetadata=res->JSON.stringify, @@ -604,6 +634,7 @@ let make = ( let msg = [ ("applePaySyncPayment", true->JSON.Encode.bool), + ("breakpoint", "1"->JSON.Encode.string), ]->Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) logger.setLogInfo( @@ -617,6 +648,9 @@ let make = ( ->catch(err => { let exceptionMessage = err->Utils.formatException->JSON.stringify + Window.window->alert( + "err: " ++ err->anyTypeToJson->JSON.stringify, + ) logger.setLogInfo( ~eventName=APPLE_PAY_FLOW, ~paymentMethod="APPLE_PAY", @@ -626,6 +660,7 @@ let make = ( let msg = [ ("applePaySyncPayment", true->JSON.Encode.bool), + ("breakpoint", "2"->JSON.Encode.string), ]->Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) resolve() @@ -639,9 +674,13 @@ let make = ( ~paymentMethod="APPLE_PAY", (), ) + Window.window->alert( + "exn: " ++ exn->Utils.formatException->JSON.stringify, + ) let msg = [ ("applePaySyncPayment", true->JSON.Encode.bool), + ("breakpoint", "3"->JSON.Encode.string), ]->Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) }