Search in sources :

Example 6 with InvoiceItemGeneratorLogger

use of org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testInArrear5.

// 
// Scenario: Call processRecurringEvent 2 in a row
// - IN_ARREAR
// - one CREATE billing event
// - one future CHANGE billing event
// - targetDate = CHANGE date
// 
// => Expect one item + 1 notification first time and no new item for the CHANGE
// 
@Test(groups = "fast")
public void testInArrear5() throws InvoiceApiException {
    final BillingMode billingMode = BillingMode.IN_ARREAR;
    final UUID invoiceId = UUID.randomUUID();
    final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger = new InvoiceItemGeneratorLogger(invoiceId, account.getId(), "recurring", logger);
    final Map<UUID, SubscriptionFutureNotificationDates> perSubscriptionFutureNotificationDates = new HashMap<>();
    final LocalDate eventDate1 = new LocalDate("2020-01-01");
    final BillingEvent event1 = createDefaultBillingEvent(eventDate1, null, BigDecimal.TEN, SubscriptionBaseTransitionType.CREATE, 1, 1, billingMode);
    final LocalDate eventDate2 = new LocalDate("2020-01-15");
    final BillingEvent event2 = createDefaultBillingEvent(eventDate2, null, BigDecimal.ONE, SubscriptionBaseTransitionType.CHANGE, 1, 2, billingMode);
    final LocalDate targetDate = eventDate2;
    List<InvoiceItem> invoiceItems = fixedAndRecurringInvoiceItemGenerator.processRecurringEvent(invoiceId, account.getId(), event1, event2, targetDate, account.getCurrency(), invoiceItemGeneratorLogger, perSubscriptionFutureNotificationDates, internalCallContext);
    assertEquals(invoiceItems.size(), 1);
    assertEquals(invoiceItems.get(0).getStartDate(), eventDate1);
    assertEquals(invoiceItems.get(0).getEndDate(), eventDate2);
    assertEquals(invoiceItems.get(0).getAmount().compareTo(BigDecimal.TEN), -1);
    SubscriptionFutureNotificationDates notifications = perSubscriptionFutureNotificationDates.get(subscription.getId());
    assertEquals(notifications.getNextRecurringDate(), eventDate1.plusMonths(1));
    // Call processRecurringEvent another time for  eventDate2
    invoiceItems = fixedAndRecurringInvoiceItemGenerator.processRecurringEvent(invoiceId, account.getId(), event2, null, targetDate, account.getCurrency(), invoiceItemGeneratorLogger, perSubscriptionFutureNotificationDates, internalCallContext);
    assertEquals(invoiceItems.size(), 0);
    notifications = perSubscriptionFutureNotificationDates.get(subscription.getId());
    assertEquals(notifications.getNextRecurringDate(), eventDate1.plusMonths(1));
}
Also used : SubscriptionFutureNotificationDates(org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates) 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) HashMap(java.util.HashMap) BillingMode(org.killbill.billing.catalog.api.BillingMode) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID) InvoiceItemGeneratorLogger(org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 7 with InvoiceItemGeneratorLogger

use of org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testInAdvance6.

// 
// Scenario: Start with future notification and verify the CANCEL event clears it
// - IN_ADVANCE
// - one CANCEL billing event
// - targetDate = CANCEL date
// 
// => Expect nothing
// 
@Test(groups = "fast")
public void testInAdvance6() throws InvoiceApiException {
    final BillingMode billingMode = BillingMode.IN_ADVANCE;
    final UUID invoiceId = UUID.randomUUID();
    final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger = new InvoiceItemGeneratorLogger(invoiceId, account.getId(), "recurring", logger);
    final Map<UUID, SubscriptionFutureNotificationDates> perSubscriptionFutureNotificationDates = new HashMap<>();
    final LocalDate eventDate1 = new LocalDate("2020-01-01");
    /*final BillingEvent event1 = */
    createDefaultBillingEvent(eventDate1, null, BigDecimal.TEN, SubscriptionBaseTransitionType.CREATE, 1, 1, billingMode);
    // Set next notification date
    SubscriptionFutureNotificationDates subscriptionFutureNotificationDates = new SubscriptionFutureNotificationDates(billingMode);
    subscriptionFutureNotificationDates.updateNextRecurringDateIfRequired(eventDate1.plusMonths(1));
    perSubscriptionFutureNotificationDates.put(subscription.getId(), subscriptionFutureNotificationDates);
    final LocalDate eventDate2 = new LocalDate("2020-01-15");
    final BillingEvent event2 = createDefaultBillingEvent(eventDate2, null, null, SubscriptionBaseTransitionType.CANCEL, 1, 2, billingMode);
    final LocalDate targetDate = eventDate2;
    final List<InvoiceItem> invoiceItems = fixedAndRecurringInvoiceItemGenerator.processRecurringEvent(invoiceId, account.getId(), event2, null, targetDate, account.getCurrency(), invoiceItemGeneratorLogger, perSubscriptionFutureNotificationDates, internalCallContext);
    assertEquals(invoiceItems.size(), 0);
    final SubscriptionFutureNotificationDates notifications = perSubscriptionFutureNotificationDates.get(subscription.getId());
    assertNull(notifications.getNextRecurringDate());
}
Also used : SubscriptionFutureNotificationDates(org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates) 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) HashMap(java.util.HashMap) BillingMode(org.killbill.billing.catalog.api.BillingMode) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID) InvoiceItemGeneratorLogger(org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 8 with InvoiceItemGeneratorLogger

use of org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testInArrear1.

// 
// Scenario: Verify CREATE (IN_ARREAR) generates initial future notification and nothing more
// - IN_ARREAR
// - one CREATE billing event
// - targetDate = CREATE date
// 
// => Expect 1 notification
// 
@Test(groups = "fast")
public void testInArrear1() throws InvoiceApiException {
    final BillingMode billingMode = BillingMode.IN_ARREAR;
    final UUID invoiceId = UUID.randomUUID();
    final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger = new InvoiceItemGeneratorLogger(invoiceId, account.getId(), "recurring", logger);
    final Map<UUID, SubscriptionFutureNotificationDates> perSubscriptionFutureNotificationDates = new HashMap<>();
    final LocalDate eventDate1 = new LocalDate("2020-01-01");
    final BillingEvent event1 = createDefaultBillingEvent(eventDate1, null, BigDecimal.TEN, SubscriptionBaseTransitionType.CREATE, 1, 1, billingMode);
    final LocalDate targetDate = eventDate1;
    final List<InvoiceItem> invoiceItems = fixedAndRecurringInvoiceItemGenerator.processRecurringEvent(invoiceId, account.getId(), event1, null, targetDate, account.getCurrency(), invoiceItemGeneratorLogger, perSubscriptionFutureNotificationDates, internalCallContext);
    assertEquals(invoiceItems.size(), 0);
    final SubscriptionFutureNotificationDates notifications = perSubscriptionFutureNotificationDates.get(subscription.getId());
    assertEquals(notifications.getNextRecurringDate(), eventDate1.plusMonths(1));
}
Also used : SubscriptionFutureNotificationDates(org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates) 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) HashMap(java.util.HashMap) BillingMode(org.killbill.billing.catalog.api.BillingMode) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID) InvoiceItemGeneratorLogger(org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 9 with InvoiceItemGeneratorLogger

use of org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testInAdvance4b.

// 
// Scenario: Similar to testInAdvance4a but the CHANGE event is a month after leading to 2 items generated
// - IN_ADVANCE
// - one CREATE billing event
// - one future CHANGE billing event (used to compute period endDate)
// - targetDate = CREATE date + 1 month
// 
// => Expect 2 items + 1 notification
// 
@Test(groups = "fast")
public void testInAdvance4b() throws InvoiceApiException {
    final BillingMode billingMode = BillingMode.IN_ADVANCE;
    final UUID invoiceId = UUID.randomUUID();
    final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger = new InvoiceItemGeneratorLogger(invoiceId, account.getId(), "recurring", logger);
    final Map<UUID, SubscriptionFutureNotificationDates> perSubscriptionFutureNotificationDates = new HashMap<>();
    final LocalDate eventDate1 = new LocalDate("2020-01-01");
    final BillingEvent event1 = createDefaultBillingEvent(eventDate1, null, BigDecimal.TEN, SubscriptionBaseTransitionType.CREATE, 1, 1, billingMode);
    final LocalDate eventDate2 = new LocalDate("2020-02-15");
    final BillingEvent event2 = createDefaultBillingEvent(eventDate2, null, BigDecimal.ONE, SubscriptionBaseTransitionType.CHANGE, 1, 2, billingMode);
    final LocalDate targetDate = eventDate1.plusMonths(1);
    final List<InvoiceItem> invoiceItems = fixedAndRecurringInvoiceItemGenerator.processRecurringEvent(invoiceId, account.getId(), event1, event2, targetDate, account.getCurrency(), invoiceItemGeneratorLogger, perSubscriptionFutureNotificationDates, internalCallContext);
    assertEquals(invoiceItems.size(), 2);
    assertEquals(invoiceItems.get(0).getStartDate(), eventDate1);
    assertEquals(invoiceItems.get(0).getEndDate(), eventDate1.plusMonths(1));
    assertEquals(invoiceItems.get(0).getAmount().compareTo(BigDecimal.TEN), 0);
    assertEquals(invoiceItems.get(1).getStartDate(), eventDate1.plusMonths(1));
    assertEquals(invoiceItems.get(1).getEndDate(), eventDate2);
    assertEquals(invoiceItems.get(1).getAmount().compareTo(BigDecimal.TEN), -1);
    final SubscriptionFutureNotificationDates notifications = perSubscriptionFutureNotificationDates.get(subscription.getId());
    assertEquals(notifications.getNextRecurringDate(), eventDate2);
}
Also used : SubscriptionFutureNotificationDates(org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates) 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) HashMap(java.util.HashMap) BillingMode(org.killbill.billing.catalog.api.BillingMode) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID) InvoiceItemGeneratorLogger(org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 10 with InvoiceItemGeneratorLogger

use of org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testInArrear4a.

// 
// Scenario:
// - IN_ARREAR
// - one CREATE billing event
// - one future CHANGE billing event (used to compute period endDate)
// - targetDate = CREATE date
// 
// => Expect 1 notification
// 
@Test(groups = "fast")
public void testInArrear4a() throws InvoiceApiException {
    final BillingMode billingMode = BillingMode.IN_ARREAR;
    final UUID invoiceId = UUID.randomUUID();
    final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger = new InvoiceItemGeneratorLogger(invoiceId, account.getId(), "recurring", logger);
    final Map<UUID, SubscriptionFutureNotificationDates> perSubscriptionFutureNotificationDates = new HashMap<>();
    final LocalDate eventDate1 = new LocalDate("2020-01-01");
    final BillingEvent event1 = createDefaultBillingEvent(eventDate1, null, BigDecimal.TEN, SubscriptionBaseTransitionType.CREATE, 1, 1, billingMode);
    final LocalDate eventDate2 = new LocalDate("2020-01-15");
    final BillingEvent event2 = createDefaultBillingEvent(eventDate2, null, BigDecimal.ONE, SubscriptionBaseTransitionType.CHANGE, 1, 2, billingMode);
    final LocalDate targetDate = eventDate1;
    final List<InvoiceItem> invoiceItems = fixedAndRecurringInvoiceItemGenerator.processRecurringEvent(invoiceId, account.getId(), event1, event2, targetDate, account.getCurrency(), invoiceItemGeneratorLogger, perSubscriptionFutureNotificationDates, internalCallContext);
    assertEquals(invoiceItems.size(), 0);
    final SubscriptionFutureNotificationDates notifications = perSubscriptionFutureNotificationDates.get(subscription.getId());
    assertEquals(notifications.getNextRecurringDate(), eventDate1.plusMonths(1));
}
Also used : SubscriptionFutureNotificationDates(org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates) 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) HashMap(java.util.HashMap) BillingMode(org.killbill.billing.catalog.api.BillingMode) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID) InvoiceItemGeneratorLogger(org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

HashMap (java.util.HashMap)14 UUID (java.util.UUID)14 LocalDate (org.joda.time.LocalDate)14 BillingMode (org.killbill.billing.catalog.api.BillingMode)14 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)14 InvoiceItemGeneratorLogger (org.killbill.billing.invoice.generator.InvoiceItemGenerator.InvoiceItemGeneratorLogger)14 SubscriptionFutureNotificationDates (org.killbill.billing.invoice.generator.InvoiceWithMetadata.SubscriptionFutureNotificationDates)14 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)14 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)14 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)14 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)14 BillingEvent (org.killbill.billing.junction.BillingEvent)14 DefaultBillingEvent (org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent)14 Test (org.testng.annotations.Test)14