use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testDeleteConsumedCredit.
@Test(groups = "slow")
public void testDeleteConsumedCredit() throws Exception {
final UUID accountId = account.getId();
final Invoice invoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final RecurringInvoiceItem recurringItem = new RecurringInvoiceItem(invoice.getId(), accountId, UUID.randomUUID(), UUID.randomUUID(), "test product", "test plan", "test ZOO", null, clock.getUTCNow().plusMonths(-1).toLocalDate(), clock.getUTCNow().toLocalDate(), BigDecimal.TEN, BigDecimal.TEN, Currency.USD);
final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem1 = new CreditBalanceAdjInvoiceItem(invoice.getId(), invoice.getAccountId(), invoice.getInvoiceDate(), BigDecimal.ONE.negate(), invoice.getCurrency());
invoiceUtil.createInvoice(invoice, context);
invoiceUtil.createInvoiceItem(recurringItem, context);
invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem1, context);
invoiceUtil.verifyInvoice(invoice.getId(), 9.00, -1.00, context);
// Delete the CBA on invoice 1
invoiceDao.deleteCBA(accountId, invoice.getId(), creditBalanceAdjInvoiceItem1.getId(), context);
final InvoiceModelDao res = invoiceDao.getById(invoice.getId(), context);
Assert.assertEquals(res.getInvoiceItems().size(), 2);
Assert.assertEquals(InvoiceModelDaoHelper.getRawBalanceForRegularInvoice(res).compareTo(BigDecimal.TEN), 0);
Assert.assertEquals(InvoiceModelDaoHelper.getCBAAmount(res).compareTo(BigDecimal.ZERO), 0);
final InvoiceItemModelDao cbaAdj = Iterables.tryFind(res.getInvoiceItems(), new Predicate<InvoiceItemModelDao>() {
@Override
public boolean apply(final InvoiceItemModelDao input) {
return input.getType() == InvoiceItemType.CBA_ADJ && input.getAmount().compareTo(BigDecimal.ZERO) == 0;
}
}).orNull();
Assert.assertNotNull(cbaAdj);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testGetInvoicesBySubscriptionForRecurringItems.
@Test(groups = "slow")
public void testGetInvoicesBySubscriptionForRecurringItems() throws EntityPersistenceException {
final UUID accountId = account.getId();
final UUID bundleId = UUID.randomUUID();
final UUID subscriptionId1 = UUID.randomUUID();
final BigDecimal rate1 = new BigDecimal("17.0");
final UUID subscriptionId2 = UUID.randomUUID();
final BigDecimal rate2 = new BigDecimal("42.0");
final UUID subscriptionId3 = UUID.randomUUID();
final BigDecimal rate3 = new BigDecimal("3.0");
final UUID subscriptionId4 = UUID.randomUUID();
final BigDecimal rate4 = new BigDecimal("12.0");
final LocalDate targetDate = new LocalDate(2011, 5, 23);
// Create invoice 1 (subscriptions 1-4)
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate, Currency.USD);
invoiceUtil.createInvoice(invoice1, context);
final UUID invoiceId1 = invoice1.getId();
LocalDate startDate = new LocalDate(2011, 3, 1);
LocalDate endDate = startDate.plusMonths(1);
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId1, "test product", "test plan", "test A", null, startDate, endDate, rate1, rate1, Currency.USD);
invoiceUtil.createInvoiceItem(item1, context);
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId2, "test product", "test plan", "test B", null, startDate, endDate, rate2, rate2, Currency.USD);
invoiceUtil.createInvoiceItem(item2, context);
final RecurringInvoiceItem item3 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId3, "test product", "test plan", "test C", null, startDate, endDate, rate3, rate3, Currency.USD);
invoiceUtil.createInvoiceItem(item3, context);
final RecurringInvoiceItem item4 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId4, "test product", "test plan", "test D", null, startDate, endDate, rate4, rate4, Currency.USD);
invoiceUtil.createInvoiceItem(item4, context);
// Create invoice 2 (subscriptions 1-3)
final DefaultInvoice invoice2 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate, Currency.USD);
invoiceUtil.createInvoice(invoice2, context);
final UUID invoiceId2 = invoice2.getId();
startDate = endDate;
endDate = startDate.plusMonths(1);
final RecurringInvoiceItem item5 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId1, "test product", "test plan", "test phase A", null, startDate, endDate, rate1, rate1, Currency.USD);
invoiceUtil.createInvoiceItem(item5, context);
final RecurringInvoiceItem item6 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId2, "test product", "test plan", "test phase B", null, startDate, endDate, rate2, rate2, Currency.USD);
invoiceUtil.createInvoiceItem(item6, context);
final RecurringInvoiceItem item7 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId3, "test product", "test plan", "test phase C", null, startDate, endDate, rate3, rate3, Currency.USD);
invoiceUtil.createInvoiceItem(item7, context);
// Check that each subscription returns the correct number of invoices
final List<InvoiceModelDao> items1 = invoiceDao.getInvoicesBySubscription(subscriptionId1, context);
assertEquals(items1.size(), 2);
final List<InvoiceModelDao> items2 = invoiceDao.getInvoicesBySubscription(subscriptionId2, context);
assertEquals(items2.size(), 2);
final List<InvoiceModelDao> items3 = invoiceDao.getInvoicesBySubscription(subscriptionId3, context);
assertEquals(items3.size(), 2);
final List<InvoiceModelDao> items4 = invoiceDao.getInvoicesBySubscription(subscriptionId4, context);
assertEquals(items4.size(), 1);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testInvoicePayment.
@Test(groups = "slow")
public void testInvoicePayment() throws InvoiceApiException, EntityPersistenceException {
final UUID accountId = account.getId();
final Invoice invoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final UUID invoiceId = invoice.getId();
final UUID subscriptionId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final LocalDate startDate = new LocalDate(2010, 1, 1);
final LocalDate endDate = new LocalDate(2010, 4, 1);
final InvoiceItem invoiceItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test product", "test plan", "test phase", null, startDate, endDate, new BigDecimal("21.00"), new BigDecimal("7.00"), Currency.USD);
invoice.addInvoiceItem(invoiceItem);
invoiceUtil.createInvoice(invoice, context);
final InvoiceModelDao savedInvoice = invoiceDao.getById(invoiceId, context);
assertNotNull(savedInvoice);
assertEquals(InvoiceModelDaoHelper.getRawBalanceForRegularInvoice(savedInvoice).compareTo(new BigDecimal("21.00")), 0);
assertEquals(savedInvoice.getInvoiceItems().size(), 1);
final BigDecimal paymentAmount = new BigDecimal("11.00");
final UUID paymentId = UUID.randomUUID();
final DefaultInvoicePayment defaultInvoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoiceId, clock.getUTCNow().plusDays(12), paymentAmount, Currency.USD, Currency.USD, "cookie", true);
invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment), UUID.randomUUID(), context);
final InvoiceModelDao retrievedInvoice = invoiceDao.getById(invoiceId, context);
assertNotNull(retrievedInvoice);
assertEquals(retrievedInvoice.getInvoiceItems().size(), 1);
assertEquals(InvoiceModelDaoHelper.getRawBalanceForRegularInvoice(retrievedInvoice).compareTo(new BigDecimal("10.00")), 0);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testAccountBalance.
@Test(groups = "slow")
public void testAccountBalance() throws EntityPersistenceException {
final UUID accountId = account.getId();
final UUID bundleId = UUID.randomUUID();
final LocalDate targetDate1 = new LocalDate(2011, 10, 6);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate1, Currency.USD);
invoiceUtil.createInvoice(invoice1, context);
final LocalDate startDate = new LocalDate(2011, 3, 1);
final LocalDate endDate = startDate.plusMonths(1);
final BigDecimal rate1 = new BigDecimal("17.0");
final BigDecimal rate2 = new BigDecimal("42.0");
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test product", "test plan", "test phase A", null, startDate, endDate, rate1, rate1, Currency.USD);
invoiceUtil.createInvoiceItem(item1, context);
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test product", "test plan", "test phase B", null, startDate, endDate, rate2, rate2, Currency.USD);
invoiceUtil.createInvoiceItem(item2, context);
final BigDecimal payment1 = new BigDecimal("48.0");
final InvoicePayment payment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), payment1, Currency.USD, Currency.USD, null, true);
invoiceUtil.createPayment(payment, context);
final BigDecimal balance = invoiceDao.getAccountBalance(accountId, context);
assertEquals(balance.compareTo(rate1.add(rate2).subtract(payment1)), 0);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDaoHelper method testPopulateChildrenWithParent.
@Test(groups = "slow")
public void testPopulateChildrenWithParent() throws Exception {
final Account parentAccount = invoiceUtil.createAccount(callContext);
final UUID childAccountId = account.getId();
final UUID parentAccountId = parentAccount.getId();
final InternalCallContext parentContext = internalCallContextFactory.createInternalCallContext(parentAccountId, callContext);
final InvoiceModelDao parentInvoice = new InvoiceModelDao(parentAccountId, today, account.getCurrency(), InvoiceStatus.DRAFT, true);
final InvoiceItem parentInvoiceItem = new ParentInvoiceItem(UUID.randomUUID(), now, parentInvoice.getId(), parentAccountId, childAccountId, BigDecimal.TEN, account.getCurrency(), "");
parentInvoice.addInvoiceItem(new InvoiceItemModelDao(parentInvoiceItem));
invoiceUtil.createInvoice(new DefaultInvoice(parentInvoice), parentContext);
final UUID accountId = account.getId();
final Invoice childInvoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final InvoiceItem invoiceItem = new RecurringInvoiceItem(childInvoice.getId(), accountId, UUID.randomUUID(), UUID.randomUUID(), "test", "test-plan", "test-phase", null, today, today, BigDecimal.TEN, BigDecimal.TEN, Currency.USD);
childInvoice.addInvoiceItem(invoiceItem);
invoiceUtil.createInvoice(childInvoice, internalAccountContext);
InvoiceParentChildModelDao invoiceRelation = new InvoiceParentChildModelDao(parentInvoice.getId(), childInvoice.getId(), childAccountId);
invoiceDao.createParentChildInvoiceRelation(invoiceRelation, internalAccountContext);
// //
final List<Tag> tags = ImmutableList.of();
final InvoiceModelDao invoice1 = getRawInvoice(childInvoice.getId(), internalAccountContext);
populateChildrenByInvoiceId(invoice1, tags);
final InvoiceModelDao invoice2 = getRawInvoice(childInvoice.getId(), internalAccountContext);
populateChildrenByAccountRecordId(invoice2, tags);
Assert.assertEquals(invoice1, invoice2);
}
Aggregations