Search in sources :

Example 16 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testProcessFixedBillingEventsWithCancellationOnNextDay.

@Test(groups = "fast")
public void testProcessFixedBillingEventsWithCancellationOnNextDay() throws InvoiceApiException {
    final LocalDate targetDate = new LocalDate("2016-01-08");
    final UUID invoiceId = UUID.randomUUID();
    final BillingEventSet events = new MockBillingEventSet();
    final BigDecimal fixedPriceAmount = BigDecimal.TEN;
    final MockInternationalPrice fixedPrice = new MockInternationalPrice(new DefaultPrice(fixedPriceAmount, Currency.USD));
    final Plan plan = new MockPlan("my-plan");
    final PlanPhase phase = new MockPlanPhase(null, fixedPrice, BillingPeriod.NO_BILLING_PERIOD, PhaseType.TRIAL);
    final BillingEvent event1 = 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);
    events.add(event1);
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(account, subscription, new DateTime("2016-01-09"), plan, phase, null, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 2L, SubscriptionBaseTransitionType.CANCEL);
    events.add(event2);
    final List<InvoiceItem> proposedItems = new ArrayList<InvoiceItem>();
    fixedAndRecurringInvoiceItemGenerator.processFixedBillingEvents(invoiceId, account.getId(), events, targetDate, Currency.USD, proposedItems, internalCallContext);
    assertEquals(proposedItems.size(), 1);
    assertEquals(proposedItems.get(0).getInvoiceItemType(), InvoiceItemType.FIXED);
    assertEquals(proposedItems.get(0).getAmount().compareTo(fixedPriceAmount), 0);
}
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) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) ArrayList(java.util.ArrayList) 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) 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) UUID(java.util.UUID) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) Test(org.testng.annotations.Test)

Example 17 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testItemPartiallyRepairedAndPartiallyAdjustedV2.

@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/664")
public void testItemPartiallyRepairedAndPartiallyAdjustedV2() throws InvoiceApiException {
    final LocalDate startDate = new LocalDate("2016-01-01");
    final BillingEventSet events = new MockBillingEventSet();
    final BigDecimal amount = BigDecimal.TEN;
    final MockInternationalPrice price = new MockInternationalPrice(new DefaultPrice(amount, account.getCurrency()));
    final Plan plan = new MockPlan("my-plan");
    final PlanPhase planPhase = new MockPlanPhase(price, null, BillingPeriod.MONTHLY, PhaseType.EVERGREEN);
    final BillingEvent event1 = invoiceUtil.createMockBillingEvent(account, subscription, startDate.toDateTimeAtStartOfDay(), plan, planPhase, null, amount, account.getCurrency(), BillingPeriod.MONTHLY, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
    events.add(event1);
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(account, subscription, startDate.plusDays(1).toDateTimeAtStartOfDay(), plan, planPhase, null, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 2L, SubscriptionBaseTransitionType.CANCEL);
    events.add(event2);
    // Subscription incorrectly invoiced
    final List<Invoice> existingInvoices = new LinkedList<Invoice>();
    final Invoice invoice = new DefaultInvoice(account.getId(), clock.getUTCToday(), startDate, account.getCurrency());
    invoice.addInvoiceItem(new RecurringInvoiceItem(UUID.randomUUID(), startDate.toDateTimeAtStartOfDay(), invoice.getId(), account.getId(), subscription.getBundleId(), subscription.getId(), plan.getName(), planPhase.getName(), startDate, startDate.plusMonths(1), amount, amount, account.getCurrency()));
    // Item adjust the remaining
    invoice.addInvoiceItem(new ItemAdjInvoiceItem(invoice.getInvoiceItems().get(0), startDate, BigDecimal.ONE.negate(), account.getCurrency()));
    // Repaired by the system (the system would have consumed all the remaining amount available)
    invoice.addInvoiceItem(new RepairAdjInvoiceItem(UUID.randomUUID(), startDate.toDateTimeAtStartOfDay(), invoice.getId(), account.getId(), startDate.plusDays(1), startDate.plusMonths(1), new BigDecimal("9").negate(), account.getCurrency(), invoice.getInvoiceItems().get(0).getId()));
    existingInvoices.add(invoice);
    final List<InvoiceItem> generatedItems = fixedAndRecurringInvoiceItemGenerator.generateItems(account, UUID.randomUUID(), events, existingInvoices, startDate, account.getCurrency(), new HashMap<UUID, SubscriptionFutureNotificationDates>(), internalCallContext);
    assertTrue(generatedItems.isEmpty());
}
Also used : SubscriptionFutureNotificationDates(org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates) 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) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) 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) LinkedList(java.util.LinkedList) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) BillingEventSet(org.killbill.billing.junction.BillingEventSet) ItemAdjInvoiceItem(org.killbill.billing.invoice.model.ItemAdjInvoiceItem) 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) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 18 with BillingEvent

use of org.killbill.billing.junction.BillingEvent 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 19 with BillingEvent

use of org.killbill.billing.junction.BillingEvent 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 20 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testAutoInvoiceOffAccount.

@Test(groups = "fast")
public void testAutoInvoiceOffAccount() throws Exception {
    final MockBillingEventSet events = new MockBillingEventSet();
    events.setAccountInvoiceOff(true);
    final SubscriptionBase sub = createSubscription();
    final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1);
    final Plan plan = new MockPlan();
    final BigDecimal rate1 = TEN;
    final PlanPhase phase = createMockMonthlyPlanPhase(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 UUID accountId = UUID.randomUUID();
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, targetDate, Currency.USD, internalCallContext);
    assertNull(invoiceWithMetadata.getInvoice());
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) MockPlan(org.killbill.billing.catalog.MockPlan) 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) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

BillingEvent (org.killbill.billing.junction.BillingEvent)98 Test (org.testng.annotations.Test)82 DateTime (org.joda.time.DateTime)52 LocalDate (org.joda.time.LocalDate)49 Plan (org.killbill.billing.catalog.api.Plan)42 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)41 MockPlan (org.killbill.billing.catalog.MockPlan)40 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)40 BigDecimal (java.math.BigDecimal)36 ArrayList (java.util.ArrayList)36 UUID (java.util.UUID)35 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)35 BillingEventSet (org.killbill.billing.junction.BillingEventSet)33 Invoice (org.killbill.billing.invoice.api.Invoice)32 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)32 TreeSet (java.util.TreeSet)30 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)27 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)26 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)25 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)25