From 6671239b06fa2b791d07ef0de6e4ed893c392f0f Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Mon, 18 Sep 2023 11:30:08 +0530 Subject: [PATCH 1/2] Refactored API Error logs and Google Pay logs --- src/Payments/GPay.res | 41 +++----------------------------- src/Utilities/PaymentHelpers.res | 24 ++++++++----------- src/Utilities/Utils.res | 18 ++++++++++++++ src/orca-loader/Elements.res | 33 +++++++++++++------------ 4 files changed, 47 insertions(+), 69 deletions(-) diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 0ee319eb4..0bd8f8b5e 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -167,63 +167,28 @@ let default = (props: props) => { (), ) let bodyDict = PaymentBody.gPayThirdPartySdkBody(~connectors) + processPayment(bodyDict) + } else { loggerState.setLogInfo( ~logType=DEBUG, ~eventName=GOOGLE_PAY_FLOW, ~paymentMethod="GOOGLE_PAY", - ~value=bodyDict->toJson->Js.Json.stringify, + ~value="not isDelayedSessionToken", (), ) - processPayment(bodyDict) - } else { handlePostMessage([ ("fullscreen", true->Js.Json.boolean), ("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, - ~paymentMethod="GOOGLE_PAY", - ~value=paymentDataRequest->toJson->Js.Json.stringify, - (), - ) options.readOnly ? () : handlePostMessage([ ("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/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index b770dd946..d8bdb36e1 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -175,14 +175,13 @@ let intentCall = ( resolve() }) ->catch(err => { - let exceptionJson = err->toJson - + let exceptionMessage = err->Utils.formatException logApi( ~optLogger, ~url=uri, ~statusCode, ~type_="no_response", - ~data=exceptionJson, + ~data=exceptionMessage, ~eventName, ~logType=ERROR, ~logCategory=API, @@ -353,13 +352,13 @@ let intentCall = ( let url = urlSearch(confirmParam.return_url) url.searchParams.set(. "payment_intent_client_secret", clientSecret) url.searchParams.set(. "status", "failed") - let exceptionJson = err->toJson + let exceptionMessage = err->Utils.formatException logApi( ~optLogger, ~url=uri, ~eventName, ~type_="no_response", - ~data=exceptionJson, + ~data=exceptionMessage, ~logType=ERROR, ~logCategory=API, (), @@ -663,8 +662,7 @@ let useSessions = ( json->resolve }) ->catch(err => { - let exceptionJson = err->toJson - + let exceptionMessage = err->Utils.formatException logApi( ~optLogger, ~url=uri, @@ -672,7 +670,7 @@ let useSessions = ( ~eventName=SESSIONS_CALL, ~logType=ERROR, ~logCategory=API, - ~data=exceptionJson, + ~data=exceptionMessage, (), ) Js.Dict.empty()->Js.Json.object_->resolve @@ -733,8 +731,7 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { json->resolve }) ->catch(err => { - let exceptionJson = err->toJson - + let exceptionMessage = err->Utils.formatException logApi( ~optLogger=Some(logger), ~url=uri, @@ -742,7 +739,7 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { ~eventName=PAYMENT_METHODS_CALL, ~logType=ERROR, ~logCategory=API, - ~data=exceptionJson, + ~data=exceptionMessage, (), ) Js.Dict.empty()->Js.Json.object_->resolve @@ -800,8 +797,7 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => { }) ->then(res => resolve(res)) ->catch(err => { - let exceptionJson = err->toJson - + let exceptionMessage = err->Utils.formatException logApi( ~optLogger, ~url=uri, @@ -809,7 +805,7 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => { ~eventName=CUSTOMER_PAYMENT_METHODS_CALL, ~logType=ERROR, ~logCategory=API, - ~data=exceptionJson, + ~data=exceptionMessage, (), ) Js.Dict.empty()->Js.Json.object_->resolve diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index 58539257a..b9aba4f6b 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -733,3 +733,21 @@ let delay = timeOut => { }, timeOut)->ignore }) } + +let formatException = exc => { + let exceptionMessage = exc->toJson->getDictFromJson + let exceptionMessage = + [ + ( + "exception_id", + exceptionMessage->Js.Dict.get("RE_EXN_ID")->Belt.Option.getWithDefault(Js.Json.null), + ), + ( + "exception_message", + exceptionMessage->Js.Dict.get("_1")->Belt.Option.getWithDefault(Js.Json.null), + ), + ] + ->Js.Dict.fromArray + ->Js.Json.object_ + exceptionMessage +} diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 10e56d615..ac28a0511 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -305,7 +305,7 @@ let make = ( resolve() }) ->catch(err => { - let exceptionMessage = err->toJson->Js.Json.stringify + let exceptionMessage = err->Utils.formatException->Js.Json.stringify logger.setLogInfo( ~value=exceptionMessage, ~eventName=GOOGLE_PAY_FLOW, @@ -320,11 +320,14 @@ let make = ( }) ->ignore } catch { - | _ => { + | err => { + let exceptionMessage = err->Utils.formatException->Js.Json.stringify logger.setLogInfo( - ~value="TrustPay API initialising error", + ~value=exceptionMessage, ~eventName=GOOGLE_PAY_FLOW, ~paymentMethod="GOOGLE_PAY", + ~logType=ERROR, + ~logCategory=USER_ERROR, (), ) let msg = [("googlePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray @@ -353,23 +356,18 @@ let make = ( 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 => { + let exceptionMessage = err->Utils.formatException->Js.Json.stringify logger.setLogInfo( - ~value=err->toJson->Js.Json.stringify, + ~value=exceptionMessage, ~eventName=GOOGLE_PAY_FLOW, ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, + ~logType=ERROR, + ~logCategory=USER_ERROR, (), ) let msg = [("gpayResponse", err->toJson)]->Js.Dict.fromArray @@ -379,14 +377,16 @@ let make = ( ->ignore } catch { | err => { + let exceptionMessage = err->Utils.formatException->Js.Json.stringify logger.setLogInfo( - ~value=err->toJson->Js.Json.stringify, + ~value=exceptionMessage, ~eventName=GOOGLE_PAY_FLOW, ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, + ~logType=ERROR, + ~logCategory=USER_ERROR, (), ) - let msg = [("gpayErorr", err->toJson)]->Js.Dict.fromArray + let msg = [("gpayError", err->toJson)]->Js.Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) } } @@ -518,8 +518,7 @@ let make = ( resolve() }) ->catch(err => { - let exceptionMessage = err->toJson->Js.Json.stringify - + let exceptionMessage = err->Utils.formatException->Js.Json.stringify logger.setLogInfo( ~eventName=APPLE_PAY_FLOW, ~paymentMethod="APPLE_PAY", From 307bb6a5689908a9db4be0f86c74d2cfbfa2ac52 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Thu, 21 Sep 2023 17:35:50 +0530 Subject: [PATCH 2/2] Added logs for payment data filled --- src/Payments/ApplePay.res | 6 ++++++ src/Payments/GPay.res | 6 ++++++ src/orca-loader/Elements.res | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/Payments/ApplePay.res b/src/Payments/ApplePay.res index 27db94faa..e3e22e5b6 100644 --- a/src/Payments/ApplePay.res +++ b/src/Payments/ApplePay.res @@ -244,6 +244,12 @@ let default = (props: props) => { let bodyDict = PaymentBody.applePayRedirectBody(~connectors) processPayment(bodyDict) } + loggerState.setLogInfo( + ~value="", + ~eventName=PAYMENT_DATA_FILLED, + ~paymentMethod="APPLE_PAY", + (), + ) } React.useEffect1(() => { diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 0bd8f8b5e..5810b3e9c 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -201,6 +201,12 @@ let default = (props: props) => { let bodyDict = PaymentBody.gpayRedirectBody(~connectors) processPayment(bodyDict) } + loggerState.setLogInfo( + ~value="", + ~eventName=PAYMENT_DATA_FILLED, + ~paymentMethod="GOOGLE_PAY", + (), + ) } let buttonStyle = { let obj = { diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index ac28a0511..10de1c923 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -358,6 +358,12 @@ let make = ( ->then(json => { let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) + logger.setLogInfo( + ~value="", + ~eventName=PAYMENT_DATA_FILLED, + ~paymentMethod="GOOGLE_PAY", + (), + ) resolve() }) ->catch(err => { @@ -515,6 +521,12 @@ let make = ( let msg = [("applePaySyncPayment", true->Js.Json.boolean)]->Js.Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) + logger.setLogInfo( + ~value="", + ~eventName=PAYMENT_DATA_FILLED, + ~paymentMethod="APPLE_PAY", + (), + ) resolve() }) ->catch(err => {