Search in sources :

Example 26 with Invoice

use of org.killbill.billing.invoice.api.Invoice 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, null, new LocalDate("2012-02-01"), Currency.USD, 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, invoiceList, new LocalDate("2012-04-05"), Currency.USD, 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 : 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 27 with Invoice

use of org.killbill.billing.invoice.api.Invoice in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testTwoMonthlySubscriptionsWithAlignedBillingDates.

@Test(groups = "fast")
public void testTwoMonthlySubscriptionsWithAlignedBillingDates() throws InvoiceApiException, CatalogApiException {
    final BillingEventSet events = new MockBillingEventSet();
    final Plan plan1 = new MockPlan();
    final BigDecimal rate1 = FIVE;
    final PlanPhase phase1 = createMockMonthlyPlanPhase(rate1);
    final Plan plan2 = new MockPlan();
    final BigDecimal rate2 = TEN;
    final PlanPhase phase2 = createMockMonthlyPlanPhase(rate2);
    final SubscriptionBase sub = createSubscription();
    final BillingEvent event1 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 9, 1), plan1, phase1, 1);
    events.add(event1);
    final BillingEvent event2 = createBillingEvent(sub.getId(), sub.getBundleId(), invoiceUtil.buildDate(2011, 10, 1), plan2, phase2, 1);
    events.add(event2);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 10, 3);
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, targetDate, Currency.USD, internalCallContext);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertNotNull(invoice);
    assertEquals(invoice.getNumberOfItems(), 2);
    assertEquals(invoice.getBalance(), KillBillMoney.of(rate1.add(rate2), invoice.getCurrency()));
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) MockPlan(org.killbill.billing.catalog.MockPlan) 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) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 28 with Invoice

use of org.killbill.billing.invoice.api.Invoice in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testEndDateIsCorrect.

@Test(groups = "fast")
public void testEndDateIsCorrect() throws InvoiceApiException, CatalogApiException {
    final Plan plan = new MockPlan();
    final PlanPhase planPhase = createMockMonthlyPlanPhase(ONE);
    final BillingEventSet events = new MockBillingEventSet();
    final LocalDate startDate = clock.getUTCToday().minusDays(1);
    final LocalDate targetDate = startDate.plusDays(1);
    events.add(createBillingEvent(UUID.randomUUID(), UUID.randomUUID(), startDate, plan, planPhase, startDate.getDayOfMonth()));
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, targetDate, Currency.USD, internalCallContext);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    final RecurringInvoiceItem item = (RecurringInvoiceItem) invoice.getInvoiceItems().get(0);
    // end date of the invoice item should be equal to exactly one month later (rounded)
    assertEquals(item.getEndDate(), startDate.plusMonths(1));
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockPlan(org.killbill.billing.catalog.MockPlan) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) 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) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 29 with Invoice

use of org.killbill.billing.invoice.api.Invoice in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testWithSingleThirtyDaysEvent.

@Test(groups = "fast")
public void testWithSingleThirtyDaysEvent() throws InvoiceApiException, CatalogApiException {
    final BillingEventSet events = new MockBillingEventSet();
    final SubscriptionBase sub = createSubscription();
    final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1);
    final Plan plan = new MockPlan();
    final BigDecimal rate1 = TEN;
    final PlanPhase phase = createMockThirtyDaysPlanPhase(rate1);
    final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 1);
    events.add(event);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 10, 3);
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, targetDate, Currency.USD, internalCallContext);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertNotNull(invoice);
    assertEquals(invoice.getNumberOfItems(), 2);
    assertEquals(invoice.getBalance(), KillBillMoney.of(TWENTY, invoice.getCurrency()));
    assertEquals(invoice.getInvoiceItems().get(0).getSubscriptionId(), sub.getId());
    assertEquals(invoice.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), new LocalDate(2011, 9, 1));
    assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), new LocalDate(2011, 10, 1));
    assertEquals(invoice.getInvoiceItems().get(1).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(1).getStartDate(), new LocalDate(2011, 10, 1));
    assertEquals(invoice.getInvoiceItems().get(1).getEndDate(), new LocalDate(2011, 10, 31));
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) MockPlan(org.killbill.billing.catalog.MockPlan) 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) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 30 with Invoice

use of org.killbill.billing.invoice.api.Invoice in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testInvoiceGeneration.

private void testInvoiceGeneration(final UUID accountId, final BillingEventSet events, final List<Invoice> existingInvoices, final LocalDate targetDate, final int expectedNumberOfItems, final BigDecimal expectedAmount) throws InvoiceApiException {
    final Currency currency = Currency.USD;
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, existingInvoices, targetDate, currency, internalCallContext);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertNotNull(invoice);
    assertEquals(invoice.getNumberOfItems(), expectedNumberOfItems);
    existingInvoices.add(invoice);
    distributeItems(existingInvoices);
    assertEquals(invoice.getBalance(), KillBillMoney.of(expectedAmount, invoice.getCurrency()));
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) Currency(org.killbill.billing.catalog.api.Currency)

Aggregations

Invoice (org.killbill.billing.invoice.api.Invoice)245 Test (org.testng.annotations.Test)190 LocalDate (org.joda.time.LocalDate)165 BigDecimal (java.math.BigDecimal)148 UUID (java.util.UUID)105 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)96 Account (org.killbill.billing.account.api.Account)84 DateTime (org.joda.time.DateTime)73 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)70 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)57 ArrayList (java.util.ArrayList)50 BillingEventSet (org.killbill.billing.junction.BillingEventSet)48 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)45 MockPlan (org.killbill.billing.catalog.MockPlan)45 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)45 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)44 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)43 Plan (org.killbill.billing.catalog.api.Plan)41 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)40 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)39