Search in sources :

Example 6 with DefaultPrice

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

the class TestFixedAndRecurringInvoiceItemGenerator method testIsSameDayAndSameSubscriptionWithNullPrevEvent.

// 
// 
// IS_SAME_DAY_AND_SAME_SUBSCRIPTION TESTS
// 
// 
@Test(groups = "fast")
public void testIsSameDayAndSameSubscriptionWithNullPrevEvent() {
    final Plan plan = new MockPlan("my-plan");
    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 InvoiceItem prevInvoiceItem = null;
    final BillingEvent event = invoiceUtil.createMockBillingEvent(account, subscription, new DateTime("2016-02-01"), plan, phase, fixedPriceAmount, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
    assertFalse(fixedAndRecurringInvoiceItemGenerator.isSameDayAndSameSubscription(prevInvoiceItem, event, internalCallContext));
}
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) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) BigDecimal(java.math.BigDecimal) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 7 with DefaultPrice

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

the class TestFixedAndRecurringInvoiceItemGenerator method createDefaultBillingEvent.

private BillingEvent createDefaultBillingEvent(final LocalDate eventDate, final BigDecimal fixedAmount, final BigDecimal recurringPrice, final SubscriptionBaseTransitionType eventType, final int billCycleDay, final long ordering, final BillingMode billingMode) {
    final MockInternationalPrice price = new MockInternationalPrice(new DefaultPrice(recurringPrice, account.getCurrency()));
    final MockPlan plan = new MockPlan("my-plan");
    plan.setRecurringBillingMode(billingMode);
    final PlanPhase planPhase = new MockPlanPhase(price, null, BillingPeriod.MONTHLY, PhaseType.EVERGREEN);
    final boolean isDisabledOrBlocked = (eventType == SubscriptionBaseTransitionType.CANCEL || eventType == SubscriptionBaseTransitionType.START_BILLING_DISABLED);
    final BillingPeriod billingPeriod = recurringPrice == null ? BillingPeriod.NO_BILLING_PERIOD : BillingPeriod.MONTHLY;
    // Rely on real (junction) BillingEvent instead of MockBillingEvent to test the real behavior
    return new DefaultBillingEvent(subscription.getId(), subscription.getBundleId(), eventDate.toDateTimeAtStartOfDay(), plan, planPhase, fixedAmount, recurringPrice, ImmutableList.of(), account.getCurrency(), billingPeriod, billCycleDay, "desc", ordering, eventType, isDisabledOrBlocked);
}
Also used : MockPlan(org.killbill.billing.catalog.MockPlan) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent)

Example 8 with DefaultPrice

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

the class TestFixedAndRecurringInvoiceItemGenerator method testIsSameDayAndSameSubscriptionWithDifferentDate.

@Test(groups = "fast")
public void testIsSameDayAndSameSubscriptionWithDifferentDate() {
    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-02-01"), plan, phase, fixedPriceAmount, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
    assertFalse(fixedAndRecurringInvoiceItemGenerator.isSameDayAndSameSubscription(prevInvoiceItem, event, internalCallContext));
}
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) 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) 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) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 9 with DefaultPrice

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

the class TestFixedAndRecurringInvoiceItemGenerator method testOverlappingExistingItems.

@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/664")
public void testOverlappingExistingItems() 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(), null, event.getPlan().getName(), event.getPlanPhase().getName(), null, startDate, startDate.plusDays(29), amount, amount, account.getCurrency()));
    // Correct one already generated
    invoice.addInvoiceItem(new RecurringInvoiceItem(UUID.randomUUID(), startDate.toDateTimeAtStartOfDay(), invoice.getId(), account.getId(), subscription.getBundleId(), subscription.getId(), null, event.getPlan().getName(), event.getPlanPhase().getName(), null, startDate, startDate.plusMonths(1), amount, amount, account.getCurrency()));
    existingInvoices.add(invoice);
    try {
        // There will be one proposed item but the tree will refuse the merge because of the bad state on disk
        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();
        // Maybe we could auto-fix-it one day?
        // assertEquals(generatedItems.size(), 1);
        // assertTrue(generatedItems.get(0) instanceof RepairAdjInvoiceItem);
        // assertEquals(generatedItems.get(0).getAmount().compareTo(amount.negate()), 0);
        // assertEquals(generatedItems.get(0).getLinkedItemId(), invoice.getInvoiceItems().get(0).getId());
        fail();
    } catch (final InvoiceApiException e) {
        assertEquals(e.getCode(), ErrorCode.UNEXPECTED_ERROR.getCode());
        assertTrue(e.getCause().getMessage().startsWith("Double billing detected"));
    }
}
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) AccountInvoices(org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) RecurringInvoiceItem(org.killbill.billing.invoice.model.RecurringInvoiceItem) HashMap(java.util.HashMap) 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) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) Test(org.testng.annotations.Test)

Example 10 with DefaultPrice

use of org.killbill.billing.catalog.DefaultPrice 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));
}
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) 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) 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) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) DefaultBillingEvent(org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

DefaultPrice (org.killbill.billing.catalog.DefaultPrice)38 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)34 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)34 MockPlan (org.killbill.billing.catalog.MockPlan)33 Test (org.testng.annotations.Test)32 LocalDate (org.joda.time.LocalDate)30 BillingEvent (org.killbill.billing.junction.BillingEvent)30 Plan (org.killbill.billing.catalog.api.Plan)28 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)28 BigDecimal (java.math.BigDecimal)27 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)26 BillingEventSet (org.killbill.billing.junction.BillingEventSet)25 Invoice (org.killbill.billing.invoice.api.Invoice)23 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)23 RecurringInvoiceItem (org.killbill.billing.invoice.model.RecurringInvoiceItem)22 AccountInvoices (org.killbill.billing.invoice.optimizer.InvoiceOptimizerBase.AccountInvoices)22 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)19 RepairAdjInvoiceItem (org.killbill.billing.invoice.model.RepairAdjInvoiceItem)19 DefaultBillingEvent (org.killbill.billing.junction.plumbing.billing.DefaultBillingEvent)19 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)18