Esempio n. 1
0
  @Transactional
  @Override
  public Payment makePayment(String username, Payment payment) {
    User user = userDao.getByUsername(username);
    payment.setUser(user);
    if (!(checkCreditCard(payment))) // credit card invalid
    throw new AccessDeniedException("Credit card invalid");

    AccountType accountType;
    try {
      accountType = accountTypeDao.getAccountTypeByPrice(payment.getAmount());
    } catch (NoResultException nre) {
      throw new AccessDeniedException("No such type of account.");
    }
    paymentDao.makePayment(payment);

    UserAccountType userAccountType;
    try {
      userAccountType = userAccountTypeDao.getUserAccountType(user.getId());
      userAccountType.setAccountType(accountType);
      userAccountType.setPayment(payment);
      userAccountTypeDao.updateUserAccountType(userAccountType);
    } catch (NoResultException nre) {
      userAccountType = new UserAccountType();
      userAccountType.setUser(user);
      userAccountType.setAccountType(accountType);
      userAccountType.setPayment(payment);
      userAccountTypeDao.addUserAccountType(userAccountType);
    }
    return payment;
  }
Esempio n. 2
0
 private boolean checkCreditCard(Payment payment) {
   return checkCreditCardNumberValidity(payment.getCreditCardNumber())
       && checkCreditCardExpirationDate(payment.getValidUntil())
       && payment.getAmount() > 0;
 }