Skip to content

Commit

Permalink
Pull request #225: Log masked payload on /confirm
Browse files Browse the repository at this point in the history
Merge in EXC/orca-elements from feature/log_masked_payload to master

* commit 'b3413ac5f06654b2b8dbc19183f17b40e26e9f49':
  Log headers as well
  Log masked payload on /confirm
  • Loading branch information
Vrishab Srivatsa authored and prafulkoppalkar committed Sep 13, 2023
2 parents dd48ecd + b3413ac commit 5fa5fc7
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion 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 @@ -452,9 +476,32 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, 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 =
body
->OrcaUtils.safeParseOpt
->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,
Expand Down

0 comments on commit 5fa5fc7

Please sign in to comment.