Skip to content

Commit

Permalink
fix: google Pay Payment Data Filled event fix and tagging headless lo…
Browse files Browse the repository at this point in the history
…gs with source
  • Loading branch information
Vrishab Srivatsa committed Apr 8, 2024
1 parent 6678dc1 commit ec2fbfd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 46 deletions.
16 changes: 8 additions & 8 deletions src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let make = (
~walletOptions: array<string>,
) => {
let (requiredFieldsBody, setRequiredFieldsBody) = React.useState(_ => Dict.make())
let (loggerState, _setLoggerState) = Recoil.useRecoilState(loggerAtom)
let (loggerState, _) = Recoil.useRecoilState(loggerAtom)
let {iframeId} = Recoil.useRecoilValueFromAtom(keys)
let {publishableKey, sdkHandleOneClickConfirmPayment} = Recoil.useRecoilValueFromAtom(keys)
let {localeString} = Recoil.useRecoilValueFromAtom(configAtom)
Expand Down Expand Up @@ -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([
Expand All @@ -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()
})
Expand Down
11 changes: 3 additions & 8 deletions src/Utilities/LoggerUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let logApi = (
~optLogger: option<OrcaLogger.loggerMake>,
~logType: OrcaLogger.logType=INFO,
~logCategory: OrcaLogger.logCategory=API,
~isPaymentSession: bool=false,
(),
) => {
let (value, internalMetadata) = switch apiLogType {
Expand Down Expand Up @@ -44,21 +45,15 @@ let logApi = (
~logType,
~logCategory,
~apiLogType,
~isPaymentSession,
(),
)
| None => ()
}
}

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 = (
Expand Down
19 changes: 18 additions & 1 deletion src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ let rec intentCall = (
~eventName=initEventName,
~logType=INFO,
~logCategory=API,
~isPaymentSession,
(),
)
let handleOpenUrl = url => {
Expand Down Expand Up @@ -341,6 +342,7 @@ let rec intentCall = (
~eventName,
~logType=ERROR,
~logCategory=API,
~isPaymentSession,
(),
)

Expand Down Expand Up @@ -378,6 +380,7 @@ let rec intentCall = (
~eventName,
~logType=ERROR,
~logCategory=API,
~isPaymentSession,
(),
)
if counter >= 5 {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -713,6 +724,7 @@ let rec intentCall = (
~data=exceptionMessage,
~logType=ERROR,
~logCategory=API,
~isPaymentSession,
(),
)
if counter >= 5 {
Expand Down Expand Up @@ -1162,6 +1174,7 @@ let fetchCustomerDetails = (
~endpoint,
~optLogger,
~switchToCustomPod,
~isPaymentSession=false,
) => {
open Promise
let headers = [("Content-Type", "application/json"), ("api-key", publishableKey)]
Expand All @@ -1173,6 +1186,7 @@ let fetchCustomerDetails = (
~eventName=CUSTOMER_PAYMENT_METHODS_CALL_INIT,
~logType=INFO,
~logCategory=API,
~isPaymentSession,
(),
)
fetchApi(
Expand All @@ -1196,6 +1210,7 @@ let fetchCustomerDetails = (
~eventName=CUSTOMER_PAYMENT_METHODS_CALL,
~logType=ERROR,
~logCategory=API,
~isPaymentSession,
(),
)
JSON.Encode.null->resolve
Expand All @@ -1209,6 +1224,7 @@ let fetchCustomerDetails = (
~eventName=CUSTOMER_PAYMENT_METHODS_CALL,
~logType=INFO,
~logCategory=API,
~isPaymentSession,
(),
)
res->Fetch.Response.json
Expand All @@ -1224,6 +1240,7 @@ let fetchCustomerDetails = (
~logType=ERROR,
~logCategory=API,
~data=exceptionMessage,
~isPaymentSession,
(),
)
JSON.Encode.null->resolve
Expand Down
7 changes: 0 additions & 7 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/orca-loader/PaymentSessionMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let getCustomerSavedPaymentMethods = (
~endpoint,
~switchToCustomPod,
~optLogger=Some(logger),
~isPaymentSession=true,
)
->then(customerDetails => {
let customerPaymentMethods =
Expand Down
28 changes: 6 additions & 22 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -194,6 +194,7 @@ type loggerMake = {
~logCategory: logCategory=?,
~paymentMethod: string=?,
~apiLogType: apiLogType=?,
~isPaymentSession: bool=?,
unit,
) => unit,
setLogInitiated: unit => unit,
Expand Down Expand Up @@ -229,6 +230,7 @@ let defaultLoggerConfig = {
~logCategory as _=?,
~paymentMethod as _=?,
~apiLogType as _=?,
~isPaymentSession as _=?,
(),
) => (),
setLogInfo: (
Expand Down Expand Up @@ -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: "<all headers>" response_headers: "<all 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)
Expand All @@ -320,6 +302,7 @@ let getSourceString = source => {
switch source {
| Loader => "orca-loader"
| Elements => "orca-element"
| Headless => "headless"
}
}

Expand Down Expand Up @@ -640,6 +623,7 @@ let make = (
~logCategory=API,
~paymentMethod="",
~apiLogType=Request,
~isPaymentSession=false,
(),
) => {
let eventNameStr = eventName->eventNameToStrMapper
Expand All @@ -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
Expand Down

0 comments on commit ec2fbfd

Please sign in to comment.