diff --git a/src/Components/DynamicFields.res b/src/Components/DynamicFields.res index e57334d64..493702c45 100644 --- a/src/Components/DynamicFields.res +++ b/src/Components/DynamicFields.res @@ -29,9 +29,19 @@ let make = ( ~paymentMethodType, ) + let creditPaymentMethodTypes = PaymentUtils.usePaymentMethodTypeFromList( + ~paymentMethodListValue, + ~paymentMethod, + ~paymentMethodType="credit", + ) + 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 +}