From fb2f960590799a8ad6c8949d106dff3744a246ba Mon Sep 17 00:00:00 2001 From: Arush Date: Tue, 29 Aug 2023 18:49:06 +0530 Subject: [PATCH 1/9] Added Logs for the API Call Failure --- src/Payments/QRCodeDisplay.res | 5 +- src/Utilities/PaymentHelpers.res | 98 ++++++++++++++++++++++++++++---- src/orca-loader/HyperLoader.res | 29 +++++++++- 3 files changed, 118 insertions(+), 14 deletions(-) diff --git a/src/Payments/QRCodeDisplay.res b/src/Payments/QRCodeDisplay.res index 453f3cb27..faf769cf8 100644 --- a/src/Payments/QRCodeDisplay.res +++ b/src/Payments/QRCodeDisplay.res @@ -15,6 +15,7 @@ let make = () => { let (return_url, setReturnUrl) = React.useState(_ => "") let (clientSecret, setClientSecret) = React.useState(_ => "") let (headers, setHeaders) = React.useState(_ => []) + let logger = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom) React.useEffect0(() => { handlePostMessage([("iframeMountedCallback", true->Js.Json.boolean)]) @@ -49,7 +50,7 @@ let make = () => { // } open Promise setHeaders(_ => headers->Js.Dict.entries) - PaymentHelpers.pollRetrievePaymentIntent(paymentIntentId, headers->Js.Dict.entries) + PaymentHelpers.pollRetrievePaymentIntent(paymentIntentId, headers->Js.Dict.entries, ~optLogger=Some(logger)) ->then(res => { Modal.close(setOpenModal) postSubmitResponse(~jsonData=res, ~url=return_url) @@ -77,7 +78,7 @@ let make = () => { let closeModal = () => { open Promise - PaymentHelpers.retrievePaymentIntent(clientSecret, headers) + PaymentHelpers.retrievePaymentIntent(clientSecret, headers, ~optLogger=Some(logger)) ->then(json => { let dict = json->Js.Json.decodeObject->Belt.Option.getWithDefault(Js.Dict.empty()) let status = dict->getString("status", "") diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 56c2aec40..35a98ef0b 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -13,7 +13,7 @@ type payment = Card | BankTransfer | BankDebits | KlarnaRedirect | Gpay | Applep let closePaymentLoaderIfAny = () => Utils.handlePostMessage([("fullscreen", false->Js.Json.boolean)]) -let retrievePaymentIntent = (clientSecret, headers) => { +let retrievePaymentIntent = (clientSecret, headers, ~optLogger) => { open Promise let fetchApi = CommonHooks.useApiFetcher() let paymentIntentID = Js.String2.split(clientSecret, "_secret_")[0] @@ -22,6 +22,26 @@ let retrievePaymentIntent = (clientSecret, headers) => { //let headers = [("Accept", "application/json"), ("api-key", publishableKey)] fetchApi(uri, ~method_=Fetch.Get, ~headers=headers->addCustomPodHeader, ()) ->then(res => { + let statusCode = res->Fetch.Response.status->string_of_int + if statusCode->Js.String2.charAt(0) !== "2" { + res + ->Fetch.Response.json + ->then(data => { + logApi( + ~optLogger, + ~url=uri, + ~data, + ~statusCode, + ~type_="response", + ~eventName=API_CALL_FAILED, + ~logType=ERROR, + ~logCategory=API, + (), + ) + resolve() + }) + ->ignore + } res->Fetch.Response.json }) ->then(res => resolve(res)) @@ -31,9 +51,9 @@ let retrievePaymentIntent = (clientSecret, headers) => { }) } -let rec pollRetrievePaymentIntent = (clientSecret, headers) => { +let rec pollRetrievePaymentIntent = (clientSecret, headers, ~optLogger) => { open Promise - retrievePaymentIntent(clientSecret, headers) + retrievePaymentIntent(clientSecret, headers, ~optLogger) ->then(json => { let dict = json->Js.Json.decodeObject->Belt.Option.getWithDefault(Js.Dict.empty()) let status = dict->getString("status", "") @@ -42,13 +62,13 @@ let rec pollRetrievePaymentIntent = (clientSecret, headers) => { resolve(json) } else { delay(2000)->then(_val => { - pollRetrievePaymentIntent(clientSecret, headers) + pollRetrievePaymentIntent(clientSecret, headers, ~optLogger) }) } }) ->catch(e => { Js.log2("Unable to retrieve payment due to following error", e) - pollRetrievePaymentIntent(clientSecret, headers) + pollRetrievePaymentIntent(clientSecret, headers, ~optLogger) }) } @@ -456,6 +476,7 @@ let useSessions = ( ~publishableKey, ~wallets=[], ~isDelayedSessionToken=false, + ~optLogger, (), ) => { let fetchApi = CommonHooks.useApiFetcher() @@ -473,14 +494,35 @@ let useSessions = ( ] ->Js.Dict.fromArray ->Js.Json.object_ + let uri = `${endpoint}/payments/session_tokens` fetchApi( - `${endpoint}/payments/session_tokens`, + uri, ~method_=Fetch.Post, ~bodyStr=body->Js.Json.stringify, ~headers=headers->addCustomPodHeader, (), ) ->then(resp => { + let statusCode = resp->Fetch.Response.status->string_of_int + if statusCode->Js.String2.charAt(0) !== "2" { + resp + ->Fetch.Response.json + ->then(data => { + logApi( + ~optLogger, + ~url=uri, + ~data, + ~statusCode, + ~type_="response", + ~eventName=API_CALL_FAILED, + ~logType=ERROR, + ~logCategory=API, + (), + ) + resolve() + }) + ->ignore + } Fetch.Response.json(resp) }) ->then(json => { @@ -496,8 +538,9 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { open Promise let headers = [("Content-Type", "application/json"), ("api-key", publishableKey)] + let uri = `${endpoint}/account/payment_methods?client_secret=${clientSecret}` fetchApi( - `${endpoint}/account/payment_methods?client_secret=${clientSecret}`, + uri, ~method_=Fetch.Get, ~headers=headers->addCustomPodHeader, (), @@ -505,7 +548,23 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { ->then(resp => { let statusCode = resp->Fetch.Response.status->string_of_int if statusCode->Js.String2.charAt(0) !== "2" { - ErrorUtils.manageErrorWarning(INTERNAL_API_DOWN, ~logger, ()) + resp + ->Fetch.Response.json + ->then(data => { + logApi( + ~optLogger=Some(logger), + ~url=uri, + ~data, + ~statusCode, + ~type_="response", + ~eventName=API_CALL_FAILED, + ~logType=ERROR, + ~logCategory=API, + (), + ) + resolve() + }) + ->ignore } Fetch.Response.json(resp) }) @@ -517,7 +576,7 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { }) } -let useCustomerDetails = (~clientSecret, ~publishableKey) => { +let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => { open Promise let fetchApi = CommonHooks.useApiFetcher() let headers = [("Content-Type", "application/json"), ("api-key", publishableKey)] @@ -525,11 +584,30 @@ let useCustomerDetails = (~clientSecret, ~publishableKey) => { fetchApi(uri, ~method_=Fetch.Get, ~headers=headers->ApiEndpoint.addCustomPodHeader, ()) ->then(res => { + let statusCode = res->Fetch.Response.status->string_of_int + if statusCode->Js.String2.charAt(0) !== "2" { + res + ->Fetch.Response.json + ->then(data => { + logApi( + ~optLogger, + ~url=uri, + ~data, + ~statusCode, + ~type_="response", + ~eventName=API_CALL_FAILED, + ~logType=ERROR, + ~logCategory=API, + (), + ) + resolve() + }) + ->ignore + } res->Fetch.Response.json }) ->then(res => resolve(res)) ->catch(e => { - Js.log2("Unable to retrieve customer details because of ", e) Js.Dict.empty()->Js.Json.object_->resolve }) } diff --git a/src/orca-loader/HyperLoader.res b/src/orca-loader/HyperLoader.res index 9b1408f5b..0c5d622cf 100644 --- a/src/orca-loader/HyperLoader.res +++ b/src/orca-loader/HyperLoader.res @@ -453,6 +453,7 @@ module Elements = { let sessionsPromise = PaymentHelpers.useSessions( ~clientSecret=clientSecretId, ~publishableKey, + ~optLogger=Some(logger), (), ) let paymentMethodListPromise = PaymentHelpers.usePaymentMethodList( @@ -533,6 +534,7 @@ module Elements = { let customerDetailsPromise = PaymentHelpers.useCustomerDetails( ~clientSecret=clientSecretId, ~publishableKey, + ~optLogger=Some(logger), ) open Promise customerDetailsPromise @@ -1046,12 +1048,35 @@ module Hyper = { "api-key": publishableKey, } let paymentIntentID = Js.String2.split(clientSecret, "_secret_")[0] + let retrievePaymentUrl = `${ApiEndpoint.endpoint}/payments/${paymentIntentID}?client_secret=${clientSecret}` open Promise Fetch.fetchWithInit( - `${ApiEndpoint.endpoint}/payments/${paymentIntentID}?client_secret=${clientSecret}`, + retrievePaymentUrl, Fetch.RequestInit.make(~method_=Fetch.Get, ~headers=Fetch.HeadersInit.make(headers), ()), ) - ->then(Fetch.Response.json) + ->then(resp => { + let statusCode = resp->Fetch.Response.status->string_of_int + if statusCode->Js.String2.charAt(0) !== "2" { + resp + ->Fetch.Response.json + ->then(data => { + logApi( + ~optLogger=Some(logger), + ~url=retrievePaymentUrl, + ~data, + ~statusCode, + ~type_="response", + ~eventName=API_CALL_FAILED, + ~logType=ERROR, + ~logCategory=API, + (), + ) + resolve() + }) + ->ignore + } + Fetch.Response.json(resp) + }) ->then(data => { [("paymentIntent", data)]->Js.Dict.fromArray->Js.Json.object_->Promise.resolve }) From 7f3c157184d7dc0fe4c2b8afaca784a77ad2faeb Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Wed, 30 Aug 2023 16:54:28 +0530 Subject: [PATCH 2/9] Reformatted logs --- src/Utilities/LoggerUtils.res | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Utilities/LoggerUtils.res b/src/Utilities/LoggerUtils.res index 6999e97a0..0fab50fdd 100644 --- a/src/Utilities/LoggerUtils.res +++ b/src/Utilities/LoggerUtils.res @@ -30,13 +30,13 @@ let logApi = ( ] | NoResponse => [ ("url", url->Js.Json.string), - ("statusCode", "\"500\""->Js.Json.string), - ("response", "{\"error\": \"No Response from Server\"}"->Js.Json.string), + ("statusCode", "500"->Js.Json.string), + ("response", `{"error": "No Response from Server"}`->Js.Json.string), ] | Err => [ ("url", url->Js.Json.string), ("statusCode", statusCode->Js.Json.string), - ("response", "{\"error\": \"No Response from Server\"}"->Js.Json.string), + ("response", `{"error": "No Response from Server"}`->Js.Json.string), ] | Method => [("method", paymentMethod->Js.Json.string), ("result", result)] } From d845e934a1d854e3c46d46d62d447d6ca46d7385 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Thu, 31 Aug 2023 16:01:06 +0530 Subject: [PATCH 3/9] Changed status code for no response --- src/Utilities/LoggerUtils.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utilities/LoggerUtils.res b/src/Utilities/LoggerUtils.res index 0fab50fdd..9dc4bb925 100644 --- a/src/Utilities/LoggerUtils.res +++ b/src/Utilities/LoggerUtils.res @@ -30,7 +30,7 @@ let logApi = ( ] | NoResponse => [ ("url", url->Js.Json.string), - ("statusCode", "500"->Js.Json.string), + ("statusCode", "504"->Js.Json.string), ("response", `{"error": "No Response from Server"}`->Js.Json.string), ] | Err => [ From 64273de9204986415f7327045199de10b16c9044 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Fri, 1 Sep 2023 15:33:31 +0530 Subject: [PATCH 4/9] Merge branch 'fix/log-api-calls' of ssh://ssh.bitbucket.juspay.net/exc/orca-elements into bugfixes/sdk_logs_formats --- src/orca-loader/Elements.res | 2 ++ src/orca-loader/Hyper.res | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index e96442cc0..e1a8b7e0d 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -45,6 +45,7 @@ let make = ( let sessionsPromise = PaymentHelpers.useSessions( ~clientSecret=clientSecretId, ~publishableKey, + ~optLogger=Some(logger), (), ) let paymentMethodListPromise = PaymentHelpers.usePaymentMethodList( @@ -125,6 +126,7 @@ let make = ( let customerDetailsPromise = PaymentHelpers.useCustomerDetails( ~clientSecret=clientSecretId, ~publishableKey, + ~optLogger=Some(logger), ) open Promise customerDetailsPromise diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res index 20e2b7554..2377bdc0d 100644 --- a/src/orca-loader/Hyper.res +++ b/src/orca-loader/Hyper.res @@ -120,12 +120,35 @@ let make = (publishableKey, _options: option, analyticsInfo: optionthen(Fetch.Response.json) + ->then(resp => { + let statusCode = resp->Fetch.Response.status->string_of_int + if statusCode->Js.String2.charAt(0) !== "2" { + resp + ->Fetch.Response.json + ->then(data => { + logApi( + ~optLogger=Some(logger), + ~url=retrievePaymentUrl, + ~data, + ~statusCode, + ~type_="response", + ~eventName=API_CALL_FAILED, + ~logType=ERROR, + ~logCategory=API, + (), + ) + resolve() + }) + ->ignore + } + Fetch.Response.json(resp) + }) ->then(data => { [("paymentIntent", data)]->Js.Dict.fromArray->Js.Json.object_->Promise.resolve }) From e5ea7e9f644ff701f7f310fc14a96861abc9d038 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Fri, 1 Sep 2023 16:58:46 +0530 Subject: [PATCH 5/9] Refactor API call logs --- src/Utilities/PaymentHelpers.res | 118 +++++++++++++++++++++------- src/orca-loader/Hyper.res | 15 +++- src/orca-log-catcher/OrcaLogger.res | 34 +++++++- 3 files changed, 131 insertions(+), 36 deletions(-) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 2ca9fb0d5..02a8f12b2 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -32,8 +32,8 @@ let retrievePaymentIntent = (clientSecret, headers, ~optLogger) => { ~url=uri, ~data, ~statusCode, - ~type_="response", - ~eventName=API_CALL_FAILED, + ~type_="err", + ~eventName=RETRIEVE_CALL_FAILED, ~logType=ERROR, ~logCategory=API, (), @@ -41,6 +41,17 @@ let retrievePaymentIntent = (clientSecret, headers, ~optLogger) => { resolve() }) ->ignore + } else { + logApi( + ~optLogger, + ~url=uri, + ~statusCode, + ~type_="response", + ~eventName=RETRIEVE_CALL, + ~logType=INFO, + ~logCategory=API, + (), + ) } res->Fetch.Response.json }) @@ -93,6 +104,7 @@ let intentCall = ( ~setIsManualRetryEnabled, ) => { open Promise + let isConfirm = uri->Js.String.includes("/confirm") fetchApi(uri, ~method_=fetchMethod, ~headers=headers->addCustomPodHeader, ~bodyStr, ()) ->then(res => { let statusCode = res->Fetch.Response.status->string_of_int @@ -104,7 +116,7 @@ let intentCall = ( res ->Fetch.Response.json ->then(data => { - if uri->Js.String.includes("/confirm") { + if isConfirm { let paymentMethod = switch paymentType { | Card => "CARD" | _ => @@ -120,18 +132,19 @@ let intentCall = ( ~paymentMethod, ) } - + let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL_FAILED : RETRIEVE_CALL_FAILED logApi( ~optLogger, ~url=uri, ~data, ~statusCode, - ~type_="response", - ~eventName=API_CALL_FAILED, + ~type_="err", + ~eventName, ~logType=ERROR, ~logCategory=API, (), ) + let dict = data->getDictFromJson let errorObj = PaymentError.itemToObjMapper(dict) closePaymentLoaderIfAny() @@ -142,12 +155,15 @@ let intentCall = ( resolve() }) ->catch(_err => { + let eventName: OrcaLogger.eventName = isConfirm + ? CONFIRM_CALL_FAILED_WITHOUT_STATUS_CODE + : RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE logApi( ~optLogger, ~url=uri, ~statusCode, - ~type_="err", - ~eventName=API_CALL_FAILED_WITHOUT_STATUS_CODE, + ~type_="no_response", + ~eventName, ~logType=ERROR, ~logCategory=API, (), @@ -161,18 +177,11 @@ let intentCall = ( }) ->ignore } else { + let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL res ->Fetch.Response.json ->then(data => { - logApi( - ~optLogger, - ~url=uri, - ~data, - ~statusCode, - ~type_="response", - ~eventName=PAYMENT_RESPONSE, - (), - ) + logApi(~optLogger, ~url=uri, ~statusCode, ~type_="response", ~eventName, ()) let intent = PaymentConfirmTypes.itemToObjMapper(data->getDictFromJson) let url = urlSearch(confirmParam.return_url) @@ -286,12 +295,15 @@ let intentCall = ( }) ->catch(_err => { let url = urlSearch(confirmParam.return_url) + let eventName: OrcaLogger.eventName = isConfirm + ? CONFIRM_CALL_FAILED_WITHOUT_STATUS_CODE + : RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE url.searchParams.set(. "payment_intent_client_secret", clientSecret) url.searchParams.set(. "status", "failed") logApi( ~optLogger, ~url=uri, - ~eventName=API_CALL_FAILED_WITHOUT_STATUS_CODE, + ~eventName, ~type_="no_response", ~logType=ERROR, ~logCategory=API, @@ -513,8 +525,8 @@ let useSessions = ( ~url=uri, ~data, ~statusCode, - ~type_="response", - ~eventName=API_CALL_FAILED, + ~type_="err", + ~eventName=SESSIONS_CALL_FAILED, ~logType=ERROR, ~logCategory=API, (), @@ -522,6 +534,17 @@ let useSessions = ( resolve() }) ->ignore + } else { + logApi( + ~optLogger, + ~url=uri, + ~statusCode, + ~type_="response", + ~eventName=SESSIONS_CALL, + ~logType=INFO, + ~logCategory=API, + (), + ) } Fetch.Response.json(resp) }) @@ -529,6 +552,15 @@ let useSessions = ( json->resolve }) ->catch(_e => { + logApi( + ~optLogger, + ~url=uri, + ~type_="no_response", + ~eventName=SESSIONS_CALL_FAILED_WITHOUT_STATUS_CODE, + ~logType=ERROR, + ~logCategory=API, + (), + ) Js.Dict.empty()->Js.Json.object_->resolve }) } @@ -539,12 +571,7 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { open Promise let headers = [("Content-Type", "application/json"), ("api-key", publishableKey)] let uri = `${endpoint}/account/payment_methods?client_secret=${clientSecret}` - fetchApi( - uri, - ~method_=Fetch.Get, - ~headers=headers->addCustomPodHeader, - (), - ) + fetchApi(uri, ~method_=Fetch.Get, ~headers=headers->addCustomPodHeader, ()) ->then(resp => { let statusCode = resp->Fetch.Response.status->string_of_int if statusCode->Js.String2.charAt(0) !== "2" { @@ -556,8 +583,8 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { ~url=uri, ~data, ~statusCode, - ~type_="response", - ~eventName=API_CALL_FAILED, + ~type_="err", + ~eventName=PAYMENT_METHODS_CALL_FAILED, ~logType=ERROR, ~logCategory=API, (), @@ -565,6 +592,17 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { resolve() }) ->ignore + } else { + logApi( + ~optLogger=Some(logger), + ~url=uri, + ~statusCode, + ~type_="response", + ~eventName=PAYMENT_METHODS_CALL, + ~logType=INFO, + ~logCategory=API, + (), + ) } Fetch.Response.json(resp) }) @@ -572,6 +610,15 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { json->resolve }) ->catch(_e => { + logApi( + ~optLogger=Some(logger), + ~url=uri, + ~type_="no_response", + ~eventName=PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE, + ~logType=ERROR, + ~logCategory=API, + (), + ) Js.Dict.empty()->Js.Json.object_->resolve }) } @@ -594,8 +641,8 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => { ~url=uri, ~data, ~statusCode, - ~type_="response", - ~eventName=API_CALL_FAILED, + ~type_="err", + ~eventName=CUSTOMER_PAYMENT_METHODS_CALL_FAILED, ~logType=ERROR, ~logCategory=API, (), @@ -603,6 +650,17 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => { resolve() }) ->ignore + } else { + logApi( + ~optLogger, + ~url=uri, + ~statusCode, + ~type_="response", + ~eventName=CUSTOMER_PAYMENT_METHODS_CALL, + ~logType=INFO, + ~logCategory=API, + (), + ) } res->Fetch.Response.json }) diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res index 2377bdc0d..a54929542 100644 --- a/src/orca-loader/Hyper.res +++ b/src/orca-loader/Hyper.res @@ -137,8 +137,8 @@ let make = (publishableKey, _options: option, analyticsInfo: option, analyticsInfo: optionignore + } else { + logApi( + ~optLogger=Some(logger), + ~url=retrievePaymentUrl, + ~statusCode, + ~type_="response", + ~eventName=RETRIEVE_CALL, + ~logType=INFO, + ~logCategory=API, + (), + ) } Fetch.Response.json(resp) }) diff --git a/src/orca-log-catcher/OrcaLogger.res b/src/orca-log-catcher/OrcaLogger.res index 66ce942b4..928216257 100644 --- a/src/orca-log-catcher/OrcaLogger.res +++ b/src/orca-log-catcher/OrcaLogger.res @@ -28,8 +28,21 @@ type eventName = | COUNTRY_CHANGED | LOG_INITIATED | INPUT_FIELD_CHANGED - | API_CALL_FAILED - | API_CALL_FAILED_WITHOUT_STATUS_CODE + | RETRIEVE_CALL + | RETRIEVE_CALL_FAILED + | RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE + | CONFIRM_CALL + | CONFIRM_CALL_FAILED + | CONFIRM_CALL_FAILED_WITHOUT_STATUS_CODE + | SESSIONS_CALL + | SESSIONS_CALL_FAILED + | SESSIONS_CALL_FAILED_WITHOUT_STATUS_CODE + | PAYMENT_METHODS_CALL + | PAYMENT_METHODS_CALL_FAILED + | PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE + | CUSTOMER_PAYMENT_METHODS_CALL + | CUSTOMER_PAYMENT_METHODS_CALL_FAILED + | CUSTOMER_PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE | TRUSTPAY_SCRIPT | GOOGLE_PAY_SCRIPT | APPLE_PAY_FLOW @@ -76,8 +89,21 @@ let eventNameToStrMapper = eventName => { | COUNTRY_CHANGED => "COUNTRY_CHANGED" | LOG_INITIATED => "LOG_INITIATED" | INPUT_FIELD_CHANGED => "INPUT_FIELD_CHANGED" - | API_CALL_FAILED => "API_CALL_FAILED" - | API_CALL_FAILED_WITHOUT_STATUS_CODE => "API_CALL_FAILED_WITHOUT_STATUS_CODE" + | RETRIEVE_CALL => "RETRIEVE_CALL" + | RETRIEVE_CALL_FAILED => "RETRIEVE_CALL_FAILED" + | RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE => "RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE" + | CONFIRM_CALL => "CONFIRM_CALL" + | CONFIRM_CALL_FAILED => "RETRIEVE_CALL_FAILED" + | CONFIRM_CALL_FAILED_WITHOUT_STATUS_CODE => "RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE" + | SESSIONS_CALL => "SESSIONS_CALL" + | SESSIONS_CALL_FAILED => "SESSIONS_CALL_FAILED" + | SESSIONS_CALL_FAILED_WITHOUT_STATUS_CODE => "SESSIONS_CALL_FAILED_WITHOUT_STATUS_CODE" + | PAYMENT_METHODS_CALL => "PAYMENT_METHODS_CALL" + | PAYMENT_METHODS_CALL_FAILED => "PAYMENT_METHODS_CALL_FAILED" + | PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE => "PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE" + | CUSTOMER_PAYMENT_METHODS_CALL => "CUSTOMER_PAYMENT_METHODS_CALL" + | CUSTOMER_PAYMENT_METHODS_CALL_FAILED => "CUSTOMER_PAYMENT_METHODS_CALL_FAILED" + | CUSTOMER_PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE => "CUSTOMER_PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE" | TRUSTPAY_SCRIPT => "TRUSTPAY_SCRIPT" | GOOGLE_PAY_SCRIPT => "GOOGLE_PAY_SCRIPT" | APPLE_PAY_FLOW => "APPLE_PAY_FLOW" From 0f77394d9bc3853d80380d960c567b0a8ed9baf0 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Fri, 1 Sep 2023 17:13:38 +0530 Subject: [PATCH 6/9] Removed batching --- src/orca-log-catcher/OrcaLogger.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/orca-log-catcher/OrcaLogger.res b/src/orca-log-catcher/OrcaLogger.res index 928216257..502eb0f72 100644 --- a/src/orca-log-catcher/OrcaLogger.res +++ b/src/orca-log-catcher/OrcaLogger.res @@ -499,7 +499,7 @@ let make = ( | None => timeOut := Some(Js.Global.setTimeout(() => sendLogs(), 20000)) } let len = mainLogFile->Js.Array2.length - if len > 5 { + if len > 1 { sendLogs() } } From 1480da0989d3a8a46b3791d1058d22d5176adfaa Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Fri, 1 Sep 2023 17:29:21 +0530 Subject: [PATCH 7/9] Removed _failed event names --- src/Utilities/PaymentHelpers.res | 22 +++++++++------------- src/orca-loader/Hyper.res | 2 +- src/orca-log-catcher/OrcaLogger.res | 20 -------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 02a8f12b2..64ea6fd73 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -33,7 +33,7 @@ let retrievePaymentIntent = (clientSecret, headers, ~optLogger) => { ~data, ~statusCode, ~type_="err", - ~eventName=RETRIEVE_CALL_FAILED, + ~eventName=RETRIEVE_CALL, ~logType=ERROR, ~logCategory=API, (), @@ -132,7 +132,7 @@ let intentCall = ( ~paymentMethod, ) } - let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL_FAILED : RETRIEVE_CALL_FAILED + let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL logApi( ~optLogger, ~url=uri, @@ -155,9 +155,7 @@ let intentCall = ( resolve() }) ->catch(_err => { - let eventName: OrcaLogger.eventName = isConfirm - ? CONFIRM_CALL_FAILED_WITHOUT_STATUS_CODE - : RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE + let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL logApi( ~optLogger, ~url=uri, @@ -295,9 +293,7 @@ let intentCall = ( }) ->catch(_err => { let url = urlSearch(confirmParam.return_url) - let eventName: OrcaLogger.eventName = isConfirm - ? CONFIRM_CALL_FAILED_WITHOUT_STATUS_CODE - : RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE + let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL url.searchParams.set(. "payment_intent_client_secret", clientSecret) url.searchParams.set(. "status", "failed") logApi( @@ -526,7 +522,7 @@ let useSessions = ( ~data, ~statusCode, ~type_="err", - ~eventName=SESSIONS_CALL_FAILED, + ~eventName=SESSIONS_CALL, ~logType=ERROR, ~logCategory=API, (), @@ -556,7 +552,7 @@ let useSessions = ( ~optLogger, ~url=uri, ~type_="no_response", - ~eventName=SESSIONS_CALL_FAILED_WITHOUT_STATUS_CODE, + ~eventName=SESSIONS_CALL, ~logType=ERROR, ~logCategory=API, (), @@ -584,7 +580,7 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { ~data, ~statusCode, ~type_="err", - ~eventName=PAYMENT_METHODS_CALL_FAILED, + ~eventName=PAYMENT_METHODS_CALL, ~logType=ERROR, ~logCategory=API, (), @@ -614,7 +610,7 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => { ~optLogger=Some(logger), ~url=uri, ~type_="no_response", - ~eventName=PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE, + ~eventName=PAYMENT_METHODS_CALL, ~logType=ERROR, ~logCategory=API, (), @@ -642,7 +638,7 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => { ~data, ~statusCode, ~type_="err", - ~eventName=CUSTOMER_PAYMENT_METHODS_CALL_FAILED, + ~eventName=CUSTOMER_PAYMENT_METHODS_CALL, ~logType=ERROR, ~logCategory=API, (), diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res index a54929542..3845af66a 100644 --- a/src/orca-loader/Hyper.res +++ b/src/orca-loader/Hyper.res @@ -138,7 +138,7 @@ let make = (publishableKey, _options: option, analyticsInfo: option { | LOG_INITIATED => "LOG_INITIATED" | INPUT_FIELD_CHANGED => "INPUT_FIELD_CHANGED" | RETRIEVE_CALL => "RETRIEVE_CALL" - | RETRIEVE_CALL_FAILED => "RETRIEVE_CALL_FAILED" - | RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE => "RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE" | CONFIRM_CALL => "CONFIRM_CALL" - | CONFIRM_CALL_FAILED => "RETRIEVE_CALL_FAILED" - | CONFIRM_CALL_FAILED_WITHOUT_STATUS_CODE => "RETRIEVE_CALL_FAILED_WITHOUT_STATUS_CODE" | SESSIONS_CALL => "SESSIONS_CALL" - | SESSIONS_CALL_FAILED => "SESSIONS_CALL_FAILED" - | SESSIONS_CALL_FAILED_WITHOUT_STATUS_CODE => "SESSIONS_CALL_FAILED_WITHOUT_STATUS_CODE" | PAYMENT_METHODS_CALL => "PAYMENT_METHODS_CALL" - | PAYMENT_METHODS_CALL_FAILED => "PAYMENT_METHODS_CALL_FAILED" - | PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE => "PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE" | CUSTOMER_PAYMENT_METHODS_CALL => "CUSTOMER_PAYMENT_METHODS_CALL" - | CUSTOMER_PAYMENT_METHODS_CALL_FAILED => "CUSTOMER_PAYMENT_METHODS_CALL_FAILED" - | CUSTOMER_PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE => "CUSTOMER_PAYMENT_METHODS_CALL_FAILED_WITHOUT_STATUS_CODE" | TRUSTPAY_SCRIPT => "TRUSTPAY_SCRIPT" | GOOGLE_PAY_SCRIPT => "GOOGLE_PAY_SCRIPT" | APPLE_PAY_FLOW => "APPLE_PAY_FLOW" From f931c999fa09ddc124f5a7e8c4eb29495e122433 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Fri, 1 Sep 2023 18:39:11 +0530 Subject: [PATCH 8/9] Resolved comments --- src/Utilities/PaymentHelpers.res | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 64ea6fd73..4c48acc1a 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -105,6 +105,7 @@ let intentCall = ( ) => { open Promise let isConfirm = uri->Js.String.includes("/confirm") + let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL fetchApi(uri, ~method_=fetchMethod, ~headers=headers->addCustomPodHeader, ~bodyStr, ()) ->then(res => { let statusCode = res->Fetch.Response.status->string_of_int @@ -132,7 +133,6 @@ let intentCall = ( ~paymentMethod, ) } - let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL logApi( ~optLogger, ~url=uri, @@ -155,7 +155,6 @@ let intentCall = ( resolve() }) ->catch(_err => { - let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL logApi( ~optLogger, ~url=uri, @@ -175,7 +174,6 @@ let intentCall = ( }) ->ignore } else { - let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL res ->Fetch.Response.json ->then(data => { @@ -293,7 +291,6 @@ let intentCall = ( }) ->catch(_err => { let url = urlSearch(confirmParam.return_url) - let eventName: OrcaLogger.eventName = isConfirm ? CONFIRM_CALL : RETRIEVE_CALL url.searchParams.set(. "payment_intent_client_secret", clientSecret) url.searchParams.set(. "status", "failed") logApi( From 47e6da8c2fc16bda4fc7870375f4e4cff0e1babf Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Mon, 4 Sep 2023 16:19:03 +0530 Subject: [PATCH 9/9] Length check changes to > 0 --- src/orca-log-catcher/OrcaLogger.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/orca-log-catcher/OrcaLogger.res b/src/orca-log-catcher/OrcaLogger.res index 016e99ae0..5734d5de5 100644 --- a/src/orca-log-catcher/OrcaLogger.res +++ b/src/orca-log-catcher/OrcaLogger.res @@ -479,7 +479,7 @@ let make = ( | None => timeOut := Some(Js.Global.setTimeout(() => sendLogs(), 20000)) } let len = mainLogFile->Js.Array2.length - if len > 1 { + if len > 0 { sendLogs() } }