Search in sources :

Example 16 with FixedPriceInvoiceItem

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);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) CreditAdjInvoiceItem(org.killbill.billing.invoice.model.CreditAdjInvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ParentInvoiceItem(org.killbill.billing.invoice.model.ParentInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) BigDecimal(java.math.BigDecimal) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) DefaultInvoicePayment(org.killbill.billing.invoice.model.DefaultInvoicePayment) Test(org.testng.annotations.Test)

Example 17 with FixedPriceInvoiceItem

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);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) CreditAdjInvoiceItem(org.killbill.billing.invoice.model.CreditAdjInvoiceItem) Invoice(org.killbill.billing.invoice.api.Invoice) CreditAdjInvoiceItem(org.killbill.billing.invoice.model.CreditAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 18 with FixedPriceInvoiceItem

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);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 19 with FixedPriceInvoiceItem

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);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 20 with FixedPriceInvoiceItem

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>");
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)37 Test (org.testng.annotations.Test)33 LocalDate (org.joda.time.LocalDate)32 BigDecimal (java.math.BigDecimal)29 Invoice (org.killbill.billing.invoice.api.Invoice)21 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)21 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)18 UUID (java.util.UUID)17 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)16 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)14 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)10 DateTime (org.joda.time.DateTime)9 CreditBalanceAdjInvoiceItem (org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem)9 Plan (org.killbill.billing.catalog.api.Plan)7 CreditAdjInvoiceItem (org.killbill.billing.invoice.model.CreditAdjInvoiceItem)7 ExternalChargeInvoiceItem (org.killbill.billing.invoice.model.ExternalChargeInvoiceItem)7 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)6 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)6 MockPlan (org.killbill.billing.catalog.MockPlan)6 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)6