Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trim card CVC number if it exceeds max length of new card brand #840

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ let maxCardLength = cardBrand => {
Array.reduce(obj.length, 0, (acc, val) => max(acc, val))
}

let maxCvcLength = cardBrand => {
let obj = getobjFromCardPattern(cardBrand)
obj.maxCVCLength
}

let isCardLengthValid = (cardBrand, cardNumberLength) => {
let obj = getobjFromCardPattern(cardBrand)
Array.includes(obj.length, cardNumberLength)
Expand Down
15 changes: 15 additions & 0 deletions src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
None
}, (cvcNumber, cardNumber))

React.useEffect(() => {
let maxCvcLengthPossible = maxCvcLength(cardBrand)
if (
cvcNumber->String.length > 0 && cvcNumberInRange(cvcNumber, cardBrand)->Array.includes(true)
) {
setIsCVCValid(_ => Some(true))
} else if cvcNumber->String.length > maxCvcLengthPossible {
setCvcNumber(_ => cvcNumber->String.slice(~start=0, ~end=maxCvcLengthPossible))
setIsCVCValid(_ => Some(true))
} else {
setIsCVCValid(_ => None)
}
None
}, [cardBrand])

let changeCardNumber = ev => {
let val = ReactEvent.Form.target(ev)["value"]
logInputChangeInfo("cardNumber", logger)
Expand Down
Loading