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

fix: info element added & logs addition #471

Merged
merged 9 commits into from
Jul 4, 2024
57 changes: 39 additions & 18 deletions src/Payments/AddBankDetails.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Loader = {
let {themeObj} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
<div className="w-full flex items-center justify-center">
<div className="w-8 h-8 animate-spin" style={color: themeObj.colorTextSecondary}>
<Icon size=32 name="loader" />
<Icon size=28 name="loader" />
</div>
</div>
}
Expand All @@ -20,6 +20,7 @@ let make = (~paymentMethodType) => {
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
let setShowFields = Recoil.useSetRecoilState(RecoilAtoms.showCardFieldsAtom)
let (showLoader, setShowLoader) = React.useState(() => false)
let logger = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)

let pmAuthConnectorsArr =
PmAuthConnectorUtils.findPmAuthAllPMAuthConnectors(
Expand All @@ -41,6 +42,7 @@ let make = (~paymentMethodType) => {
~paymentMethodType,
~publishableKey,
~setOptionValue,
~optLogger=Some(logger),
)
->then(_ => {
handlePostMessage([("fullscreen", false->JSON.Encode.bool)])
Expand Down Expand Up @@ -81,24 +83,43 @@ let make = (~paymentMethodType) => {
~iframeId,
~paymentMethodType,
~pmAuthConnectorsArr,
~optLogger=Some(logger),
)->ignore
}

<button
onClick={_ => onClickHandler()}
disabled={showLoader}
style={
width: "100%",
padding: "20px",
cursor: "pointer",
borderRadius: themeObj.borderRadius,
borderColor: themeObj.borderColor,
borderWidth: "2px",
}>
{if showLoader {
<Loader />
} else {
{React.string("Add Bank Details")}
}}
</button>
<>
<button
onClick={_ => onClickHandler()}
disabled={showLoader}
style={
width: "100%",
padding: "10px",
borderRadius: themeObj.borderRadius,
borderColor: themeObj.borderColor,
borderWidth: "2px",
}>
{if showLoader {
<Loader />
} else {
{React.string("Add Bank Details")}
}}
</button>
<div className="opacity-50 text-xs mb-2 text-left mt-8" style={color: themeObj.colorText}>
{React.string(
`${paymentMethodType->String.toUpperCase} Bank Debit has 2 steps to pay. Please follow the instructions:`,
)}
<ul className="list-disc px-5 py-2">
<li>
{React.string(
"Please Click on Add Bank Details and proceed to add your bank account details.",
)}
</li>
<li>
{React.string(
"Post verification, you will see your account added. You can select the account that you want to pay with and click on the pay button.",
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
)}
</li>
</ul>
</div>
</>
}
16 changes: 12 additions & 4 deletions src/Payments/PlaidSDKIframe.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
let make = () => {
open Utils

let logger = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)
let (linkToken, setLinkToken) = React.useState(_ => "")
let (isReady, setIsReady) = React.useState(_ => false)
let (pmAuthConnectorsArr, setPmAuthConnectorsArr) = React.useState(_ => [])
let (publishableKey, setPublishableKey) = React.useState(_ => "")
let (paymentId, setPaymentId) = React.useState(_ => "")
let logger = React.useMemo(() => {
OrcaLogger.make(~source=Loader, ~clientSecret=paymentId, ~merchantId=publishableKey, ())
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
}, (publishableKey, paymentId))

React.useEffect0(() => {
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
let handle = (ev: Window.event) => {
let json = ev.data->JSON.parseExn

let metaData = json->getDictFromJson->getDictFromDict("metadata")
let linkToken = metaData->getString("linkToken", "")
if linkToken->String.length > 0 {
Expand All @@ -22,9 +24,12 @@ let make = () => {

setLinkToken(_ => linkToken)
setPmAuthConnectorsArr(_ => pmAuthConnectorArray)
setPublishableKey(_ => metaData->getString("payment_id", ""))
setPaymentId(_ => metaData->getString("publishableKey", ""))
}
}
Window.addEventListener("message", handle)
handlePostMessage([("iframeMountedCallback", true->JSON.Encode.bool)])
Some(() => {Window.removeEventListener("message", handle)})
})

Expand All @@ -46,6 +51,9 @@ let make = () => {
if isReady && linkToken->String.length > 0 {
let handler = Plaid.create({
token: linkToken,
onLoad: _ => {
logger.setLogInfo(~value="Plaid SDK Loaded", ~eventName=PLAID_SDK_LOADED, ())
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
},
onSuccess: (publicToken, _) => {
handlePostMessage([
("isPlaid", true->JSON.Encode.bool),
Expand All @@ -66,7 +74,7 @@ let make = () => {
}

None
}, (isReady, linkToken))
}, (isReady, linkToken, logger))

<div
className="PlaidIframe h-screen w-screen bg-black/40 backdrop-blur-sm m-auto"
Expand Down
80 changes: 78 additions & 2 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@ let callAuthLink = (
~paymentMethodType,
~pmAuthConnectorsArr,
~iframeId,
~optLogger,
) => {
open Promise
let endpoint = ApiEndpoint.getApiEndPoint()
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -1745,7 +1746,18 @@ let callAuthLink = (
if statusCode->String.charAt(0) !== "2" {
res
->Fetch.Response.json
->then(_ => {
->then(data => {
logApi(
~optLogger,
~url=uri,
~data,
~statusCode,
~apiLogType=Err,
~eventName=PAYMENT_METHODS_AUTH_LINK,
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
~logType=ERROR,
~logCategory=API,
(),
)
JSON.Encode.null->resolve
})
} else {
Expand All @@ -1756,6 +1768,8 @@ let callAuthLink = (
[
("linkToken", data->getDictFromJson->getString("link_token", "")->JSON.Encode.string),
("pmAuthConnectorArray", pmAuthConnectorsArr->Identity.anyTypeToJson),
("payment_id", clientSecret->Option.getOr("")->getPaymentId->JSON.Encode.string),
("publishableKey", publishableKey->JSON.Encode.string),
]->getJsonFromArrayOfJson

handlePostMessage([
Expand All @@ -1764,11 +1778,31 @@ let callAuthLink = (
("iframeId", iframeId->JSON.Encode.string),
("metadata", metaData),
])
logApi(
~optLogger,
~url=uri,
~statusCode,
~apiLogType=Response,
~eventName=PAYMENT_METHODS_AUTH_LINK,
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
~logType=INFO,
~logCategory=API,
(),
)
JSON.Encode.null->resolve
})
}
})
->catch(e => {
logApi(
~optLogger,
~url=uri,
~apiLogType=NoResponse,
~eventName=PAYMENT_METHODS_AUTH_LINK,
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
~logType=ERROR,
~logCategory=API,
~data={e->formatException},
(),
)
Console.log2("Unable to retrieve payment_methods auth/link because of ", e)
JSON.Encode.null->resolve
})
Expand All @@ -1780,6 +1814,7 @@ let callAuthExchange = (
~paymentMethodType,
~publishableKey,
~setOptionValue: (PaymentType.options => PaymentType.options) => unit,
~optLogger,
) => {
open Promise
open PaymentType
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -1808,10 +1843,31 @@ let callAuthExchange = (
if statusCode->String.charAt(0) !== "2" {
res
->Fetch.Response.json
->then(_ => {
->then(data => {
logApi(
~optLogger,
~url=uri,
~data,
~statusCode,
~apiLogType=Err,
~eventName=PAYMENT_METHODS_AUTH_EXCHANGE,
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
~logType=ERROR,
~logCategory=API,
(),
)
JSON.Encode.null->resolve
})
} else {
logApi(
~optLogger,
~url=uri,
~statusCode,
~apiLogType=Response,
~eventName=PAYMENT_METHODS_AUTH_EXCHANGE,
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
~logType=INFO,
~logCategory=API,
(),
)
fetchCustomerPaymentMethodList(
~clientSecret=clientSecret->Option.getOr(""),
~publishableKey,
Expand All @@ -1831,6 +1887,16 @@ let callAuthExchange = (
JSON.Encode.null->resolve
})
->catch(e => {
logApi(
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
~optLogger,
~url=uri,
~apiLogType=NoResponse,
~eventName=CUSTOMER_PAYMENT_METHODS_CALL,
~logType=ERROR,
~logCategory=API,
~data={e->formatException},
(),
)
Console.log2(
"Unable to retrieve customer/payment_methods after auth/exchange because of ",
e,
Expand All @@ -1840,6 +1906,16 @@ let callAuthExchange = (
}
})
->catch(e => {
logApi(
~optLogger,
~url=uri,
~apiLogType=NoResponse,
~eventName=PAYMENT_METHODS_AUTH_EXCHANGE,
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved
~logType=ERROR,
~logCategory=API,
~data={e->formatException},
(),
)
Console.log2("Unable to retrieve payment_methods auth/exchange because of ", e)
JSON.Encode.null->resolve
})
Expand Down
7 changes: 7 additions & 0 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ type eventName =
| POLL_STATUS_CALL
| COMPLETE_AUTHORIZE_CALL_INIT
| COMPLETE_AUTHORIZE_CALL
| PLAID_SDK_LOADED
| PAYMENT_METHODS_AUTH_EXCHANGE
| PAYMENT_METHODS_AUTH_LINK

let eventNameToStrMapper = eventName => {
switch eventName {
Expand Down Expand Up @@ -144,6 +147,9 @@ let eventNameToStrMapper = eventName => {
| POLL_STATUS_CALL => "POLL_STATUS_CALL"
| COMPLETE_AUTHORIZE_CALL_INIT => "COMPLETE_AUTHORIZE_CALL_INIT"
| COMPLETE_AUTHORIZE_CALL => "COMPLETE_AUTHORIZE_CALL"
| PLAID_SDK_LOADED => "PLAID_SDK_LOADED"
| PAYMENT_METHODS_AUTH_EXCHANGE => "PAYMENT_METHODS_AUTH_EXCHANGE"
| PAYMENT_METHODS_AUTH_LINK => "PAYMENT_METHODS_AUTH_LINK"
}
}

Expand Down Expand Up @@ -576,6 +582,7 @@ let make = (~sessionId=?, ~source: source, ~clientSecret=?, ~merchantId=?, ~meta
RETRIEVE_CALL,
DISPLAY_THREE_DS_SDK,
APPLE_PAY_FLOW,
PLAID_SDK_LOADED,
]
arrayOfLogs
->Array.find(log => {
Expand Down
Loading