Skip to content

Commit

Permalink
Pull request #236: Optimization/logs gpay applepay and formatting
Browse files Browse the repository at this point in the history
Merge in EXC/orca-elements from optimization/logs_gpay_and_format to master

* commit '307bb6a5689908a9db4be0f86c74d2cfbfa2ac52':
  Added logs for payment data filled
  Refactored API Error logs and Google Pay logs
  • Loading branch information
Vrishab Srivatsa authored and arun.mishra committed Sep 21, 2023
2 parents 0337717 + 307bb6a commit 7188879
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 67 deletions.
6 changes: 6 additions & 0 deletions src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
47 changes: 9 additions & 38 deletions src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -236,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 = {
Expand Down
24 changes: 10 additions & 14 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
(),
Expand Down Expand Up @@ -663,16 +662,15 @@ let useSessions = (
json->resolve
})
->catch(err => {
let exceptionJson = err->toJson

let exceptionMessage = err->Utils.formatException
logApi(
~optLogger,
~url=uri,
~type_="no_response",
~eventName=SESSIONS_CALL,
~logType=ERROR,
~logCategory=API,
~data=exceptionJson,
~data=exceptionMessage,
(),
)
Js.Dict.empty()->Js.Json.object_->resolve
Expand Down Expand Up @@ -733,16 +731,15 @@ let usePaymentMethodList = (~clientSecret, ~publishableKey, ~logger) => {
json->resolve
})
->catch(err => {
let exceptionJson = err->toJson

let exceptionMessage = err->Utils.formatException
logApi(
~optLogger=Some(logger),
~url=uri,
~type_="no_response",
~eventName=PAYMENT_METHODS_CALL,
~logType=ERROR,
~logCategory=API,
~data=exceptionJson,
~data=exceptionMessage,
(),
)
Js.Dict.empty()->Js.Json.object_->resolve
Expand Down Expand Up @@ -800,16 +797,15 @@ let useCustomerDetails = (~clientSecret, ~publishableKey, ~optLogger) => {
})
->then(res => resolve(res))
->catch(err => {
let exceptionJson = err->toJson

let exceptionMessage = err->Utils.formatException
logApi(
~optLogger,
~url=uri,
~type_="no_response",
~eventName=CUSTOMER_PAYMENT_METHODS_CALL,
~logType=ERROR,
~logCategory=API,
~data=exceptionJson,
~data=exceptionMessage,
(),
)
Js.Dict.empty()->Js.Json.object_->resolve
Expand Down
18 changes: 18 additions & 0 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
41 changes: 26 additions & 15 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -353,23 +356,24 @@ let make = (
try {
gPayClient.loadPaymentData(. data)
->then(json => {
let msg = [("gpayResponse", json->toJson)]->Js.Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
logger.setLogInfo(
~value=json->toJson->Js.Json.stringify,
~eventName=GOOGLE_PAY_FLOW,
~value="",
~eventName=PAYMENT_DATA_FILLED,
~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
Expand All @@ -379,14 +383,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)
}
}
Expand Down Expand Up @@ -515,11 +521,16 @@ 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 => {
let exceptionMessage = err->toJson->Js.Json.stringify

let exceptionMessage = err->Utils.formatException->Js.Json.stringify
logger.setLogInfo(
~eventName=APPLE_PAY_FLOW,
~paymentMethod="APPLE_PAY",
Expand Down

0 comments on commit 7188879

Please sign in to comment.