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: payment data filled event logs for few payment methods #467

Merged
merged 11 commits into from
Jul 4, 2024
4 changes: 4 additions & 0 deletions src/Payments/KlarnaSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let make = (~sessionObj: SessionsType.token) => {
let {iframeId} = Recoil.useRecoilValueFromAtom(keys)
let status = CommonHooks.useScript("https://x.klarnacdn.net/kp/lib/v1/api.js") // Klarna SDK script
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
let (complete, setComplete) = React.useState(_ => false)

let setAreOneClickWalletsRendered = Recoil.useSetRecoilState(areOneClickWalletsRendered)
let (stateJson, setStatesJson) = React.useState(_ => JSON.Encode.null)
Expand All @@ -40,6 +41,8 @@ let make = (~sessionObj: SessionsType.token) => {

PaymentUtils.useStatesJson(setStatesJson)

UtilityHooks.useHandlePostMessages(~complete, ~empty=!complete, ~paymentType="klarna")

React.useEffect(() => {
if (
status === "ready" &&
Expand Down Expand Up @@ -67,6 +70,7 @@ let make = (~sessionObj: SessionsType.token) => {
("param", "paymentloader"->JSON.Encode.string),
("iframeId", iframeId->JSON.Encode.string),
])
setComplete(_ => true)
authorize(
{collect_shipping_address: componentName->getIsExpressCheckoutComponent},
Dict.make()->JSON.Encode.object,
Expand Down
5 changes: 5 additions & 0 deletions src/Payments/PayPal.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ let make = () => {
let isManualRetryEnabled = Recoil.useRecoilValueFromAtom(RecoilAtoms.isManualRetryEnabled)

let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Paypal)
UtilityHooks.useHandlePostMessages(
~complete=paypalClicked,
~empty=!paypalClicked,
~paymentType="paypal",
)
let onPaypalClick = _ev => {
loggerState.setLogInfo(
~value="Paypal Button Clicked",
Expand Down
3 changes: 3 additions & 0 deletions src/Payments/PaypalSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) =
let (loggerState, _setLoggerState) = Recoil.useRecoilState(RecoilAtoms.loggerAtom)
let areOneClickWalletsRendered = Recoil.useSetRecoilState(RecoilAtoms.areOneClickWalletsRendered)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
let (complete, setComplete) = React.useState(_ => false)

let token = sessionObj.token
let orderDetails = sessionObj.orderDetails->getOrderDetails(paymentType)
Expand Down Expand Up @@ -51,6 +52,7 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) =
)

PaymentUtils.useStatesJson(setStatesJson)
UtilityHooks.useHandlePostMessages(~complete, ~empty=!complete, ~paymentType="paypal")

let mountPaypalSDK = () => {
let clientId = sessionObj.token
Expand Down Expand Up @@ -84,6 +86,7 @@ let make = (~sessionObj: SessionsType.token, ~paymentType: CardThemeType.mode) =
~completeAuthorize,
~handleCloseLoader,
~areOneClickWalletsRendered,
~setComplete,
)
})
Window.body->Window.appendChild(paypalScript)
Expand Down
2 changes: 2 additions & 0 deletions src/Payments/PaypalSDKHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let loadPaypalSDK = (
~areOneClickWalletsRendered: (
RecoilAtoms.areOneClickWalletsRendered => RecoilAtoms.areOneClickWalletsRendered
) => unit,
~setComplete,
) => {
loggerState.setLogInfo(
~value="Paypal SDK Button Clicked",
Expand All @@ -32,6 +33,7 @@ let loadPaypalSDK = (
if result {
let paypalWrapper = GooglePayType.getElementById(Utils.document, "paypal-button")
paypalWrapper.innerHTML = ""
setComplete(_ => true)
paypal["Buttons"]({
style: buttonStyle,
fundingSource: paypal["FUNDING"]["PAYPAL"],
Expand Down
Loading