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: added fix for google_pay and apple_pay #630

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
PritishBudhiraja marked this conversation as resolved.
Show resolved Hide resolved

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
Loading