use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testRefundCBAFullyConsumedTwice.
@Test(groups = "slow")
public void testRefundCBAFullyConsumedTwice() throws Exception {
final UUID accountId = account.getId();
// Create invoice 1
// Scenario: single item with payment
// * $10 item
// Then, a repair occur:
// * $-10 repair
// * $10 generated CBA due to the repair (assume previous payment)
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final InvoiceItem fixedItem1 = new FixedPriceInvoiceItem(invoice1.getId(), invoice1.getAccountId(), null, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, clock.getUTCToday(), BigDecimal.TEN, Currency.USD);
final RepairAdjInvoiceItem repairAdjInvoiceItem = new RepairAdjInvoiceItem(fixedItem1.getInvoiceId(), fixedItem1.getAccountId(), fixedItem1.getStartDate(), fixedItem1.getEndDate(), fixedItem1.getAmount().negate(), fixedItem1.getCurrency(), fixedItem1.getId());
final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem1 = new CreditBalanceAdjInvoiceItem(fixedItem1.getInvoiceId(), fixedItem1.getAccountId(), fixedItem1.getStartDate(), fixedItem1.getAmount(), fixedItem1.getCurrency());
invoiceUtil.createInvoice(invoice1, context);
invoiceUtil.createInvoiceItem(fixedItem1, context);
invoiceUtil.createInvoiceItem(repairAdjInvoiceItem, context);
invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem1, context);
final BigDecimal paymentAmount = new BigDecimal("10.00");
final UUID paymentId = UUID.randomUUID();
final DefaultInvoicePayment defaultInvoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoice1.getId(), clock.getUTCNow().plusDays(12), paymentAmount, Currency.USD, Currency.USD, "cookie", true);
invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment), UUID.randomUUID(), context);
// Create invoice 2
// Scenario: single item
// * $5 item
// * $-5 CBA used
final DefaultInvoice invoice2 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final InvoiceItem fixedItem2 = new FixedPriceInvoiceItem(invoice2.getId(), invoice1.getAccountId(), null, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, clock.getUTCToday(), new BigDecimal("5"), Currency.USD);
final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem2 = new CreditBalanceAdjInvoiceItem(fixedItem2.getInvoiceId(), fixedItem2.getAccountId(), fixedItem2.getStartDate(), fixedItem2.getAmount().negate(), fixedItem2.getCurrency());
invoiceUtil.createInvoice(invoice2, context);
invoiceUtil.createInvoiceItem(fixedItem2, context);
invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem2, context);
// Create invoice 3
// Scenario: single item
// * $5 item
// * $-5 CBA used
final DefaultInvoice invoice3 = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final InvoiceItem fixedItem3 = new FixedPriceInvoiceItem(invoice3.getId(), invoice1.getAccountId(), null, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, clock.getUTCToday(), new BigDecimal("5"), Currency.USD);
final CreditBalanceAdjInvoiceItem creditBalanceAdjInvoiceItem3 = new CreditBalanceAdjInvoiceItem(fixedItem3.getInvoiceId(), fixedItem3.getAccountId(), fixedItem3.getStartDate(), fixedItem3.getAmount().negate(), fixedItem3.getCurrency());
invoiceUtil.createInvoice(invoice3, context);
invoiceUtil.createInvoiceItem(fixedItem3, context);
invoiceUtil.createInvoiceItem(creditBalanceAdjInvoiceItem3, context);
// Verify scenario - all CBA should have been used
Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 0.00);
invoiceUtil.verifyInvoice(invoice1.getId(), 0.00, 10.00, context);
invoiceUtil.verifyInvoice(invoice2.getId(), 0.00, -5.00, context);
invoiceUtil.verifyInvoice(invoice3.getId(), 0.00, -5.00, context);
invoiceDao.createRefund(paymentId, UUID.randomUUID(), paymentAmount, false, ImmutableMap.<UUID, BigDecimal>of(), UUID.randomUUID().toString(), true, context);
// Verify all three invoices were affected
Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 0.00);
invoiceUtil.verifyInvoice(invoice1.getId(), 10.00, 10.00, context);
invoiceUtil.verifyInvoice(invoice2.getId(), 0.00, -5.00, context);
invoiceUtil.verifyInvoice(invoice3.getId(), 0.00, -5.00, context);
}
use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestInvoiceFlagBehaviors method testMigratedInvoiceWithAccountCredit.
@Test(groups = "slow", description = "Verify invoice/account balance with migrated invoice. Verify account credit is not consumed and that invoice/account balance does not take into account migrated invoice.")
public void testMigratedInvoiceWithAccountCredit() throws Exception {
// Add credit on the account
final InvoiceItem inputCredit = new CreditAdjInvoiceItem(null, accountId, clock.getUTCToday(), "some description", BigDecimal.TEN, accountCurrency, null);
invoiceUserApi.insertCredits(accountId, clock.getUTCToday(), ImmutableList.of(inputCredit), true, null, callContext);
final UUID invoiceId = invoiceUserApi.createMigrationInvoice(accountId, null, ImmutableList.<InvoiceItem>of(new FixedPriceInvoiceItem(UUID.randomUUID(), clock.getUTCNow(), null, accountId, null, null, null, "foo", "bar", null, null, null, BigDecimal.ONE, accountCurrency)), callContext);
final Invoice invoice1 = invoiceUserApi.getInvoice(invoiceId, callContext);
assertEquals(invoice1.getBalance().compareTo(BigDecimal.ZERO), 0);
// Verify credit is **not applied** against migration invoice
final BigDecimal accountBalance0 = invoiceUserApi.getAccountBalance(accountId, callContext);
assertEquals(accountBalance0.compareTo(new BigDecimal("-10.0")), 0);
final BigDecimal accountCBA0 = invoiceUserApi.getAccountCBA(accountId, callContext);
assertEquals(accountCBA0.compareTo(BigDecimal.TEN), 0);
}
use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testWithNewFixedItem.
@Test(groups = "fast")
public void testWithNewFixedItem() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate endDate = new LocalDate(2014, 2, 1);
final BigDecimal monthlyRate = new BigDecimal("12.00");
final BigDecimal monthlyAmount = monthlyRate;
final BigDecimal fixedAmount = new BigDecimal("5.00");
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
final InvoiceItem monthly = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyAmount, monthlyRate, currency);
tree.addItem(monthly);
tree.flatten(true);
final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyAmount, monthlyRate, currency);
final InvoiceItem fixed = new FixedPriceInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, fixedAmount, currency);
tree.mergeProposedItem(proposed1);
tree.mergeProposedItem(fixed);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
expectedResult.add(fixed);
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testWithExistingFixedItem.
@Test(groups = "fast")
public void testWithExistingFixedItem() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate endDate = new LocalDate(2014, 2, 1);
final BigDecimal monthlyRate = new BigDecimal("12.00");
final BigDecimal monthlyAmount = monthlyRate;
final BigDecimal fixedAmount = new BigDecimal("5.00");
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
final InvoiceItem monthly = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyAmount, monthlyRate, currency);
final InvoiceItem fixed = new FixedPriceInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, fixedAmount, currency);
tree.addItem(monthly);
tree.addItem(fixed);
tree.flatten(true);
final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, monthlyAmount, monthlyRate, currency);
tree.mergeProposedItem(proposed1);
tree.mergeProposedItem(fixed);
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
verifyResult(tree.getView(), expectedResult);
}
use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceItemFormatter method testNullEndDate.
@Test(groups = "fast")
public void testNullEndDate() throws Exception {
final LocalDate startDate = new LocalDate(2012, 12, 1);
final FixedPriceInvoiceItem fixedItem = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, startDate, BigDecimal.TEN, Currency.USD);
checkOutput(fixedItem, "{{#invoiceItem}}<td>{{formattedStartDate}}{{#formattedEndDate}} - {{formattedEndDate}}{{/formattedEndDate}}</td>{{/invoiceItem}}", "<td>Dec 1, 2012</td>");
}
Aggregations