use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestFixedAndRecurringInvoiceItemGenerator method testIsSameDayAndSameSubscriptionWithSameDateAndSubscriptionId.
@Test(groups = "fast")
public void testIsSameDayAndSameSubscriptionWithSameDateAndSubscriptionId() {
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-01-08"), plan, phase, fixedPriceAmount, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
assertTrue(fixedAndRecurringInvoiceItemGenerator.isSameDayAndSameSubscription(prevInvoiceItem, event, internalCallContext));
}
use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestFixedAndRecurringInvoiceItemGeneratorWithOptimization method testFixedPrice.
@Test(groups = "fast")
public void testFixedPrice() throws InvoiceApiException {
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 DateTime startDate = new DateTime("2020-01-01");
final BillingEvent event = invoiceUtil.createMockBillingEvent(account, subscription, startDate, plan, phase, fixedPriceAmount, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
events.add(event);
// Only look for older invoices 1 month from NOW (we assume targetDate = NOW as time pass normally)
final Period maxInvoiceLimit = new Period("P1m");
// Initial invoicing (targetDate1 = startDate)
// There is no existing invoice
// => Should generate the item
// 2020-01-01
final LocalDate targetDate1 = startDate.toLocalDate();
final LocalDate cuttoffDate1 = targetDate1.minus(maxInvoiceLimit);
final AccountInvoices existingInvoices1 = new AccountInvoicesExp(cuttoffDate1, null, ImmutableList.of());
final InvoiceGeneratorResult result1 = fixedAndRecurringInvoiceItemGenerator.generateItems(account, UUID.randomUUID(), events, existingInvoices1, targetDate1, account.getCurrency(), new HashMap<UUID, SubscriptionFutureNotificationDates>(), null, internalCallContext);
assertEquals(result1.getItems().size(), 1);
assertEquals(result1.getItems().get(0).getInvoiceItemType(), InvoiceItemType.FIXED);
assertEquals(result1.getItems().get(0).getStartDate().compareTo(new LocalDate("2020-01-01")), 0);
// One month after invoicing, optimization does not kick-in yet
// There is an existing invoice
// => Should not regenerate the item
// 2020-02-01
final LocalDate targetDate2 = startDate.toLocalDate().plusMonths(1);
final LocalDate cuttoffDate2 = targetDate2.minus(maxInvoiceLimit);
final Invoice invoice = new DefaultInvoice(account.getId(), clock.getUTCToday(), targetDate2, account.getCurrency());
invoice.addInvoiceItem(new FixedPriceInvoiceItem(UUID.randomUUID(), clock.getUTCNow(), invoice.getId(), account.getId(), subscription.getBundleId(), subscription.getId(), null, event.getPlan().getName(), event.getPlanPhase().getName(), null, "Buggy fixed item", startDate.toLocalDate(), fixedPriceAmount, account.getCurrency()));
final AccountInvoices existingInvoices2 = new AccountInvoicesExp(cuttoffDate2, null, ImmutableList.of(invoice));
final InvoiceGeneratorResult result2 = fixedAndRecurringInvoiceItemGenerator.generateItems(account, UUID.randomUUID(), events, existingInvoices2, targetDate2, account.getCurrency(), new HashMap<UUID, SubscriptionFutureNotificationDates>(), null, internalCallContext);
assertEquals(result2.getItems().size(), 0);
// Two month after invoicing, optimization *does* not kick-in
// There is no existing invoice (optimization removed it)
// => Should not regenerate the item
// 2020-03-01;
final LocalDate targetDate3 = startDate.toLocalDate().plusMonths(2);
final LocalDate cuttoffDate3 = targetDate3.minus(maxInvoiceLimit);
final AccountInvoices existingInvoices3 = new AccountInvoicesExp(cuttoffDate3, null, ImmutableList.of());
final InvoiceGeneratorResult result3 = fixedAndRecurringInvoiceItemGenerator.generateItems(account, UUID.randomUUID(), events, existingInvoices3, targetDate3, account.getCurrency(), new HashMap<UUID, SubscriptionFutureNotificationDates>(), null, internalCallContext);
assertEquals(result3.getItems().size(), 0);
}
use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestFixedAndRecurringInvoiceItemGenerator method testTooManyFixedInvoiceItemsForGivenSubscriptionAndStartDate.
@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/664")
public void testTooManyFixedInvoiceItemsForGivenSubscriptionAndStartDate() 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(null, price, BillingPeriod.NO_BILLING_PERIOD, PhaseType.TRIAL);
final BillingEvent event = invoiceUtil.createMockBillingEvent(account, subscription, startDate.toDateTimeAtStartOfDay(), plan, planPhase, amount, null, account.getCurrency(), BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
events.add(event);
// Simulate a bunch of fixed items for that subscription and start date (simulate bad data on disk)
final List<Invoice> existingInvoices = new LinkedList<Invoice>();
for (int i = 0; i < 20; i++) {
final Invoice invoice = new DefaultInvoice(account.getId(), clock.getUTCToday(), startDate, account.getCurrency());
invoice.addInvoiceItem(new FixedPriceInvoiceItem(UUID.randomUUID(), clock.getUTCNow(), invoice.getId(), account.getId(), subscription.getBundleId(), subscription.getId(), null, event.getPlan().getName(), event.getPlanPhase().getName(), null, "Buggy fixed item", startDate, amount, account.getCurrency()));
existingInvoices.add(invoice);
}
final List<InvoiceItem> generatedItems = fixedAndRecurringInvoiceItemGenerator.generateItems(account, UUID.randomUUID(), events, new AccountInvoices(null, null, existingInvoices), startDate, account.getCurrency(), new HashMap<UUID, SubscriptionFutureNotificationDates>(), null, internalCallContext).getItems();
// There will be one proposed, but because it will match one of ones in the existing list and we don't repair, it won't be returned
assertEquals(generatedItems.size(), 0);
}
use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceFormatter method testFormattedAmountUSAndGBP.
@Test(groups = "fast")
public void testFormattedAmountUSAndGBP() throws Exception {
final FixedPriceInvoiceItem fixedItem = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), new BigDecimal("1499.95"), Currency.GBP);
final Invoice invoice = new DefaultInvoice(UUID.randomUUID(), new LocalDate(), new LocalDate(), Currency.GBP);
invoice.addInvoiceItem(fixedItem);
checkOutput(invoice, "<tr>\n" + " <td class=\"amount\"><strong>{{invoice.formattedChargedAmount}}</strong></td>\n" + "</tr>\n" + "<tr>\n" + " <td class=\"amount\"><strong>{{invoice.formattedPaidAmount}}</strong></td>\n" + "</tr>\n" + "<tr>\n" + " <td class=\"amount\"><strong>{{invoice.formattedBalance}}</strong></td>\n" + "</tr>", "<tr>\n" + " <td class=\"amount\"><strong>£1,499.95</strong></td>\n" + "</tr>\n" + "<tr>\n" + " <td class=\"amount\"><strong>£0.00</strong></td>\n" + "</tr>\n" + "<tr>\n" + " <td class=\"amount\"><strong>£1,499.95</strong></td>\n" + "</tr>", Locale.US);
}
use of org.killbill.billing.invoice.model.FixedPriceInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceFormatter method testFormattedAmountUSAndEUR.
@Test(groups = "fast")
public void testFormattedAmountUSAndEUR() throws Exception {
final FixedPriceInvoiceItem fixedItem = new FixedPriceInvoiceItem(UUID.randomUUID(), UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, new LocalDate(), new BigDecimal("2635.14"), Currency.EUR);
final Invoice invoice = new DefaultInvoice(UUID.randomUUID(), new LocalDate(), new LocalDate(), Currency.EUR);
invoice.addInvoiceItem(fixedItem);
checkOutput(invoice, "<tr>\n" + " <td class=\"amount\"><strong>{{invoice.formattedChargedAmount}}</strong></td>\n" + "</tr>\n" + "<tr>\n" + " <td class=\"amount\"><strong>{{invoice.formattedPaidAmount}}</strong></td>\n" + "</tr>\n" + "<tr>\n" + " <td class=\"amount\"><strong>{{invoice.formattedBalance}}</strong></td>\n" + "</tr>", "<tr>\n" + " <td class=\"amount\"><strong>€2,635.14</strong></td>\n" + "</tr>\n" + "<tr>\n" + " <td class=\"amount\"><strong>€0.00</strong></td>\n" + "</tr>\n" + "<tr>\n" + " <td class=\"amount\"><strong>€2,635.14</strong></td>\n" + "</tr>", Locale.US);
}
Aggregations