Skip to content

Commit

Permalink
Log masked payload on /confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrishab Srivatsa committed Sep 13, 2023
1 parent bcf2ca9 commit 9358f7e
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,30 @@ let usePaymentSync = (optLogger: option<OrcaLogger.loggerMake>, 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<OrcaLogger.loggerMake>, paymentType: payment) => {
let fetchApi = CommonHooks.useApiFetcher()
let list = Recoil.useRecoilValueFromAtom(RecoilAtoms.list)
Expand Down Expand Up @@ -455,10 +479,16 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, 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",
)
Expand All @@ -467,7 +497,7 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, paymentType: p
if str === "payment_method_type" {
handleLogging(
~optLogger,
~value=loggerPayload,
~value=maskedPayload,
~eventName=PAYMENT_ATTEMPT,
~paymentMethod=json->Js.Json.decodeString->Belt.Option.getWithDefault(""),
)
Expand Down

0 comments on commit 9358f7e

Please sign in to comment.