Skip to content

Commit

Permalink
refactor: paypal flow based on payment experience from pml
Browse files Browse the repository at this point in the history
  • Loading branch information
Saksham Sharma authored and Saksham Sharma committed Aug 13, 2024
1 parent b571c55 commit a104fb2
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/Payments/PaymentRequestButtonElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module WalletsSaveDetailsText = {
@react.component
let make = (~sessions, ~walletOptions, ~paymentType) => {
open SessionsType
let methodslist = Recoil.useRecoilValueFromAtom(RecoilAtoms.paymentMethodList)
let dict = sessions->Utils.getDictFromJson
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)

Expand All @@ -47,6 +48,18 @@ let make = (~sessions, ~walletOptions, ~paymentType) => {
() => getPaymentSessionObj(sessionObj.sessionsToken, Paypal),
[sessionObj],
)
let paypalPaymentMethodExperience = React.useMemo(() => {
switch methodslist {
| Loaded(paymentlist) =>
let plist = paymentlist->Utils.getDictFromJson->PaymentMethodsRecord.itemToObjMapper
PaymentMethodsRecord.getPaymentExperienceTypeFromPML(
~paymentMethodList=plist,
~paymentMethodName="wallet",
~paymentMethodType="paypal",
)
| _ => []
}
}, methodslist)
let gPayToken = getPaymentSessionObj(sessionObj.sessionsToken, Gpay)
let applePaySessionObj = itemToObjMapper(dict, ApplePayObject)
let applePayToken = getPaymentSessionObj(applePaySessionObj.sessionsToken, ApplePay)
Expand All @@ -60,6 +73,8 @@ let make = (~sessions, ~walletOptions, ~paymentType) => {
let klarnaTokenObj = SessionsType.getPaymentSessionObj(sessionObj.sessionsToken, Klarna)

let {clientSecret} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)
let isPaypalSDKFlow = paypalPaymentMethodExperience->Array.includes(InvokeSDK)
let isPaypalRedirectFlow = paypalPaymentMethodExperience->Array.includes(RedirectToURL)

<div className="flex flex-col gap-2 h-auto w-full">
{walletOptions
Expand Down Expand Up @@ -94,11 +109,15 @@ let make = (~sessions, ~walletOptions, ~paymentType) => {
<SessionPaymentWrapper type_={Wallet}>
{switch paypalToken {
| OtherTokenOptional(optToken) =>
switch optToken {
| Some(token) => <PaypalSDKLazy sessionObj=token paymentType />
| None => <PayPalLazy />
switch (optToken, isPaypalSDKFlow, isPaypalRedirectFlow) {
| (Some(token), true, _) => <PaypalSDKLazy sessionObj=token paymentType />
| (_, _, true) => <PayPalLazy />
| (_, _, _) => React.null
}
| _ => <PayPalLazy />
| _ =>
<RenderIf condition={isPaypalRedirectFlow}>
<PayPalLazy />
</RenderIf>
}}
</SessionPaymentWrapper>
| ApplePayWallet =>
Expand Down

0 comments on commit a104fb2

Please sign in to comment.