Ejemplo n.º 1
0
 /**
  * Setter for the CVV
  *
  * @param cvv String containing the new cvv
  * @throws CardException if the cvv is not valid
  */
 public void setCvv(String cvv) throws CardException {
   if (this.number != null) {
     Cards card = CardValidator.getCardType(this.number);
     if (!CardValidator.validateCVV(cvv, card))
       throw new CardException(CardExceptionType.INVALID_CVV);
     else this.cvv = cvv;
   } else throw new CardException(CardExceptionType.INVALID_NUMBER);
 }
Ejemplo n.º 2
0
  /**
   * Secondary constructor, with optional billing details
   *
   * @param cardNumber String containing the card's number
   * @param name String containing the card's owner name
   * @param expMonth String containing the expiry month
   * @param expYear String containing the expiry year
   * @param cvv String containing the CVV
   * @param billingDetails CustDetails object containing the customer details
   * @throws CardException if any of the parameter is not valid
   */
  public Card(
      String cardNumber,
      String name,
      String expMonth,
      String expYear,
      String cvv,
      CustDetails billingDetails)
      throws CardException {
    if (!CardValidator.validateCardNumber(cardNumber))
      throw new CardException(CardExceptionType.INVALID_NUMBER);
    if (!CardValidator.validateExpiryDate(expMonth, expYear))
      throw new CardException(CardExceptionType.INVALID_EXPIRY_DATE);
    Cards card = CardValidator.getCardType(cardNumber);
    if (!CardValidator.validateCVV(cvv, card))
      throw new CardException(CardExceptionType.INVALID_CVV);

    this.number = CardValidator.sanitizeEntry(cardNumber, true);
    this.name = name;
    this.expiryMonth = expMonth;
    this.expiryYear = expYear;
    this.cvv = cvv;
    this.billingDetails = billingDetails;
  }