From 95d7bb32164611bdcc76fb1232e17b4d22fe220a Mon Sep 17 00:00:00 2001 From: ArushKapoorJuspay <121166031+ArushKapoorJuspay@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:26:31 +0530 Subject: [PATCH] fix: added fix for google_pay and apple_pay (#630) --- src/PaymentElement.res | 46 ++++++++++++++++++---------------- src/Utilities/PaymentUtils.res | 28 ++++++++++++--------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/PaymentElement.res b/src/PaymentElement.res index 7f0928ff6..c4580a648 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -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) @@ -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 } diff --git a/src/Utilities/PaymentUtils.res b/src/Utilities/PaymentUtils.res index 108f3f8c2..6422fb090 100644 --- a/src/Utilities/PaymentUtils.res +++ b/src/Utilities/PaymentUtils.res @@ -7,10 +7,9 @@ let paymentListLookupNew = ( ~isShowKlarnaOneClick, ~isKlarnaSDKFlow, ~paymentMethodListValue: PaymentMethodsRecord.paymentMethodList, - ~areAllApplePayRequiredFieldsPrefilled, ~areAllGooglePayRequiredFieldsPrefilled, - ~isApplePayReady, ~isGooglePayReady, + ~shouldDisplayApplePayInTabs, ) => { let pmList = list->PaymentMethodsRecord.buildFromPaymentList let walletsList = [] @@ -33,11 +32,7 @@ let paymentListLookupNew = ( ] let otherPaymentList = [] - if ( - !paymentMethodListValue.collect_billing_details_from_wallets && - !areAllApplePayRequiredFieldsPrefilled && - isApplePayReady - ) { + if shouldDisplayApplePayInTabs { walletToBeDisplayedInTabs->Array.push("apple_pay") } @@ -346,6 +341,12 @@ 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, @@ -353,10 +354,9 @@ let useGetPaymentMethodList = (~paymentOptions, ~paymentType, ~sessions) => { ~isShowKlarnaOneClick=optionAtomValue.wallets.klarna === Auto, ~isKlarnaSDKFlow, ~paymentMethodListValue=plist, - ~areAllApplePayRequiredFieldsPrefilled, ~areAllGooglePayRequiredFieldsPrefilled, - ~isApplePayReady, ~isGooglePayReady, + ~shouldDisplayApplePayInTabs, ) let klarnaPaymentMethodExperience = PaymentMethodsRecord.getPaymentExperienceTypeFromPML( @@ -368,9 +368,13 @@ let useGetPaymentMethodList = (~paymentOptions, ~paymentType, ~sessions) => { let isKlarnaInvokeSDKExperience = klarnaPaymentMethodExperience->Array.includes(InvokeSDK) let filterPaymentMethods = (paymentOptionsList: array) => { - paymentOptionsList->Array.filter(paymentOptionsName => - !(paymentOptionsName === "klarna" && isKlarnaSDKFlow && isKlarnaInvokeSDKExperience) - ) + paymentOptionsList->Array.filter(paymentOptionsName => { + switch paymentOptionsName { + | "klarna" => !(isKlarnaSDKFlow && isKlarnaInvokeSDKExperience) + | "apple_pay" => shouldDisplayApplePayInTabs + | _ => true + } + }) } (