Skip to content

Commit

Permalink
fix: HS-111: Added billing name to address element (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
prafulkoppalkar authored Feb 15, 2024
1 parent f986a58 commit 426415a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,13 @@ let make = (
disabled=false
options=currencyArr
/>
| FullName =>
<FullNamePaymentInput
paymentType
customFieldName={item->getCustomFieldName}
optionalRequiredFields={Some(requiredFields)}
/>
| Email
| FullName
| InfoElement
| Country
| Bank
Expand Down Expand Up @@ -525,17 +530,9 @@ let make = (
key={`inside-billing-${index->Js.Int.toString}`}
className="flex flex-col w-full place-content-between">
{switch item {
| FullName =>
<FullNamePaymentInput
paymentType
customFieldName={item->getCustomFieldName}
optionalRequiredFields={Some(requiredFields)}
/>
| BillingName =>
<BillingNamePaymentInput
paymentType
customFieldName={item->getCustomFieldName}
optionalRequiredFields={Some(requiredFields)}
paymentType optionalRequiredFields={Some(requiredFields)}
/>
| Email => <EmailPaymentInput paymentType />
| PhoneNumber => <PhoneNumberPaymentInput />
Expand Down Expand Up @@ -728,6 +725,7 @@ let make = (
| CardCvc
| CardExpiryAndCvc
| Currency(_)
| FullName
| None => React.null
}}
</div>
Expand Down
21 changes: 18 additions & 3 deletions src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let getName = (item: PaymentMethodsRecord.required_fields, field: RecoilAtomType
let countryNames = Utils.getCountryNames(Country.country)

let billingAddressFields: array<PaymentMethodsRecord.paymentMethodsFields> = [
BillingName,
AddressLine1,
AddressLine2,
AddressCity,
Expand All @@ -25,6 +26,7 @@ let billingAddressFields: array<PaymentMethodsRecord.paymentMethodsFields> = [

let isBillingAddressFieldType = (fieldType: PaymentMethodsRecord.paymentMethodsFields) => {
switch fieldType {
| BillingName
| AddressLine1
| AddressLine2
| AddressCity
Expand Down Expand Up @@ -429,6 +431,7 @@ let useRequiredFieldsBody = (
->Belt.Option.getWithDefault(Country.defaultTimeZone)
countryCode.isoAlpha2
}
| BillingName => billingName.value
| CardNumber => cardNumber->CardUtils.clearSpaces
| CardExpiryMonth =>
let (month, _) = CardUtils.getExpiryDates(cardExpiry)
Expand All @@ -444,7 +447,6 @@ let useRequiredFieldsBody = (
| CardExpiryMonthAndYear
| CardExpiryAndCvc
| FullName
| BillingName
| None => ""
}
}
Expand All @@ -453,8 +455,20 @@ let useRequiredFieldsBody = (
if billingAddress.isUseBillingAddress {
billingAddressFields->Js.Array2.reduce((acc, item) => {
let value = item->getFieldValueFromFieldType
let path = item->getBillingAddressPathFromFieldType
acc->Js.Dict.set(path, value->Js.Json.string)
if item === BillingName {
let arr = value->Js.String2.split(" ")
acc->Js.Dict.set(
"billing.address.first_name",
arr->Belt.Array.get(0)->Belt.Option.getWithDefault("")->Js.Json.string,
)
acc->Js.Dict.set(
"billing.address.last_name",
arr->Belt.Array.get(1)->Belt.Option.getWithDefault("")->Js.Json.string,
)
} else {
let path = item->getBillingAddressPathFromFieldType
acc->Js.Dict.set(path, value->Js.Json.string)
}
acc
}, requiredFieldsBody)
} else {
Expand Down Expand Up @@ -514,6 +528,7 @@ let useRequiredFieldsBody = (

let isFieldTypeToRenderOutsideBilling = (fieldType: PaymentMethodsRecord.paymentMethodsFields) => {
switch fieldType {
| FullName
| CardNumber
| CardExpiryMonth
| CardExpiryYear
Expand Down

0 comments on commit 426415a

Please sign in to comment.