}
protected void saveCreditCard(ShoppingCartActionForm form, Site site, ShoppingCart shoppingCart, ContentBean contentBean) throws Exception {
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
Customer customer = shoppingCart.getCustomer();
CustomerCreditCard customerCreditCard = null;
Iterator<?> iterator = customer.getCustCreditCards().iterator();
boolean found = false;
if (iterator.hasNext()) {
found = true;
customerCreditCard = (CustomerCreditCard) iterator.next();
customerCreditCard.setRecCreateBy(Constants.USERNAME_SYSTEM);
customerCreditCard.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
else {
customerCreditCard = new CustomerCreditCard();
customerCreditCard.setRecUpdateBy(Constants.USERNAME_SYSTEM);
customerCreditCard.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
customerCreditCard.setRecCreateBy(Constants.USERNAME_SYSTEM);
customerCreditCard.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
customerCreditCard.setCustCreditCardFullName(form.getCustCreditCardFullName());
customerCreditCard.setCustCreditCardNum(AESEncoder.getInstance().encode(form.getCustCreditCardNum()));
customerCreditCard.setCustCreditCardExpiryMonth(form.getCustCreditCardExpiryMonth());
customerCreditCard.setCustCreditCardExpiryYear(form.getCustCreditCardExpiryYear());
customerCreditCard.setCustCreditCardVerNum(form.getCustCreditCardVerNum());
String creditCardId = form.getCreditCardId();
CreditCard creditCard = (CreditCard) em.find(CreditCard.class, Format.getLong(creditCardId));
customerCreditCard.setCreditCard(creditCard);
if (customerCreditCard.getCustCreditCardId() == null) {
em.persist(customerCreditCard);
}
if (!found) {
customer.getCustCreditCards().add(customerCreditCard);
}