diff --git a/src/PaymentElement.res b/src/PaymentElement.res index a3d4f0fa..d5fd4364 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -19,7 +19,6 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod displaySavedPaymentMethods, sdkHandleConfirmPayment, } = Recoil.useRecoilValueFromAtom(optionAtom) - let logger = HyperLogger.make(~source=Elements(Payment)) let {themeObj, localeString} = Recoil.useRecoilValueFromAtom(configAtom) let optionAtomValue = Recoil.useRecoilValueFromAtom(optionAtom) let paymentMethodList = Recoil.useRecoilValueFromAtom(paymentMethodList) @@ -158,19 +157,11 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod googlePayThirdPartySessionObj.sessionsToken, Gpay, ) - let paypalPaymentMethodExperience = React.useMemo(() => { - PaymentMethodsRecord.getPaymentExperienceTypeFromPML( - ~paymentMethodList=paymentMethodListValue, - ~paymentMethodName="wallet", - ~paymentMethodType="paypal", - ) - }, [paymentMethodListValue]) - let paypalToken = React.useMemo( - () => SessionsType.getPaymentSessionObj(sessionObj.sessionsToken, Paypal), - [sessionObj], - ) - let isPaypalSDKFlow = paypalPaymentMethodExperience->Array.includes(InvokeSDK) - let isPaypalRedirectFlow = paypalPaymentMethodExperience->Array.includes(RedirectToURL) + let { + paypalToken, + isPaypalSDKFlow, + isPaypalRedirectFlow, + } = PayPalHelpers.usePaymentMethodExperience(~paymentMethodListValue, ~sessionObj) React.useEffect(() => { switch paymentMethodList { @@ -374,7 +365,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod | OtherTokenOptional(optToken) => switch (optToken, isPaypalSDKFlow, isPaypalRedirectFlow) { | (Some(_token), true, _) => { - logger.setLogInfo( + loggerState.setLogInfo( ~value="PayPal Invoke SDK Flow in Tabs", ~eventName=PAYPAL_SDK_FLOW, ) diff --git a/src/Payments/PayPalHelpers.res b/src/Payments/PayPalHelpers.res new file mode 100644 index 00000000..dc405d12 --- /dev/null +++ b/src/Payments/PayPalHelpers.res @@ -0,0 +1,31 @@ +open PaymentMethodsRecord +open SessionsType + +type paypalExperienceData = { + paypalToken: optionalTokenType, + isPaypalSDKFlow: bool, + isPaypalRedirectFlow: bool, +} + +let usePaymentMethodExperience = (~paymentMethodListValue, ~sessionObj: sessions) => { + let paypalPaymentMethodExperience = React.useMemo(() => { + getPaymentExperienceTypeFromPML( + ~paymentMethodList=paymentMethodListValue, + ~paymentMethodName="wallet", + ~paymentMethodType="paypal", + ) + }, [paymentMethodListValue]) + + let paypalToken = React.useMemo( + () => getPaymentSessionObj(sessionObj.sessionsToken, Paypal), + [sessionObj], + ) + let isPaypalSDKFlow = paypalPaymentMethodExperience->Array.includes(InvokeSDK) + let isPaypalRedirectFlow = paypalPaymentMethodExperience->Array.includes(RedirectToURL) + + { + paypalToken, + isPaypalSDKFlow, + isPaypalRedirectFlow, + } +} diff --git a/src/Payments/PaymentRequestButtonElement.res b/src/Payments/PaymentRequestButtonElement.res index 7a67528c..7ea12207 100644 --- a/src/Payments/PaymentRequestButtonElement.res +++ b/src/Payments/PaymentRequestButtonElement.res @@ -44,17 +44,13 @@ let make = (~sessions, ~walletOptions, ~paymentType) => { let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue) let sessionObj = React.useMemo(() => itemToObjMapper(dict, Others), [dict]) - let paypalToken = React.useMemo( - () => getPaymentSessionObj(sessionObj.sessionsToken, Paypal), - [sessionObj], - ) - let paypalPaymentMethodExperience = React.useMemo(() => { - PaymentMethodsRecord.getPaymentExperienceTypeFromPML( - ~paymentMethodList=paymentMethodListValue, - ~paymentMethodName="wallet", - ~paymentMethodType="paypal", - ) - }, [paymentMethodListValue]) + + let { + paypalToken, + isPaypalSDKFlow, + isPaypalRedirectFlow, + } = PayPalHelpers.usePaymentMethodExperience(~paymentMethodListValue, ~sessionObj) + let gPayToken = getPaymentSessionObj(sessionObj.sessionsToken, Gpay) let applePaySessionObj = itemToObjMapper(dict, ApplePayObject) let applePayToken = getPaymentSessionObj(applePaySessionObj.sessionsToken, ApplePay) @@ -70,8 +66,6 @@ let make = (~sessions, ~walletOptions, ~paymentType) => { let {clientSecret} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys) let options = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom) - let isPaypalSDKFlow = paypalPaymentMethodExperience->Array.includes(InvokeSDK) - let isPaypalRedirectFlow = paypalPaymentMethodExperience->Array.includes(RedirectToURL)