Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: logging payment data filled #269

Merged
merged 11 commits into from
Apr 4, 2024
33 changes: 25 additions & 8 deletions src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,38 @@ let make = (
| _ => false
}
let empty = cvcNumber == ""
let (token, customerId) = paymentToken
let customerMethod =
savedMethods
->Array.filter(savedMethod => {
savedMethod.paymentToken === token
})
->Array.get(0)
->Option.getOr(PaymentType.defaultCustomerMethods)
let isUnknownPaymentMethod = customerMethod.paymentMethod === ""
let isCardPaymentMethod = customerMethod.paymentMethod === "card"
let isCardPaymentMethodValid = !customerMethod.requiresCvv || (complete && !empty)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper
let (token, customerId) = paymentToken
React.useEffect(() => {
let customerMethod =
savedMethods
->Array.filter(savedMethod => {
savedMethod.paymentToken === token
})
->Array.get(0)
->Option.getOr(PaymentType.defaultCustomerMethods)
let isUnknownPaymentMethod = customerMethod.paymentMethod === ""
let isCardPaymentMethod = customerMethod.paymentMethod === "card"
let isCardPaymentMethodValid = !customerMethod.requiresCvv || (complete && !empty)
let complete =
areRequiredFieldsValid &&
!isUnknownPaymentMethod &&
(!isCardPaymentMethod || isCardPaymentMethodValid)
let paymentType = customerMethod.paymentMethodType->Option.getOr(customerMethod.paymentMethod)
handlePostMessageEvents(~complete, ~empty, ~paymentType, ~loggerState, ~savedMethod=true)
None
}, (areRequiredFieldsValid, empty, customerMethod, isCardPaymentMethodValid))

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper

let savedPaymentMethodBody = switch customerMethod.paymentMethod {
| "card" =>
Expand Down Expand Up @@ -144,7 +161,7 @@ let make = (
}
}
}
}, (areRequiredFieldsValid, requiredFieldsBody, empty, complete))
}, (areRequiredFieldsValid, requiredFieldsBody, empty, complete, customerMethod))
useSubmitPaymentData(submitCallback)

<div className="flex flex-col overflow-auto h-auto no-scrollbar animate-slowShow">
Expand Down
7 changes: 7 additions & 0 deletions src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ let make = (
let bodyDict = PaymentBody.applePayRedirectBody(~connectors)
processPayment(bodyDict)
}
let value = "Payment Data Filled: New Payment Method"
loggerState.setLogInfo(
~value,
~eventName=PAYMENT_DATA_FILLED,
~paymentMethod="APPLE_PAY",
(),
)
} else {
setApplePayClicked(_ => false)
}
Expand Down
3 changes: 2 additions & 1 deletion src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ let make = (
let bodyDict = PaymentBody.gpayRedirectBody(~connectors)
processPayment(bodyDict)
}
let value = "Payment Data Filled: New Payment Method"
loggerState.setLogInfo(
~value="",
~value,
~eventName=PAYMENT_DATA_FILLED,
~paymentMethod="GOOGLE_PAY",
(),
Expand Down
10 changes: 4 additions & 6 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,12 @@ let handlePostMessageEvents = (
~empty,
~paymentType,
~loggerState: OrcaPaymentPage.OrcaLogger.loggerMake,
~savedMethod=false,
) => {
if complete && paymentType !== "" {
loggerState.setLogInfo(
~value="Payment Data Filled",
~eventName=PAYMENT_DATA_FILLED,
~paymentMethod=paymentType,
(),
)
let value =
"Payment Data Filled" ++ (savedMethod ? ": Saved Payment Method" : ": New Payment Method")
loggerState.setLogInfo(~value, ~eventName=PAYMENT_DATA_FILLED, ~paymentMethod=paymentType, ())
}
handlePostMessage([
("elementType", "payment"->JSON.Encode.string),
Expand Down
6 changes: 0 additions & 6 deletions src/orca-loader/Elements.res
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,6 @@ let make = (
let msg =
[("applePaySyncPayment", true->JSON.Encode.bool)]->Dict.fromArray
mountedIframeRef->Window.iframePostMessage(msg)
logger.setLogInfo(
~value="",
~eventName=PAYMENT_DATA_FILLED,
~paymentMethod="APPLE_PAY",
(),
)
resolve()
})
->catch(err => {
Expand Down
6 changes: 4 additions & 2 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ let make = (
switch timeOut.contents {
| Some(val) => {
clearTimeout(val)
timeOut := Some(setTimeout(() => sendLogs(), 120000))
timeOut := Some(setTimeout(() => sendLogs(), 20000))
}
| None => timeOut := Some(setTimeout(() => sendLogs(), 120000))
| None => timeOut := Some(setTimeout(() => sendLogs(), 20000))
}
beaconApiCall(mainLogFile)
let len = mainLogFile->Array.length
Expand All @@ -521,6 +521,8 @@ let make = (
REDIRECTING_USER,
DISPLAY_BANK_TRANSFER_INFO_PAGE,
DISPLAY_QR_CODE_INFO_PAGE,
DISPLAY_VOUCHER,
LOADER_CHANGED,
SESSIONS_CALL,
RETRIEVE_CALL,
]
Expand Down
Loading