Search in sources :

Example 1 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class TestInvoiceDao method testDeleteCBANotConsumed.

@Test(groups = "slow")
public void testDeleteCBANotConsumed() 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, UUID.randomUUID().toString(), UUID.randomUUID().toString(), 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);
    // Verify scenario - no CBA should have been used
    Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 10.00);
    invoiceUtil.verifyInvoice(invoice1.getId(), 10.00, 10.00, context);
    // Delete the CBA on invoice 1
    invoiceDao.deleteCBA(accountId, invoice1.getId(), creditBalanceAdjInvoiceItem1.getId(), context);
    // Verify the result
    Assert.assertEquals(invoiceDao.getAccountCBA(accountId, context).doubleValue(), 0.00);
    invoiceUtil.verifyInvoice(invoice1.getId(), 0.00, 0.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) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 2 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class TestInvoiceItemDao method testFixedPriceWithSubMillisecondCatalogEffectiveDateInvoiceSqlDao.

@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/1370")
public void testFixedPriceWithSubMillisecondCatalogEffectiveDateInvoiceSqlDao() throws EntityPersistenceException {
    final UUID invoiceId = UUID.randomUUID();
    final UUID accountId = account.getId();
    final LocalDate startDate = new LocalDate(2012, 4, 1);
    final InvoiceItem fixedPriceInvoiceItem = new FixedPriceInvoiceItem(invoiceId, accountId, UUID.randomUUID(), UUID.randomUUID(), "test product", "test plan", "test phase", new DateTime("2020-09-16T10:34:25.348646Z"), startDate, TEN, Currency.USD);
    invoiceUtil.createInvoiceItem(fixedPriceInvoiceItem, context);
    final InvoiceItemModelDao savedItem = invoiceUtil.getInvoiceItemById(fixedPriceInvoiceItem.getId(), context);
    assertSameInvoiceItem(fixedPriceInvoiceItem, savedItem);
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) TaxInvoiceItem(org.killbill.billing.invoice.model.TaxInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) CreditBalanceAdjInvoiceItem(org.killbill.billing.invoice.model.CreditBalanceAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 3 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testFixedPriceLifeCycle.

@Test(groups = "fast")
public void testFixedPriceLifeCycle() throws InvoiceApiException {
    final SubscriptionBase subscription = createSubscription();
    final Plan plan = new MockPlan("plan 1");
    final MockInternationalPrice zeroPrice = new MockInternationalPrice(new DefaultPrice(ZERO, Currency.USD));
    final MockInternationalPrice cheapPrice = new MockInternationalPrice(new DefaultPrice(ONE, Currency.USD));
    final PlanPhase phase1 = new MockPlanPhase(null, zeroPrice, BillingPeriod.NO_BILLING_PERIOD, PhaseType.TRIAL);
    final PlanPhase phase2 = new MockPlanPhase(cheapPrice, null, BillingPeriod.MONTHLY, PhaseType.DISCOUNT);
    final DateTime changeDate = new DateTime("2012-04-1");
    final BillingEventSet events = new MockBillingEventSet();
    final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, subscription, new DateTime("2012-01-1"), plan, phase1, ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Test Event 1", 1L, SubscriptionBaseTransitionType.CREATE);
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(null, subscription, changeDate, plan, phase2, ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Test Event 2", 2L, SubscriptionBaseTransitionType.PHASE);
    events.add(event2);
    events.add(event1);
    final InvoiceWithMetadata invoiceWithMetadata1 = generator.generateInvoice(account, events, new AccountInvoices(), null, new LocalDate("2012-02-01"), Currency.USD, null, internalCallContext);
    final Invoice invoice1 = invoiceWithMetadata1.getInvoice();
    assertNotNull(invoice1);
    assertEquals(invoice1.getNumberOfItems(), 1);
    final List<Invoice> invoiceList = new ArrayList<Invoice>();
    invoiceList.add(invoice1);
    final InvoiceWithMetadata invoiceWithMetadata2 = generator.generateInvoice(account, events, new AccountInvoices(null, null, invoiceList), null, new LocalDate("2012-04-05"), Currency.USD, null, internalCallContext);
    final Invoice invoice2 = invoiceWithMetadata2.getInvoice();
    assertNotNull(invoice2);
    assertEquals(invoice2.getNumberOfItems(), 1);
    final FixedPriceInvoiceItem item = (FixedPriceInvoiceItem) invoice2.getInvoiceItems().get(0);
    assertEquals(item.getStartDate(), changeDate.toLocalDate());
}
Also used : AccountInvoices(org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) ArrayList(java.util.ArrayList) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) DateTime(org.joda.time.DateTime) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) BillingEventSet(org.killbill.billing.junction.BillingEventSet) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) Test(org.testng.annotations.Test)

Example 4 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testIsSameDayAndSameSubscriptionWithDifferentSubscriptionId.

@Test(groups = "fast")
public void testIsSameDayAndSameSubscriptionWithDifferentSubscriptionId() {
    final Plan plan = new MockPlan("my-plan");
    final LocalDate invoiceItemDate = new LocalDate("2016-01-08");
    final BigDecimal fixedPriceAmount = BigDecimal.TEN;
    final MockInternationalPrice fixedPrice = new MockInternationalPrice(new DefaultPrice(fixedPriceAmount, Currency.USD));
    final PlanPhase phase = new MockPlanPhase(null, fixedPrice, BillingPeriod.NO_BILLING_PERIOD, PhaseType.TRIAL);
    final UUID invoiceId = UUID.randomUUID();
    final InvoiceItem prevInvoiceItem = new FixedPriceInvoiceItem(invoiceId, account.getId(), UUID.randomUUID(), UUID.randomUUID(), null, plan.getName(), phase.getName(), null, invoiceItemDate, fixedPriceAmount, Currency.USD);
    final BillingEvent event = invoiceUtil.createMockBillingEvent(account, subscription, new DateTime("2016-01-08"), plan, phase, fixedPriceAmount, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
    assertFalse(fixedAndRecurringInvoiceItemGenerator.isSameDayAndSameSubscription(prevInvoiceItem, event, internalCallContext));
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) DateTime(org.joda.time.DateTime) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 5 with FixedPriceInvoiceItem

use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testIsSameDayAndSameSubscriptionWithDifferentDate.

@Test(groups = "fast")
public void testIsSameDayAndSameSubscriptionWithDifferentDate() {
    final Plan plan = new MockPlan("my-plan");
    final LocalDate invoiceItemDate = new LocalDate("2016-01-08");
    final BigDecimal fixedPriceAmount = BigDecimal.TEN;
    final MockInternationalPrice fixedPrice = new MockInternationalPrice(new DefaultPrice(fixedPriceAmount, Currency.USD));
    final PlanPhase phase = new MockPlanPhase(null, fixedPrice, BillingPeriod.NO_BILLING_PERIOD, PhaseType.TRIAL);
    final UUID invoiceId = UUID.randomUUID();
    final InvoiceItem prevInvoiceItem = new FixedPriceInvoiceItem(invoiceId, account.getId(), subscription.getBundleId(), subscription.getId(), null, plan.getName(), phase.getName(), null, invoiceItemDate, fixedPriceAmount, Currency.USD);
    final BillingEvent event = invoiceUtil.createMockBillingEvent(account, subscription, new DateTime("2016-02-01"), plan, phase, fixedPriceAmount, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
    assertFalse(fixedAndRecurringInvoiceItemGenerator.isSameDayAndSameSubscription(prevInvoiceItem, event, internalCallContext));
}
Also used : FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) FixedPriceInvoiceItem(org.killbill.billing.invoice.model.FixedPriceInvoiceItem) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) DateTime(org.joda.time.DateTime) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) UUID(java.util.UUID) 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