![JAR search and dependency download from the Maven repository](/logo.png)
com.wix.pay.creditcard.InvalidCreditCardNumberException.scala Maven / Gradle / Ivy
The newest version!
/* __ __ _____ __ *\
** / // // /_/ |/ / Wix **
** / // // / /| / (c) 2006-2015, Wix LTD. **
** / // // / // | http://www.wix.com/ **
** \__/|__/_//_/| | **
\* |/ */
package com.wix.pay.creditcard
/** Indicates that a Credit Card number is invalid (e.g., does not pass ''Luhn'' validation,
* or ''Isracard'' validation, in the case of ''Isracard'' credit cards).
*
* @author Raz, Ohad
*/
case class InvalidCreditCardNumberException(number: String,
cause:Throwable) extends RuntimeException(
InvalidCreditCardNumberException.composeMsg(number), cause)
/** The Companion Object of the [[InvalidCreditCardNumberException]] class, which introduces means for instantiating
* an exception object.
*
* @author Raz, Ohad
*/
object InvalidCreditCardNumberException {
def apply(number: String): InvalidCreditCardNumberException = this(composeMsg(number), null)
def apply(cause: Throwable): InvalidCreditCardNumberException = this(Option(cause).map(_.toString).orNull, cause)
def apply(): InvalidCreditCardNumberException = this(null, null)
private def composeMsg(number: String): String = {
s"Invalid card number '${number.replaceAll("\\d(?=\\d{4})", "X")}'"
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy