diff --git a/src/CardUtils.res b/src/CardUtils.res index fb4c13e6..0ac6a45e 100644 --- a/src/CardUtils.res +++ b/src/CardUtils.res @@ -701,3 +701,6 @@ let getCardBrandInvalidError = (~cardNumber, ~localeString: LocaleStringTypes.lo | cardBrandValue => localeString.cardBrandConfiguredErrorText(cardBrandValue) } } + +let emitExpiryDate = formattedExpiry => + Utils.messageParentWindow([("expiryDate", formattedExpiry->JSON.Encode.string)]) diff --git a/src/Components/SavedCardItem.res b/src/Components/SavedCardItem.res index ee6f5eab..7cd8d3f3 100644 --- a/src/Components/SavedCardItem.res +++ b/src/Components/SavedCardItem.res @@ -72,16 +72,27 @@ let make = ( | None => () } } - React.useEffect(() => { - isActive ? focusCVC() : () - None - }, [isActive]) let isCard = paymentItem.paymentMethod === "card" let isRenderCvv = isCard && paymentItem.requiresCvv let expiryMonth = paymentItem.card.expiryMonth let expiryYear = paymentItem.card.expiryYear + React.useEffect(() => { + open CardUtils + + if isActive { + // * Focus CVC + focusCVC() + + // * Sending card expiry to handle cases where the card expires before the use date. + `${expiryMonth}${String.substring(~start=2, ~end=4, expiryYear)}` + ->formatCardExpiryNumber + ->emitExpiryDate + } + None + }, [isActive]) + let expiryDate = Date.fromString(`${expiryYear}-${expiryMonth}`) expiryDate->Date.setMonth(expiryDate->Date.getMonth + 1) let currentDate = Date.make() diff --git a/src/Payment.res b/src/Payment.res index befaab78..9eee90fd 100644 --- a/src/Payment.res +++ b/src/Payment.res @@ -113,7 +113,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => { handleInputFocus(~currentRef=expiryRef, ~destinationRef=cvcRef) // * Sending card expiry to handle cases where the card expires before the use date. - Utils.messageParentWindow([("expiryDate", formattedExpiry->JSON.Encode.string)]) + emitExpiryDate(formattedExpiry) } setExpiryValid(formattedExpiry, setIsExpiryValid) setCardExpiry(_ => formattedExpiry)