Search in sources :

Example 86 with PlanPhase

use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testSingleEventWithExistingInvoice.

@Test(groups = "fast")
public void testSingleEventWithExistingInvoice() throws InvoiceApiException, CatalogApiException {
    final BillingEventSet events = new MockBillingEventSet();
    final SubscriptionBase sub = createSubscription();
    final LocalDate startDate = invoiceUtil.buildDate(2011, 9, 1);
    final Plan plan1 = new MockPlan();
    final BigDecimal rate = FIVE;
    final PlanPhase phase1 = createMockMonthlyPlanPhase(rate);
    final BillingEvent event1 = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan1, phase1, 1);
    events.add(event1);
    LocalDate targetDate = invoiceUtil.buildDate(2011, 12, 1);
    final InvoiceWithMetadata invoiceWithMetadata1 = generator.generateInvoice(account, events, null, targetDate, Currency.USD, internalCallContext);
    final List<Invoice> existingInvoices = new ArrayList<Invoice>();
    final Invoice invoice1 = invoiceWithMetadata1.getInvoice();
    existingInvoices.add(invoice1);
    targetDate = invoiceUtil.buildDate(2011, 12, 3);
    final InvoiceWithMetadata invoiceWithMetadata2 = generator.generateInvoice(account, events, existingInvoices, targetDate, Currency.USD, internalCallContext);
    final Invoice invoice2 = invoiceWithMetadata2.getInvoice();
    assertNull(invoice2);
}
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) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) 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) Test(org.testng.annotations.Test)

Example 87 with PlanPhase

use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testCancelEOTWithFullItemAdjustment.

@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/654")
public void testCancelEOTWithFullItemAdjustment() throws CatalogApiException, InvoiceApiException {
    final BigDecimal rate = new BigDecimal("39.95");
    final BillingEventSet events = new MockBillingEventSet();
    final SubscriptionBase sub = createSubscription();
    final LocalDate startDate = invoiceUtil.buildDate(2016, 10, 9);
    final LocalDate endDate = invoiceUtil.buildDate(2016, 11, 9);
    final Plan plan = new MockPlan();
    final PlanPhase phase = createMockMonthlyPlanPhase(rate);
    final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 9);
    events.add(event);
    final LocalDate targetDate = invoiceUtil.buildDate(2016, 10, 9);
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, targetDate, Currency.USD, internalCallContext);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertNotNull(invoice);
    assertEquals(invoice.getNumberOfItems(), 1);
    assertEquals(invoice.getBalance(), KillBillMoney.of(rate, invoice.getCurrency()));
    assertEquals(invoice.getInvoiceItems().get(0).getSubscriptionId(), sub.getId());
    assertEquals(invoice.getInvoiceItems().get(0).getInvoiceItemType(), InvoiceItemType.RECURRING);
    assertEquals(invoice.getInvoiceItems().get(0).getStartDate(), startDate);
    assertEquals(invoice.getInvoiceItems().get(0).getEndDate(), endDate);
    // Cancel EOT and Add the item adjustment
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(account, sub, endDate.toDateTimeAtStartOfDay(), null, phase, ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 9, BillingMode.IN_ADVANCE, "Cancel", 2L, SubscriptionBaseTransitionType.CANCEL);
    events.add(event2);
    final InvoiceItem itemAdj = new ItemAdjInvoiceItem(invoice.getInvoiceItems().get(0), new LocalDate(2016, 10, 12), rate.negate(), Currency.USD);
    invoice.addInvoiceItem(itemAdj);
    final List<Invoice> existingInvoices = new ArrayList<Invoice>();
    existingInvoices.add(invoice);
    final InvoiceWithMetadata invoiceWithMetadata2 = generator.generateInvoice(account, events, existingInvoices, targetDate, Currency.USD, internalCallContext);
    final Invoice invoice2 = invoiceWithMetadata2.getInvoice();
    assertNull(invoice2);
}
Also used : 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) 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) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockPlan(org.killbill.billing.catalog.MockPlan) 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) Test(org.testng.annotations.Test)

Example 88 with PlanPhase

use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.

the class TestInvoiceHelper method generateRegularInvoice.

public UUID generateRegularInvoice(final Account account, final LocalDate targetDate, final CallContext callContext) throws Exception {
    final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class);
    Mockito.when(subscription.getId()).thenReturn(UUID.randomUUID());
    Mockito.when(subscription.getBundleId()).thenReturn(new UUID(0L, 0L));
    final BillingEventSet events = new MockBillingEventSet();
    final Plan plan = MockPlan.createBicycleNoTrialEvergreen1USD();
    final PlanPhase planPhase = MockPlanPhase.create1USDMonthlyEvergreen();
    final DateTime effectiveDate = new DateTime().minusDays(1);
    final Currency currency = Currency.USD;
    final BigDecimal fixedPrice = null;
    events.add(createMockBillingEvent(account, subscription, effectiveDate, plan, planPhase, fixedPrice, BigDecimal.ONE, currency, BillingPeriod.MONTHLY, 1, BillingMode.IN_ADVANCE, "", 1L, SubscriptionBaseTransitionType.CREATE));
    Mockito.when(billingApi.getBillingEventsForAccountAndUpdateAccountBCD(Mockito.<UUID>any(), Mockito.<DryRunArguments>any(), Mockito.<InternalCallContext>any())).thenReturn(events);
    final InvoiceNotifier invoiceNotifier = new NullInvoiceNotifier();
    final InvoiceDispatcher dispatcher = new InvoiceDispatcher(generator, accountApi, billingApi, subscriptionApi, invoiceDao, internalCallContextFactory, invoiceNotifier, invoicePluginDispatcher, locker, busService.getBus(), null, invoiceConfig, clock, parkedAccountsManager);
    Invoice invoice = dispatcher.processAccountFromNotificationOrBusEvent(account.getId(), targetDate, new DryRunFutureDateArguments(), internalCallContext);
    Assert.assertNotNull(invoice);
    final InternalCallContext context = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
    List<InvoiceModelDao> invoices = invoiceDao.getInvoicesByAccount(context);
    Assert.assertEquals(invoices.size(), 0);
    invoice = dispatcher.processAccountFromNotificationOrBusEvent(account.getId(), targetDate, null, context);
    Assert.assertNotNull(invoice);
    invoices = invoiceDao.getInvoicesByAccount(context);
    Assert.assertEquals(invoices.size(), 1);
    return invoice.getId();
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) NullInvoiceNotifier(org.killbill.billing.invoice.notification.NullInvoiceNotifier) InvoiceNotifier(org.killbill.billing.invoice.api.InvoiceNotifier) InvoiceModelDao(org.killbill.billing.invoice.dao.InvoiceModelDao) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) MutableInternalCallContext(org.killbill.billing.callcontext.MutableInternalCallContext) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) NullInvoiceNotifier(org.killbill.billing.invoice.notification.NullInvoiceNotifier) BillingEventSet(org.killbill.billing.junction.BillingEventSet) Currency(org.killbill.billing.catalog.api.Currency) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) UUID(java.util.UUID)

Example 89 with PlanPhase

use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testWithSingleMonthlyEvent.

@Test(groups = "fast")
public void testWithSingleMonthlyEvent() 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 = 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 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, 11, 1));
}
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 90 with PlanPhase

use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.

the class TestDefaultInvoiceGenerator method testWithSingleMonthlyEventWithLeadingProRation.

@Test(groups = "fast")
public void testWithSingleMonthlyEventWithLeadingProRation() 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 rate = TEN;
    final PlanPhase phase = createMockMonthlyPlanPhase(rate);
    final BillingEvent event = createBillingEvent(sub.getId(), sub.getBundleId(), startDate, plan, phase, 15);
    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);
    final BigDecimal expectedNumberOfBillingCycles;
    expectedNumberOfBillingCycles = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
    final BigDecimal expectedAmount = KillBillMoney.of(expectedNumberOfBillingCycles.multiply(rate), invoice.getCurrency());
    assertEquals(invoice.getBalance(), expectedAmount);
}
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)

Aggregations

PlanPhase (org.killbill.billing.catalog.api.PlanPhase)98 Plan (org.killbill.billing.catalog.api.Plan)77 Test (org.testng.annotations.Test)71 MockPlan (org.killbill.billing.catalog.MockPlan)50 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)49 LocalDate (org.joda.time.LocalDate)47 DateTime (org.joda.time.DateTime)43 BillingEventSet (org.killbill.billing.junction.BillingEventSet)43 BigDecimal (java.math.BigDecimal)42 BillingEvent (org.killbill.billing.junction.BillingEvent)41 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)40 Invoice (org.killbill.billing.invoice.api.Invoice)39 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)36 UUID (java.util.UUID)34 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)22 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)22 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)22 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)22 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)21 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)21