diff --git a/src/Components/DynamicFields.res b/src/Components/DynamicFields.res index e57334d64..17286e39b 100644 --- a/src/Components/DynamicFields.res +++ b/src/Components/DynamicFields.res @@ -29,9 +29,19 @@ let make = ( ~paymentMethodType, ) + let creditPaymentMethodTypes = if paymentMethod === "card" { + PaymentUtils.usePaymentMethodTypeFromList(~paymentMethodListValue, ~paymentMethod, ~paymentMethodType="credit") + } else { + PaymentMethodsRecord.defaultPaymentMethodType + } + let requiredFieldsWithBillingDetails = React.useMemo(() => { if paymentMethod === "card" { + let creditRequiredFields = creditPaymentMethodTypes.required_fields + paymentMethodTypes.required_fields + ->Array.concat(creditRequiredFields) + ->DynamicFieldsUtils.removeRequiredFieldsDuplicates } else if ( PaymentMethodsRecord.dynamicFieldsEnabledPaymentMethods->Array.includes(paymentMethodType) ) { diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index e4a92084e..c0de97724 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -783,3 +783,23 @@ let useAreAllRequiredFieldsPrefilled = ( acc && requiredField.value != "" }) } + +let removeRequiredFieldsDuplicates = ( + requiredFields: array, +) => { + let (_, requiredFields) = requiredFields->Array.reduce(([], []), ( + (requiredFieldKeys, uniqueRequiredFields), + item, + ) => { + let requiredField = item.required_field + + if requiredFieldKeys->Array.includes(requiredField)->not { + requiredFieldKeys->Array.push(requiredField) + uniqueRequiredFields->Array.push(item) + } + + (requiredFieldKeys, uniqueRequiredFields) + }) + + requiredFields +}