diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 000c597d9..400a078af 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -12,7 +12,7 @@ let make = ( ~walletOptions: array, ) => { let (requiredFieldsBody, setRequiredFieldsBody) = React.useState(_ => Dict.make()) - let (loggerState, _setLoggerState) = Recoil.useRecoilState(loggerAtom) + let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom) let {iframeId} = Recoil.useRecoilValueFromAtom(keys) let {publishableKey, sdkHandleOneClickConfirmPayment} = Recoil.useRecoilValueFromAtom(keys) let {localeString} = Recoil.useRecoilValueFromAtom(configAtom) @@ -149,6 +149,13 @@ let make = ( makeOneClickHandlerPromise(sdkHandleOneClickConfirmPayment)->then(result => { let result = result->JSON.Decode.bool->Option.getOr(false) if result { + let value = "Payment Data Filled: New Payment Method" + loggerState.setLogInfo( + ~value, + ~eventName=PAYMENT_DATA_FILLED, + ~paymentMethod="GOOGLE_PAY", + (), + ) if isInvokeSDKFlow { if isDelayedSessionToken { handlePostMessage([ @@ -170,13 +177,6 @@ let make = ( let bodyDict = PaymentBody.gpayRedirectBody(~connectors) processPayment(bodyDict) } - let value = "Payment Data Filled: New Payment Method" - loggerState.setLogInfo( - ~value, - ~eventName=PAYMENT_DATA_FILLED, - ~paymentMethod="GOOGLE_PAY", - (), - ) } resolve() }) diff --git a/src/Utilities/LoggerUtils.res b/src/Utilities/LoggerUtils.res index 3e7c0737c..7787d0605 100644 --- a/src/Utilities/LoggerUtils.res +++ b/src/Utilities/LoggerUtils.res @@ -9,6 +9,7 @@ let logApi = ( ~optLogger: option, ~logType: OrcaLogger.logType=INFO, ~logCategory: OrcaLogger.logCategory=API, + ~isPaymentSession: bool=false, (), ) => { let (value, internalMetadata) = switch apiLogType { @@ -44,6 +45,7 @@ let logApi = ( ~logType, ~logCategory, ~apiLogType, + ~isPaymentSession, (), ) | None => () @@ -51,14 +53,7 @@ let logApi = ( } let logInputChangeInfo = (text, logger: OrcaLogger.loggerMake) => { - logger.setLogInfo( - ~value=[("inputChange", text->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object - ->JSON.stringify, - ~eventName=INPUT_FIELD_CHANGED, - (), - ) + logger.setLogInfo(~value=text, ~eventName=INPUT_FIELD_CHANGED, ()) } let handleLogging = ( diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 06a0c310b..83937b42d 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -287,6 +287,7 @@ let rec intentCall = ( ~eventName=initEventName, ~logType=INFO, ~logCategory=API, + ~isPaymentSession, (), ) let handleOpenUrl = url => { @@ -341,6 +342,7 @@ let rec intentCall = ( ~eventName, ~logType=ERROR, ~logCategory=API, + ~isPaymentSession, (), ) @@ -378,6 +380,7 @@ let rec intentCall = ( ~eventName, ~logType=ERROR, ~logCategory=API, + ~isPaymentSession, (), ) if counter >= 5 { @@ -437,7 +440,15 @@ let rec intentCall = ( ->then(data => { Promise.make( (resolve, _) => { - logApi(~optLogger, ~url=uri, ~statusCode, ~apiLogType=Response, ~eventName, ()) + logApi( + ~optLogger, + ~url=uri, + ~statusCode, + ~apiLogType=Response, + ~eventName, + ~isPaymentSession, + (), + ) let intent = PaymentConfirmTypes.itemToObjMapper(data->getDictFromJson) let paymentMethod = switch paymentType { | Card => "CARD" @@ -713,6 +724,7 @@ let rec intentCall = ( ~data=exceptionMessage, ~logType=ERROR, ~logCategory=API, + ~isPaymentSession, (), ) if counter >= 5 { @@ -1162,6 +1174,7 @@ let fetchCustomerDetails = ( ~endpoint, ~optLogger, ~switchToCustomPod, + ~isPaymentSession=false, ) => { open Promise let headers = [("Content-Type", "application/json"), ("api-key", publishableKey)] @@ -1173,6 +1186,7 @@ let fetchCustomerDetails = ( ~eventName=CUSTOMER_PAYMENT_METHODS_CALL_INIT, ~logType=INFO, ~logCategory=API, + ~isPaymentSession, (), ) fetchApi( @@ -1196,6 +1210,7 @@ let fetchCustomerDetails = ( ~eventName=CUSTOMER_PAYMENT_METHODS_CALL, ~logType=ERROR, ~logCategory=API, + ~isPaymentSession, (), ) JSON.Encode.null->resolve @@ -1209,6 +1224,7 @@ let fetchCustomerDetails = ( ~eventName=CUSTOMER_PAYMENT_METHODS_CALL, ~logType=INFO, ~logCategory=API, + ~isPaymentSession, (), ) res->Fetch.Response.json @@ -1224,6 +1240,7 @@ let fetchCustomerDetails = ( ~logType=ERROR, ~logCategory=API, ~data=exceptionMessage, + ~isPaymentSession, (), ) JSON.Encode.null->resolve diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 75aaac4fa..d093d55a5 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -715,13 +715,6 @@ let make = ( gPayClient.loadPaymentData(paymentDataRequest->anyTypeToJson) ->then( json => { - logger.setLogInfo( - ~value=json->anyTypeToJson->JSON.stringify, - ~eventName=GOOGLE_PAY_FLOW, - ~paymentMethod="GOOGLE_PAY", - ~logType=DEBUG, - (), - ) let msg = [("gpayResponse", json->anyTypeToJson)]->Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) resolve() diff --git a/src/orca-loader/PaymentSessionMethods.res b/src/orca-loader/PaymentSessionMethods.res index 78512e758..8e5ab84a0 100644 --- a/src/orca-loader/PaymentSessionMethods.res +++ b/src/orca-loader/PaymentSessionMethods.res @@ -14,6 +14,7 @@ let getCustomerSavedPaymentMethods = ( ~endpoint, ~switchToCustomPod, ~optLogger=Some(logger), + ~isPaymentSession=true, ) ->then(customerDetails => { let customerPaymentMethods = diff --git a/src/orca-log-catcher/OrcaLogger.res b/src/orca-log-catcher/OrcaLogger.res index 32df8bc84..6517c1b09 100644 --- a/src/orca-log-catcher/OrcaLogger.res +++ b/src/orca-log-catcher/OrcaLogger.res @@ -138,7 +138,7 @@ let convertToScreamingSnakeCase = text => { } type maskableDetails = Email | CardDetails -type source = Loader | Elements +type source = Loader | Elements | Headless let logInfo = log => { Window.isProd ? () : log } @@ -194,6 +194,7 @@ type loggerMake = { ~logCategory: logCategory=?, ~paymentMethod: string=?, ~apiLogType: apiLogType=?, + ~isPaymentSession: bool=?, unit, ) => unit, setLogInitiated: unit => unit, @@ -229,6 +230,7 @@ let defaultLoggerConfig = { ~logCategory as _=?, ~paymentMethod as _=?, ~apiLogType as _=?, + ~isPaymentSession as _=?, (), ) => (), setLogInfo: ( @@ -292,26 +294,6 @@ let logFileToObj = logFile => { ->JSON.Encode.object } -/* SAMPLE LOG FILE - - API CALL - - log_type : "info", - session_id : "11bf5b37-e0b8-42e0-8dcf-dc8c4aefc000" - service : "orca-elements" - version : "92e923dj" - timestamp : "2022-08-03 06:37:37.611" - category : "api" - environment : "sandbox" - tag : "outgoing_request" - value : { url: payments/ request_headers: "" response_headers: "" request: "{}" response: "{}" latency: 200 ms response_code: 200 } - payment_id: "py_09923i23n20912ndoied" - payment_attempt_id: "pa_jnsdfri3383njfin23i" - merchant_id: "merchant_name" - - -*/ - let getRefFromOption = val => { let innerValue = val->Option.getOr("") ref(innerValue) @@ -320,6 +302,7 @@ let getSourceString = source => { switch source { | Loader => "orca-loader" | Elements => "orca-element" + | Headless => "headless" } } @@ -640,6 +623,7 @@ let make = ( ~logCategory=API, ~paymentMethod="", ~apiLogType=Request, + ~isPaymentSession=false, (), ) => { let eventNameStr = eventName->eventNameToStrMapper @@ -651,7 +635,7 @@ let make = ( logType, timestamp: localTimestamp, sessionId: sessionId.contents, - source: sourceString, + source: isPaymentSession ? getSourceString(Headless) : sourceString, version: GlobalVars.repoVersion, value: switch value { | ArrayType(a) => a->Dict.fromArray->JSON.Encode.object->JSON.stringify