Skip to content

Commit

Permalink
chore: emitting expiry via saved cards screen (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
aritro2002 authored Dec 10, 2024
1 parent 8545f77 commit d07622b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,6 @@ let getCardBrandInvalidError = (~cardNumber, ~localeString: LocaleStringTypes.lo
| cardBrandValue => localeString.cardBrandConfiguredErrorText(cardBrandValue)
}
}

let emitExpiryDate = formattedExpiry =>
Utils.messageParentWindow([("expiryDate", formattedExpiry->JSON.Encode.string)])
19 changes: 15 additions & 4 deletions src/Components/SavedCardItem.res
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d07622b

Please sign in to comment.