Skip to content

Commit

Permalink
fix: HS-132: Added all billing details if any is empty (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay authored Dec 21, 2023
1 parent 77eaa7a commit f7ce161
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
Expand Up @@ -550,33 +550,56 @@ let dynamicFieldsEnabledPaymentMethods = [
"apple_pay",
]

let getIsBillingField = requiredFieldType => {
switch requiredFieldType {
| AddressLine1
| AddressLine2
| AddressCity
| AddressPincode
| AddressState
| AddressCountry(_) => true
| _ => false
}
}

let getIsAnyBillingDetailEmpty = (requiredFieldsValues: array<Js.Json.t>) => {
requiredFieldsValues->Js.Array2.reduce((acc, item) => {
let requiredField = item->Utils.getDictFromJson->getRequiredFieldsFromJson
if getIsBillingField(requiredField.field_type) {
requiredField.value === "" || acc
} else {
acc
}
}, false)
}

let getPaymentMethodFields = (
paymentMethod,
requiredFields,
~isSavedCardFlow=false,
~isAllStoredCardsHaveName=false,
(),
) => {
let requiredFieldsArr =
requiredFields
->Utils.getDictFromJson
->Js.Dict.values
->Js.Array2.map(item => {
let requiredField = item->Utils.getDictFromJson->getRequiredFieldsFromJson
if requiredField.value === "" {
if (
isSavedCardFlow &&
requiredField.display_name === "card_holder_name" &&
isAllStoredCardsHaveName
) {
None
} else {
requiredField.field_type
}
} else {
let requiredFieldsValues = requiredFields->Utils.getDictFromJson->Js.Dict.values
let isAnyBillingDetailEmpty = requiredFieldsValues->getIsAnyBillingDetailEmpty
let requiredFieldsArr = requiredFieldsValues->Js.Array2.map(item => {
let requiredField = item->Utils.getDictFromJson->getRequiredFieldsFromJson
let isShowBillingField = getIsBillingField(requiredField.field_type) && isAnyBillingDetailEmpty

if requiredField.value === "" || isShowBillingField {
if (
isSavedCardFlow &&
requiredField.display_name === "card_holder_name" &&
isAllStoredCardsHaveName
) {
None
} else {
requiredField.field_type
}
})
} else {
None
}
})
requiredFieldsArr->Js.Array2.concat(
(
paymentMethodsFields
Expand Down

0 comments on commit f7ce161

Please sign in to comment.