Skip to content

Commit

Permalink
Fix: revert card details (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArushKapoorJuspay authored May 7, 2024
1 parent 5adaf7c commit 31403f8
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 189 deletions.
29 changes: 7 additions & 22 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ let make = (
paymentMethodTypes.required_fields
->Array.concat(creditRequiredFields)
->DynamicFieldsUtils.removeRequiredFieldsDuplicates
->DynamicFieldsUtils.filterCardDetailsIfSavedCardsFlow(isSavedCardFlow)
} else if (
PaymentMethodsRecord.dynamicFieldsEnabledPaymentMethods->Array.includes(paymentMethodType)
) {
paymentMethodTypes.required_fields
} else {
[]
}
}, (paymentMethod, paymentMethodTypes.required_fields, paymentMethodType, isSavedCardFlow))
}, (paymentMethod, paymentMethodTypes.required_fields, paymentMethodType))

let requiredFields = React.useMemo(() => {
requiredFieldsWithBillingDetails->DynamicFieldsUtils.removeBillingDetailsIfUseBillingAddress(
Expand All @@ -71,13 +70,7 @@ let make = (
~isAllStoredCardsHaveName,
(),
)
->DynamicFieldsUtils.updateDynamicFields(
billingAddress,
~paymentMethodListValue,
~paymentMethod,
~isSavedCardFlow,
(),
)
->DynamicFieldsUtils.updateDynamicFields(billingAddress, ())
->Belt.SortArray.stableSortBy(PaymentMethodsRecord.sortPaymentMethodFields)
//<...>//
}, (requiredFields, isAllStoredCardsHaveName, isSavedCardFlow))
Expand Down Expand Up @@ -167,7 +160,7 @@ let make = (
cardRef,
icon,
cardError,
setCardError,
_,
maxCardLength,
) = switch cardProps {
| Some(cardProps) => cardProps
Expand All @@ -183,7 +176,7 @@ let make = (
expiryRef,
_,
expiryError,
setExpiryError,
_,
) = switch expiryProps {
| Some(expiryProps) => expiryProps
| None => defaultExpiryProps
Expand All @@ -199,7 +192,7 @@ let make = (
cvcRef,
_,
cvcError,
setCvcError,
_,
) = switch cvcProps {
| Some(cvcProps) => cvcProps
| None => defaultCvcProps
Expand Down Expand Up @@ -294,17 +287,9 @@ let make = (
~isSavedCardFlow,
~isAllStoredCardsHaveName,
~setRequiredFieldsBody,
~paymentMethodListValue,
)

let submitCallback = DynamicFieldsUtils.useSubmitCallback(
~cardNumber,
~setCardError,
~cardExpiry,
~setExpiryError,
~cvcNumber,
~setCvcError,
)
let submitCallback = DynamicFieldsUtils.useSubmitCallback()
useSubmitPaymentData(submitCallback)

let bottomElement = <InfoElement />
Expand Down Expand Up @@ -352,7 +337,7 @@ let make = (
key={`outside-billing-${index->Int.toString}`}
className="flex flex-col w-full place-content-between"
style={ReactDOMStyle.make(
~marginTop=index !== 0 ? themeObj.spacingGridColumn : "",
~marginTop=index !== 0 || paymentMethod === "card" ? themeObj.spacingGridColumn : "",
~gridColumnGap=themeObj.spacingGridRow,
(),
)}>
Expand Down
11 changes: 9 additions & 2 deletions src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
checkCardExpiry(getCardElementValue(iframeId, "card-expiry"))
| _ => true
}
let cardNetwork = {
if cardBrand != "" {
[("card_network", cardNumber->CardUtils.getCardBrand->JSON.Encode.string)]
} else {
[]
}
}
if validFormat {
let body = switch paymentMode->getPaymentMode {
| Card =>
Expand All @@ -239,7 +246,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
~year,
~cardHolderName="",
~cvcNumber,
~cardBrand,
~cardBrand=cardNetwork,
(),
)
| CardNumberElement =>
Expand All @@ -251,7 +258,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
~year,
~cardHolderName="",
~cvcNumber=localCvcNumber,
~cardBrand,
~cardBrand=cardNetwork,
(),
)
| _ => []
Expand Down
Loading

0 comments on commit 31403f8

Please sign in to comment.