Search in sources :

Example 26 with MockInternationalPrice

use of org.killbill.billing.catalog.MockInternationalPrice in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testOverlappingItemsWithInvalidRepair.

@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/664")
public void testOverlappingItemsWithInvalidRepair() 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 event = 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(event);
    // Simulate a previous mis-bill: existing item is for [2016-01-01,2016-01-30], proposed will be for [2016-01-01,2016-02-01]
    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(), event.getPlan().getName(), event.getPlanPhase().getName(), startDate, startDate.plusDays(29), amount, amount, account.getCurrency()));
    // Also, the system has repaired a bigger period
    invoice.addInvoiceItem(new RepairAdjInvoiceItem(UUID.randomUUID(), startDate.toDateTimeAtStartOfDay(), invoice.getId(), account.getId(), startDate, startDate.plusDays(30), // Amount does not matter
    BigDecimal.ONE.negate(), account.getCurrency(), invoice.getInvoiceItems().get(0).getId()));
    existingInvoices.add(invoice);
    try {
        final List<InvoiceItem> generatedItems = fixedAndRecurringInvoiceItemGenerator.generateItems(account, UUID.randomUUID(), events, existingInvoices, startDate, account.getCurrency(), new HashMap<UUID, SubscriptionFutureNotificationDates>(), internalCallContext);
        fail();
    } catch (final InvoiceApiException e) {
        assertEquals(e.getCode(), ErrorCode.UNEXPECTED_ERROR.getCode());
        assertTrue(e.getCause().getMessage().startsWith("Invalid cancelledItem"));
    }
}
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) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) 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) UUID(java.util.UUID) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) RepairAdjInvoiceItem(org.killbill.billing.invoice.model.RepairAdjInvoiceItem) Test(org.testng.annotations.Test)

Example 27 with MockInternationalPrice

use of org.killbill.billing.catalog.MockInternationalPrice in project killbill by killbill.

the class TestFixedAndRecurringInvoiceItemGenerator method testItemPartiallyRepairedAndPartiallyAdjusted.

@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/664")
public void testItemPartiallyRepairedAndPartiallyAdjusted() 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()));
    // Repaired by the system
    invoice.addInvoiceItem(new RepairAdjInvoiceItem(UUID.randomUUID(), startDate.toDateTimeAtStartOfDay(), invoice.getId(), account.getId(), startDate.plusDays(1), startDate.plusMonths(1), new BigDecimal("9.68").negate(), account.getCurrency(), invoice.getInvoiceItems().get(0).getId()));
    // Item adjust the remaining
    invoice.addInvoiceItem(new ItemAdjInvoiceItem(invoice.getInvoiceItems().get(0), startDate, new BigDecimal("0.32").negate(), account.getCurrency()));
    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 28 with MockInternationalPrice

use of org.killbill.billing.catalog.MockInternationalPrice in project killbill by killbill.

the class TestInvoiceDao method testMixedModeInvoicePersistence.

@Test(groups = "slow")
public void testMixedModeInvoicePersistence() throws InvoiceApiException, CatalogApiException, EntityPersistenceException {
    final Currency currency = Currency.USD;
    final DefaultPrice zeroPrice = new DefaultPrice(BigDecimal.ZERO, Currency.USD);
    final MockInternationalPrice fixedPrice = new MockInternationalPrice(zeroPrice);
    final MockPlanPhase phase1 = new MockPlanPhase(null, fixedPrice);
    final BigDecimal cheapAmount = new BigDecimal("24.95");
    final DefaultPrice cheapPrice = new DefaultPrice(cheapAmount, Currency.USD);
    final MockInternationalPrice recurringPrice = new MockInternationalPrice(cheapPrice);
    final MockPlanPhase phase2 = new MockPlanPhase(recurringPrice, null);
    final MockPlan plan = new MockPlan();
    final SubscriptionBase subscription = getZombieSubscription();
    final DateTime effectiveDate1 = invoiceUtil.buildDate(2011, 1, 1).toDateTimeAtStartOfDay();
    final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate1, plan, phase1, fixedPrice.getPrice(currency), null, currency, BillingPeriod.MONTHLY, 1, BillingMode.IN_ADVANCE, "testEvent1", 1L, SubscriptionBaseTransitionType.CREATE);
    final BillingEventSet events = new MockBillingEventSet();
    events.add(event1);
    final DateTime effectiveDate2 = effectiveDate1.plusDays(30);
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate2, plan, phase2, null, recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingMode.IN_ADVANCE, "testEvent2", 2L, SubscriptionBaseTransitionType.CHANGE);
    events.add(event2);
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, new LocalDate(effectiveDate2), Currency.USD, context);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertNotNull(invoice);
    assertEquals(invoice.getNumberOfItems(), 2);
    assertEquals(invoice.getBalance().compareTo(cheapAmount), 0);
    invoiceUtil.createInvoice(invoice, context);
    final InvoiceModelDao savedInvoice = invoiceDao.getById(invoice.getId(), context);
    assertNotNull(savedInvoice);
    assertEquals(savedInvoice.getInvoiceItems().size(), 2);
    assertEquals(InvoiceModelDaoHelper.getBalance(savedInvoice).compareTo(cheapAmount), 0);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) InvoiceWithMetadata(org.killbill.billing.invoice.generator.InvoiceWithMetadata) LocalDate(org.joda.time.LocalDate) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) Currency(org.killbill.billing.catalog.api.Currency) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) BillingEventSet(org.killbill.billing.junction.BillingEventSet) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) Test(org.testng.annotations.Test)

Aggregations

DefaultPrice (org.killbill.billing.catalog.DefaultPrice)28 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)28 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)28 MockPlan (org.killbill.billing.catalog.MockPlan)27 Test (org.testng.annotations.Test)27 LocalDate (org.joda.time.LocalDate)26 BillingEvent (org.killbill.billing.junction.BillingEvent)25 BigDecimal (java.math.BigDecimal)23 Plan (org.killbill.billing.catalog.api.Plan)23 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)22 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)22 BillingEventSet (org.killbill.billing.junction.BillingEventSet)22 UUID (java.util.UUID)21 Invoice (org.killbill.billing.invoice.api.Invoice)20 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)20 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)20 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)20 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)20 ItemAdjInvoiceItem (org.killbill.billing.invoice.model.ItemAdjInvoiceItem)19 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)19