Beispiel #1
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;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 public void deletePayment(int paymentId) throws CustomerException {
   if (getId() == 0) {
     throw new CustomerException("deletePayment", "Invalid Customer Object. ID must be set.");
   }
   List<CustPmtMap> custPmtMapList = getCustpmttypes(0);
   boolean isValidTransaction = false;
   for (CustPmtMap cpm : custPmtMapList) {
     if (cpm.getPaymentid() == paymentId) {
       isValidTransaction = true;
       if (cpm.getPaymenttype().equals(PaymentType.CreditCard.toString())) {
         CreditCard creditcard = new CreditCard();
         creditcard.setPaymentid(paymentId);
         creditcard.deletePaymentOption();
       }
       break;
     }
   }
   if (!isValidTransaction) {
     throw new CustomerException(
         "deletePayment",
         "Invalid Request. Payment ID " + paymentId + " does not belong to cust id " + getId());
   }
 }