Search in sources :

Example 31 with AccountApiException

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);
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) Account(org.killbill.billing.account.api.Account) AccountApiException(org.killbill.billing.account.api.AccountApiException)

Example 32 with AccountApiException

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));
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) Account(org.killbill.billing.account.api.Account) AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountApiException(org.killbill.billing.account.api.AccountApiException)

Example 33 with AccountApiException

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);
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountApiException(org.killbill.billing.account.api.AccountApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 34 with AccountApiException

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);
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountApiException(org.killbill.billing.account.api.AccountApiException) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData)

Example 35 with AccountApiException

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());
    }
}
Also used : DefaultAccountEmail(org.killbill.billing.account.api.DefaultAccountEmail) AccountEmail(org.killbill.billing.account.api.AccountEmail) DefaultAccountEmail(org.killbill.billing.account.api.DefaultAccountEmail) AccountApiException(org.killbill.billing.account.api.AccountApiException) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

AccountApiException (org.killbill.billing.account.api.AccountApiException)36 UUID (java.util.UUID)17 Account (org.killbill.billing.account.api.Account)16 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)12 DefaultAccount (org.killbill.billing.account.api.DefaultAccount)10 ArrayList (java.util.ArrayList)7 ImmutableAccountData (org.killbill.billing.account.api.ImmutableAccountData)7 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)7 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)6 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)6 CallContext (org.killbill.billing.util.callcontext.CallContext)6 BigDecimal (java.math.BigDecimal)5 HashMap (java.util.HashMap)5 AccountModelDao (org.killbill.billing.account.dao.AccountModelDao)5 Invoice (org.killbill.billing.invoice.api.Invoice)5 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)4 Subscribe (com.google.common.eventbus.Subscribe)4 LocalDate (org.joda.time.LocalDate)4 DefaultMutableAccountData (org.killbill.billing.account.api.DefaultMutableAccountData)4 PaymentMethod (org.killbill.billing.payment.api.PaymentMethod)4