예제 #1
0
 public CreditCard updateCreditCardPaymentInformation(CreditCard creditcard)
     throws PaymentException {
   if (id <= 0) {
     throw new CustomerException(
         "updateCreditCardPaymentInformation", "Please specify a Customer Id");
   }
   if (creditcard == null || creditcard.getPaymentid() <= 0) {
     throw new PaymentException(
         "updateCreditCardPaymentInformation", "Please specify payment information to update.");
   }
   /*
    * we dont need to validate CC since it's an update. we're assuming the
    * client will handle this and null fields will not be updated anyways
    */
   if (true /* creditcard.validate() */) {
     if (creditcard.getAlias() == null || creditcard.getAlias().trim().length() == 0) {
       int myFirstCardNumber = Integer.parseInt(creditcard.getCreditCardNumber().substring(0, 1));
       String myAlias =
           " "
               + creditcard
                   .getCreditCardNumber()
                   .substring(
                       creditcard.getCreditCardNumber().length() - 4,
                       creditcard.getCreditCardNumber().length());
       switch (myFirstCardNumber) {
         case 3:
           myAlias = "AMEX" + myAlias;
           // throw new
           // PaymentException("updateCreditCardPaymentInformation","American Express cards are not
           // accepted at this time. Please try another card");
           break;
         case 4:
           myAlias = "VISA" + myAlias;
           break;
         case 5:
           myAlias = "MasterCard" + myAlias;
           break;
         case 6:
           myAlias = "Discover" + myAlias;
           // throw new
           // PaymentException("updateCreditCardPaymentInformation","Discover cards are not
           // accepted at this time. Please try another card");
           break;
       }
       creditcard.setAlias(myAlias);
     }
     creditcard.savePaymentOption();
   }
   // else {
   // throw new
   // PaymentException("updateCreditCardPaymentInformation","CreditCard information does not
   // validate however no validation exception was thrown.");
   // }
   return creditcard;
 }
예제 #2
0
 public CreditCard insertCreditCardPaymentInformation(CreditCard creditcard)
     throws PaymentException {
   if (id <= 0) {
     throw new CustomerException(
         "insertCreditCardPaymentInformation", "Please specify a Customer Id");
   }
   if (creditcard == null) {
     throw new PaymentException(
         "insertCreditCardPaymentInformation", "Please specify payment information to save.");
   }
   if (creditcard.validate()) {
     creditcard.savePaymentOption();
   }
   if (creditcard.getPaymentid() <= 0) {
     throw new PaymentException(
         "insertCreditCardPaymentInformation", "Error saving payment information.");
   } else {
     if (creditcard.getAlias() == null || creditcard.getAlias().trim().length() == 0) {
       int myFirstCardNumber = Integer.parseInt(creditcard.getCreditCardNumber().substring(0, 1));
       String myAlias =
           " "
               + creditcard
                   .getCreditCardNumber()
                   .substring(
                       creditcard.getCreditCardNumber().length() - 4,
                       creditcard.getCreditCardNumber().length());
       switch (myFirstCardNumber) {
         case 3:
           myAlias = "AMEX" + myAlias;
           // throw new
           // PaymentException("insertCreditCardPaymentInformation","American Express cards are not
           // accepted at this time. Please try another card");
           break;
         case 4:
           myAlias = "VISA" + myAlias;
           break;
         case 5:
           myAlias = "MasterCard" + myAlias;
           break;
         case 6:
           myAlias = "Discover" + myAlias;
           // throw new
           // PaymentException("insertCreditCardPaymentInformation","Discover cards are not
           // accepted at this time. Please try another card");
           break;
       }
       creditcard.setAlias(myAlias);
     }
     saveCustPmtMap(creditcard);
   }
   return creditcard;
 }