diff --git a/src/Components/DynamicFields.res b/src/Components/DynamicFields.res index 4310b59a5..96a4af127 100644 --- a/src/Components/DynamicFields.res +++ b/src/Components/DynamicFields.res @@ -21,16 +21,11 @@ let make = ( let {billingAddress} = Recoil.useRecoilValueFromAtom(optionAtom) //<...>// - let paymentMethodTypes = React.useMemo3(() => { - PaymentMethodsRecord.getPaymentMethodTypeFromList( - ~list, - ~paymentMethod, - ~paymentMethodType=PaymentUtils.getPaymentMethodName( - ~paymentMethodType=paymentMethod, - ~paymentMethodName=paymentMethodType, - ), - )->Belt.Option.getWithDefault(PaymentMethodsRecord.defaultPaymentMethodType) - }, (list, paymentMethod, paymentMethodType)) + let paymentMethodTypes = DynamicFieldsUtils.usePaymentMethodTypeFromList( + ~list, + ~paymentMethod, + ~paymentMethodType, + ) let requiredFieldsWithBillingDetails = React.useMemo3(() => { if paymentMethod === "card" { diff --git a/src/PaymentElement.res b/src/PaymentElement.res index e61570840..2408187d9 100644 --- a/src/PaymentElement.res +++ b/src/PaymentElement.res @@ -108,7 +108,19 @@ let make = ( None }, [savedMethods]) - let (walletList, paymentOptionsList, actualList) = React.useMemo4(() => { + let areAllGooglePayRequiredFieldsPrefilled = DynamicFieldsUtils.areAllRequiredFieldsPrefilled( + ~list, + ~paymentMethod="wallet", + ~paymentMethodType="google_pay", + ) + + let areAllApplePayRequiredFieldsPrefilled = DynamicFieldsUtils.areAllRequiredFieldsPrefilled( + ~list, + ~paymentMethod="wallet", + ~paymentMethodType="apple_pay", + ) + + let (walletList, paymentOptionsList, actualList) = React.useMemo6(() => { switch methodslist { | Loaded(paymentlist) => let paymentOrder = @@ -119,6 +131,8 @@ let make = ( ~order=paymentOrder, ~showApplePay=isApplePayReady, ~showGooglePay=isGooglePayReady, + ~areAllGooglePayRequiredFieldsPrefilled, + ~areAllApplePayRequiredFieldsPrefilled, ) ( wallets->Utils.removeDuplicate, @@ -131,7 +145,14 @@ let make = ( : ([], [], []) | _ => ([], [], []) } - }, (methodslist, paymentMethodOrder, isApplePayReady, isGooglePayReady)) + }, ( + methodslist, + paymentMethodOrder, + isApplePayReady, + isGooglePayReady, + areAllGooglePayRequiredFieldsPrefilled, + areAllApplePayRequiredFieldsPrefilled, + )) React.useEffect4(() => { switch methodslist { diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index d6a680dfa..f9eb770a1 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -695,3 +695,24 @@ let useSubmitCallback = () => { } }, (line1, line2, state, city, postalCode)) } + +let usePaymentMethodTypeFromList = (~list, ~paymentMethod, ~paymentMethodType) => { + React.useMemo3(() => { + PaymentMethodsRecord.getPaymentMethodTypeFromList( + ~list, + ~paymentMethod, + ~paymentMethodType=PaymentUtils.getPaymentMethodName( + ~paymentMethodType=paymentMethod, + ~paymentMethodName=paymentMethodType, + ), + )->Belt.Option.getWithDefault(PaymentMethodsRecord.defaultPaymentMethodType) + }, (list, paymentMethod, paymentMethodType)) +} + +let areAllRequiredFieldsPrefilled = (~list, ~paymentMethod, ~paymentMethodType) => { + let paymentMethodTypes = usePaymentMethodTypeFromList(~list, ~paymentMethod, ~paymentMethodType) + + paymentMethodTypes.required_fields->Js.Array2.reduce((acc, requiredField) => { + acc && requiredField.value != "" + }, true) +} diff --git a/src/Utilities/PaymentUtils.res b/src/Utilities/PaymentUtils.res index a26b8efc3..3ceb7a728 100644 --- a/src/Utilities/PaymentUtils.res +++ b/src/Utilities/PaymentUtils.res @@ -3,6 +3,8 @@ let paymentListLookupNew = ( ~order, ~showApplePay, ~showGooglePay, + ~areAllGooglePayRequiredFieldsPrefilled, + ~areAllApplePayRequiredFieldsPrefilled, ) => { let pmList = list->PaymentMethodsRecord.buildFromPaymentList let walletsList = [] @@ -26,14 +28,16 @@ let paymentListLookupNew = ( let applePayFields = pmList->Js.Array2.find(item => item.paymentMethodName === "apple_pay") switch googlePayFields { | Some(val) => - if val.fields->Js.Array2.length > 0 && showGooglePay { + if ( + val.fields->Js.Array2.length > 0 && showGooglePay && !areAllGooglePayRequiredFieldsPrefilled + ) { walletToBeDisplayedInTabs->Js.Array2.push("google_pay")->ignore } | None => () } switch applePayFields { | Some(val) => - if val.fields->Js.Array2.length > 0 && showApplePay { + if val.fields->Js.Array2.length > 0 && showApplePay && !areAllApplePayRequiredFieldsPrefilled { walletToBeDisplayedInTabs->Js.Array2.push("apple_pay")->ignore } | None => ()