use of org.killbill.billing.account.api.AccountApiException in project killbill by killbill.
the class DefaultAccountUserApi method updateAccount.
@Override
public void updateAccount(final UUID accountId, final AccountData accountData, final CallContext context) throws AccountApiException {
final Account currentAccount = getAccountById(accountId, context);
if (currentAccount == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId);
}
updateAccount(currentAccount, accountData, context);
}
use of org.killbill.billing.account.api.AccountApiException in project killbill by killbill.
the class DefaultAccountUserApi method updateAccount.
@Override
public void updateAccount(final Account account, final CallContext context) throws AccountApiException {
// Convert to DefaultAccount to make sure we can safely call validateAccountUpdateInput
final DefaultAccount input = new DefaultAccount(account.getId(), account);
final Account currentAccount = getAccountById(input.getId(), context);
if (currentAccount == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, input.getId());
}
input.validateAccountUpdateInput(currentAccount, true);
final AccountModelDao updatedAccountModelDao = new AccountModelDao(currentAccount.getId(), input);
accountDao.update(updatedAccountModelDao, internalCallContextFactory.createInternalCallContext(updatedAccountModelDao.getId(), context));
}
use of org.killbill.billing.account.api.AccountApiException in project killbill by killbill.
the class DefaultAccountUserApi method createAccount.
@Override
public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException {
// Not transactional, but there is a db constraint on that column
if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) {
throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey());
}
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context);
if (data.getParentAccountId() != null) {
// verify that parent account exists if parentAccountId is not null
getAccountById(data.getParentAccountId(), internalContext);
}
final AccountModelDao account = new AccountModelDao(data);
if (null != account.getExternalKey() && account.getExternalKey().length() > 255) {
throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED);
}
accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context));
return new DefaultAccount(account);
}
use of org.killbill.billing.account.api.AccountApiException in project killbill by killbill.
the class MockAccountDao method updatePaymentMethod.
@Override
public void updatePaymentMethod(final UUID accountId, final UUID paymentMethodId, final InternalCallContext context) throws AccountApiException {
final AccountModelDao currentAccountModelDao = getById(accountId, context);
if (currentAccountModelDao == null) {
throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId);
}
final DefaultAccount currentAccount = new DefaultAccount(currentAccountModelDao);
final DefaultMutableAccountData updatedAccount = new DefaultMutableAccountData(currentAccount);
updatedAccount.setPaymentMethodId(paymentMethodId);
update(new AccountModelDao(accountId, updatedAccount), context);
}
use of org.killbill.billing.account.api.AccountApiException in project killbill by killbill.
the class TestAccountDao method testHandleDuplicateEmails.
@Test(groups = "slow", description = "Test Account DAO: duplicate emails throws an exception")
public void testHandleDuplicateEmails() throws AccountApiException {
final UUID accountId = UUID.randomUUID();
final AccountEmail email = new DefaultAccountEmail(accountId, "test@gmail.com");
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 0);
final AccountEmailModelDao accountEmailModelDao = new AccountEmailModelDao(email);
accountDao.addEmail(accountEmailModelDao, internalCallContext);
Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 1);
try {
accountDao.addEmail(accountEmailModelDao, internalCallContext);
Assert.fail();
} catch (AccountApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.ACCOUNT_EMAIL_ALREADY_EXISTS.getCode());
}
}
Aggregations