Search in sources :

Example 16 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount 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 17 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.

the class TestDefaultAccountUserApiWithMocks method testCreateAccount.

@Test(groups = "fast", description = "Test Account create API")
public void testCreateAccount() throws Exception {
    final UUID id = UUID.randomUUID();
    final String externalKey = UUID.randomUUID().toString();
    final String email = UUID.randomUUID().toString();
    final String name = UUID.randomUUID().toString();
    final Integer firstNameLength = Integer.MAX_VALUE;
    final Currency currency = Currency.BRL;
    final Integer billCycleDay = Integer.MAX_VALUE;
    final UUID paymentMethodId = UUID.randomUUID();
    final DateTimeZone timeZone = DateTimeZone.UTC;
    final String locale = UUID.randomUUID().toString();
    final String address1 = UUID.randomUUID().toString();
    final String address2 = UUID.randomUUID().toString();
    final String companyName = UUID.randomUUID().toString();
    final String city = UUID.randomUUID().toString();
    final String stateOrProvince = UUID.randomUUID().toString();
    final String country = UUID.randomUUID().toString();
    final String postalCode = UUID.randomUUID().toString();
    final String phone = UUID.randomUUID().toString();
    final String notes = UUID.randomUUID().toString();
    final Boolean isMigrated = true;
    final Boolean isNotifiedForInvoices = false;
    final AccountData data = new DefaultAccount(id, externalKey, email, name, firstNameLength, currency, null, false, billCycleDay, paymentMethodId, timeZone, locale, address1, address2, companyName, city, stateOrProvince, country, postalCode, phone, notes, isMigrated, isNotifiedForInvoices);
    accountUserApi.createAccount(data, callContext);
    final AccountModelDao account = accountDao.getAccountByKey(externalKey, tenantContext);
    Assert.assertEquals(account.getExternalKey(), externalKey);
    Assert.assertEquals(account.getEmail(), email);
    Assert.assertEquals(account.getName(), name);
    Assert.assertEquals(account.getFirstNameLength(), firstNameLength);
    Assert.assertEquals(account.getCurrency(), currency);
    Assert.assertEquals(account.getBillingCycleDayLocal(), (Integer) billCycleDay);
    Assert.assertEquals(account.getPaymentMethodId(), paymentMethodId);
    Assert.assertEquals(account.getTimeZone(), timeZone);
    Assert.assertEquals(account.getLocale(), locale);
    Assert.assertEquals(account.getAddress1(), address1);
    Assert.assertEquals(account.getAddress2(), address2);
    Assert.assertEquals(account.getCompanyName(), companyName);
    Assert.assertEquals(account.getCity(), city);
    Assert.assertEquals(account.getStateOrProvince(), stateOrProvince);
    Assert.assertEquals(account.getCountry(), country);
    Assert.assertEquals(account.getPostalCode(), postalCode);
    Assert.assertEquals(account.getPhone(), phone);
    Assert.assertEquals(account.getMigrated(), isMigrated);
    Assert.assertEquals(account.getIsNotifiedForInvoices(), isNotifiedForInvoices);
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountData(org.killbill.billing.account.api.AccountData) Currency(org.killbill.billing.catalog.api.Currency) UUID(java.util.UUID) DateTimeZone(org.joda.time.DateTimeZone) Test(org.testng.annotations.Test)

Example 18 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount 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 19 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.

the class TestDefaultAccountUserApi method testBusEvents.

@Test(groups = "slow", description = "Test Account creation generates an event")
public void testBusEvents() throws Exception {
    final AccountEventHandler eventHandler = new AccountEventHandler();
    bus.register(eventHandler);
    final AccountModelDao accountModelDao = createTestAccount();
    final AccountData defaultAccount = new DefaultAccount(accountModelDao);
    final Account account = createAccount(defaultAccount);
    await().atMost(10, SECONDS).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return eventHandler.getAccountCreationInternalEvents().size() == 1;
        }
    });
    final AccountCreationInternalEvent accountCreationInternalEvent = eventHandler.getAccountCreationInternalEvents().get(0);
    Assert.assertEquals(accountCreationInternalEvent.getId(), account.getId());
    // account_record_id is most likely 1, although, depending on the DB, we cannot be sure
    Assert.assertNotNull(accountCreationInternalEvent.getSearchKey1());
    Assert.assertEquals(accountCreationInternalEvent.getSearchKey2(), internalCallContext.getTenantRecordId());
}
Also used : AccountModelDao(org.killbill.billing.account.dao.AccountModelDao) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountTestUtils.createTestAccount(org.killbill.billing.account.AccountTestUtils.createTestAccount) Account(org.killbill.billing.account.api.Account) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) AccountTestUtils.createAccountData(org.killbill.billing.account.AccountTestUtils.createAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) AccountData(org.killbill.billing.account.api.AccountData) AccountApiException(org.killbill.billing.account.api.AccountApiException) AccountCreationInternalEvent(org.killbill.billing.events.AccountCreationInternalEvent) Test(org.testng.annotations.Test)

Example 20 with DefaultAccount

use of org.killbill.billing.account.api.DefaultAccount in project killbill by killbill.

the class TestDefaultAccountUserApi method testShouldntBeAbleToUpdateExternalKey.

@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account externalKey throws an exception")
public void testShouldntBeAbleToUpdateExternalKey() throws Exception {
    final Account account = createAccount(new DefaultAccount(createTestAccount()));
    final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData();
    otherAccount.setExternalKey(UUID.randomUUID().toString());
    accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), callContext);
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountTestUtils.createTestAccount(org.killbill.billing.account.AccountTestUtils.createTestAccount) Account(org.killbill.billing.account.api.Account) DefaultAccount(org.killbill.billing.account.api.DefaultAccount) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) Test(org.testng.annotations.Test)

Aggregations

DefaultAccount (org.killbill.billing.account.api.DefaultAccount)28 Test (org.testng.annotations.Test)23 Account (org.killbill.billing.account.api.Account)22 DefaultMutableAccountData (org.killbill.billing.account.api.DefaultMutableAccountData)20 MutableAccountData (org.killbill.billing.account.api.MutableAccountData)19 AccountTestUtils.createTestAccount (org.killbill.billing.account.AccountTestUtils.createTestAccount)17 AccountModelDao (org.killbill.billing.account.dao.AccountModelDao)13 AccountData (org.killbill.billing.account.api.AccountData)7 AccountApiException (org.killbill.billing.account.api.AccountApiException)6 AccountTestUtils.createAccountData (org.killbill.billing.account.AccountTestUtils.createAccountData)5 DateTime (org.joda.time.DateTime)2 Invoice (org.killbill.billing.invoice.api.Invoice)2 BigDecimal (java.math.BigDecimal)1 UUID (java.util.UUID)1 DateTimeZone (org.joda.time.DateTimeZone)1 DefaultImmutableAccountData (org.killbill.billing.account.api.DefaultImmutableAccountData)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 Currency (org.killbill.billing.catalog.api.Currency)1 AccountCreationInternalEvent (org.killbill.billing.events.AccountCreationInternalEvent)1 MockAccountBuilder (org.killbill.billing.mock.MockAccountBuilder)1