Skip to content

Commit

Permalink
fix: combined Dynamic Fields for credit and debit
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay committed May 6, 2024
1 parent 2e7ef3b commit f377be0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand Down
20 changes: 20 additions & 0 deletions src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,23 @@ let useAreAllRequiredFieldsPrefilled = (
acc && requiredField.value != ""
})
}

let removeRequiredFieldsDuplicates = (
requiredFields: array<PaymentMethodsRecord.required_fields>,
) => {
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
}

0 comments on commit f377be0

Please sign in to comment.