Beispiel #1
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;
  }
Beispiel #2
0
 /**
  * Setter for the card number
  *
  * @param number String containing the new card number
  * @throws CardException if the card number is not valid
  */
 public void setNumber(String number) throws CardException {
   if (!CardValidator.validateCardNumber(number))
     throw new CardException(CardExceptionType.INVALID_NUMBER);
   else this.number = CardValidator.sanitizeEntry(number, true);
 }