Skip to content

Commit

Permalink
fix: added fix for google_pay and apple_pay
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay authored and PritishBudhiraja committed Sep 26, 2024
1 parent d409249 commit fefc784
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
46 changes: 24 additions & 22 deletions src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,30 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
}
None
}, [sessionsObj])

React.useEffect(() => {
if layoutClass.\"type" == Tabs {
let isCard = cardOptions->Array.includes(selectedOption)
if !isCard {
let (cardArr, dropdownArr) = CardUtils.swapCardOption(
cardOptions,
dropDownOptions,
selectedOption,
)
setCardOptions(_ => cardArr)
setDropDownOptions(_ => dropdownArr)
}
}
if selectedOption !== "" {
loggerState.setLogInfo(
~value="",
~eventName=PAYMENT_METHOD_CHANGED,
~paymentMethod=selectedOption->String.toUpperCase,
)
}
None
}, (selectedOption, cardOptions, dropDownOptions))

React.useEffect(() => {
let cardsCount: int = cardsToRender(cardsContainerWidth)
let cardOpts = Array.slice(~start=0, ~end=cardsCount, paymentOptions)
Expand Down Expand Up @@ -248,28 +272,6 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
)
None
}, (layoutClass.defaultCollapsed, paymentOptions, paymentMethodList, selectedOption))
React.useEffect(() => {
if layoutClass.\"type" == Tabs {
let isCard: bool = cardOptions->Array.includes(selectedOption)
if !isCard {
let (cardArr, dropdownArr) = CardUtils.swapCardOption(
cardOptions,
dropDownOptions,
selectedOption,
)
setCardOptions(_ => cardArr)
setDropDownOptions(_ => dropdownArr)
}
}
if selectedOption !== "" {
loggerState.setLogInfo(
~value="",
~eventName=PAYMENT_METHOD_CHANGED,
~paymentMethod=selectedOption->String.toUpperCase,
)
}
None
}, [selectedOption])
let checkRenderOrComp = () => {
walletOptions->Array.includes("paypal") || isShowOrPayUsing
}
Expand Down
28 changes: 16 additions & 12 deletions src/Utilities/PaymentUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ let paymentListLookupNew = (
~isShowKlarnaOneClick,
~isKlarnaSDKFlow,
~paymentMethodListValue: PaymentMethodsRecord.paymentMethodList,
~areAllApplePayRequiredFieldsPrefilled,
~areAllGooglePayRequiredFieldsPrefilled,
~isApplePayReady,
~isGooglePayReady,
~shouldDisplayApplePayInTabs,
) => {
let pmList = list->PaymentMethodsRecord.buildFromPaymentList
let walletsList = []
Expand All @@ -33,11 +32,7 @@ let paymentListLookupNew = (
]
let otherPaymentList = []

if (
!paymentMethodListValue.collect_billing_details_from_wallets &&
!areAllApplePayRequiredFieldsPrefilled &&
isApplePayReady
) {
if shouldDisplayApplePayInTabs {
walletToBeDisplayedInTabs->Array.push("apple_pay")
}

Expand Down Expand Up @@ -346,17 +341,22 @@ let useGetPaymentMethodList = (~paymentOptions, ~paymentType, ~sessions) => {
let paymentOrder =
paymentOrder->Array.length > 0 ? paymentOrder : PaymentModeType.defaultOrder
let plist = paymentlist->getDictFromJson->PaymentMethodsRecord.itemToObjMapper

let shouldDisplayApplePayInTabs =
!paymentMethodListValue.collect_billing_details_from_wallets &&
!areAllApplePayRequiredFieldsPrefilled &&
isApplePayReady

let (wallets, otherOptions) =
plist->paymentListLookupNew(
~order=paymentOrder,
~isShowPaypal=optionAtomValue.wallets.payPal === Auto,
~isShowKlarnaOneClick=optionAtomValue.wallets.klarna === Auto,
~isKlarnaSDKFlow,
~paymentMethodListValue=plist,
~areAllApplePayRequiredFieldsPrefilled,
~areAllGooglePayRequiredFieldsPrefilled,
~isApplePayReady,
~isGooglePayReady,
~shouldDisplayApplePayInTabs,
)

let klarnaPaymentMethodExperience = PaymentMethodsRecord.getPaymentExperienceTypeFromPML(
Expand All @@ -368,9 +368,13 @@ let useGetPaymentMethodList = (~paymentOptions, ~paymentType, ~sessions) => {
let isKlarnaInvokeSDKExperience = klarnaPaymentMethodExperience->Array.includes(InvokeSDK)

let filterPaymentMethods = (paymentOptionsList: array<string>) => {
paymentOptionsList->Array.filter(paymentOptionsName =>
!(paymentOptionsName === "klarna" && isKlarnaSDKFlow && isKlarnaInvokeSDKExperience)
)
paymentOptionsList->Array.filter(paymentOptionsName => {
switch paymentOptionsName {
| "klarna" => !(isKlarnaSDKFlow && isKlarnaInvokeSDKExperience)
| "apple_pay" => shouldDisplayApplePayInTabs
| _ => true
}
})
}

(
Expand Down

0 comments on commit fefc784

Please sign in to comment.