From 9358f7e94b655f27941d0de7ec7122d20dca5e10 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Wed, 13 Sep 2023 12:51:51 +0530 Subject: [PATCH 1/2] Log masked payload on /confirm --- src/Utilities/PaymentHelpers.res | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index aa02c5b3e..d1d49c442 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -423,6 +423,30 @@ let usePaymentSync = (optLogger: option, paymentType: pay } } +let rec maskPayload = payloadDict => { + let keys = payloadDict->Js.Dict.keys + let maskedPayload = Js.Dict.empty() + keys + ->Js.Array2.map(key => { + let value = payloadDict->Js.Dict.get(key)->Belt.Option.getWithDefault(Js.Json.null) + if value->Js.Json.decodeObject->Belt.Option.isSome { + let valueDict = value->Utils.getDictFromJson + maskedPayload->Js.Dict.set(key, valueDict->maskPayload->Js.Json.string) + } else { + maskedPayload->Js.Dict.set( + key, + value + ->Js.Json.decodeString + ->Belt.Option.getWithDefault("") + ->Js.String2.replaceByRe(%re(`/\S/g`), "x") + ->Js.Json.string, + ) + } + }) + ->ignore + maskedPayload->Js.Json.object_->Js.Json.stringify +} + let usePaymentIntent = (optLogger: option, paymentType: payment) => { let fetchApi = CommonHooks.useApiFetcher() let list = Recoil.useRecoilValueFromAtom(RecoilAtoms.list) @@ -455,10 +479,16 @@ let usePaymentIntent = (optLogger: option, paymentType: p let loggerPayload = body->Js.Dict.fromArray->Js.Json.object_->Js.Json.stringify let callIntent = body => { + let maskedPayload = + body + ->OrcaUtils.safeParseOpt + ->Belt.Option.getWithDefault(Js.Json.null) + ->Utils.getDictFromJson + ->maskPayload if paymentType == Card { handleLogging( ~optLogger, - ~value=loggerPayload, + ~value=maskedPayload, ~eventName=PAYMENT_ATTEMPT, ~paymentMethod="CARD", ) @@ -467,7 +497,7 @@ let usePaymentIntent = (optLogger: option, paymentType: p if str === "payment_method_type" { handleLogging( ~optLogger, - ~value=loggerPayload, + ~value=maskedPayload, ~eventName=PAYMENT_ATTEMPT, ~paymentMethod=json->Js.Json.decodeString->Belt.Option.getWithDefault(""), ) From b3413ac5f06654b2b8dbc19183f17b40e26e9f49 Mon Sep 17 00:00:00 2001 From: Vrishab Srivatsa Date: Wed, 13 Sep 2023 12:59:55 +0530 Subject: [PATCH 2/2] Log headers as well --- src/Utilities/PaymentHelpers.res | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index d1d49c442..ff0403d87 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -476,7 +476,7 @@ let usePaymentIntent = (optLogger: option, paymentType: p ]) let uri = `${endpoint}/payments/${paymentIntentID}/confirm` let fetchMethod = Fetch.Post - let loggerPayload = body->Js.Dict.fromArray->Js.Json.object_->Js.Json.stringify + // let loggerPayload = body->Js.Dict.fromArray->Js.Json.object_->Js.Json.stringify let callIntent = body => { let maskedPayload = @@ -485,10 +485,27 @@ let usePaymentIntent = (optLogger: option, paymentType: p ->Belt.Option.getWithDefault(Js.Json.null) ->Utils.getDictFromJson ->maskPayload + let loggerPayload = + [ + ("payload", maskedPayload->Js.Json.string), + ( + "headers", + headers + ->Js.Array2.map(header => { + let (key, value) = header + (key, value->Js.Json.string) + }) + ->Js.Dict.fromArray + ->Js.Json.object_, + ), + ] + ->Js.Dict.fromArray + ->Js.Json.object_ + ->Js.Json.stringify if paymentType == Card { handleLogging( ~optLogger, - ~value=maskedPayload, + ~value=loggerPayload, ~eventName=PAYMENT_ATTEMPT, ~paymentMethod="CARD", ) @@ -497,7 +514,7 @@ let usePaymentIntent = (optLogger: option, paymentType: p if str === "payment_method_type" { handleLogging( ~optLogger, - ~value=maskedPayload, + ~value=loggerPayload, ~eventName=PAYMENT_ATTEMPT, ~paymentMethod=json->Js.Json.decodeString->Belt.Option.getWithDefault(""), )