Search in sources :

Example 56 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class ContiguousIntervalUsageInArrear method computeNextNotificationDate.

private LocalDate computeNextNotificationDate() {
    LocalDate result = null;
    final Iterator<BillingEvent> eventIt = billingEvents.iterator();
    BillingEvent nextEvent = eventIt.next();
    while (eventIt.hasNext()) {
        final BillingEvent thisEvent = nextEvent;
        nextEvent = eventIt.next();
        final LocalDate startDate = internalTenantContext.toLocalDate(thisEvent.getEffectiveDate());
        final LocalDate endDate = internalTenantContext.toLocalDate(nextEvent.getEffectiveDate());
        final BillingIntervalDetail bid = new BillingIntervalDetail(startDate, endDate, targetDate, thisEvent.getBillCycleDayLocal(), usage.getBillingPeriod(), BillingMode.IN_ARREAR);
        final LocalDate nextBillingCycleDate = bid.getNextBillingCycleDate();
        result = (result == null || result.compareTo(nextBillingCycleDate) < 0) ? nextBillingCycleDate : result;
    }
    final LocalDate startDate = internalTenantContext.toLocalDate(nextEvent.getEffectiveDate());
    final BillingIntervalDetail bid = new BillingIntervalDetail(startDate, null, targetDate, nextEvent.getBillCycleDayLocal(), usage.getBillingPeriod(), BillingMode.IN_ARREAR);
    final LocalDate nextBillingCycleDate = bid.getNextBillingCycleDate();
    result = (result == null || result.compareTo(nextBillingCycleDate) < 0) ? nextBillingCycleDate : result;
    return result;
}
Also used : BillingIntervalDetail(org.killbill.billing.invoice.generator.BillingIntervalDetail) BillingEvent(org.killbill.billing.junction.BillingEvent) LocalDate(org.joda.time.LocalDate)

Example 57 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class TestBillingApi method testBillingEventsWithBlock.

@Test(groups = "fast")
public void testBillingEventsWithBlock() throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
    final Plan nextPlan = catalog.findPlan("3-PickupTrialEvergreen10USD", clock.getUTCNow());
    final PlanPhase nextPhase = nextPlan.getAllPhases()[1];
    final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase);
    final Account account = createAccount(32);
    final BlockingState blockingState1 = new DefaultBlockingState(bunId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1));
    final BlockingState blockingState2 = new DefaultBlockingState(bunId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(2));
    blockingStateDao.setBlockingStatesAndPostBlockingTransitionEvent(ImmutableMap.<BlockingState, Optional<UUID>>of(blockingState1, Optional.<UUID>absent(), blockingState2, Optional.<UUID>absent()), internalCallContext);
    final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext);
    Assert.assertEquals(events.size(), 3);
    final Iterator<BillingEvent> it = events.iterator();
    checkEvent(it.next(), nextPlan, account.getBillCycleDayLocal(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString(), nextPhase.getFixed().getPrice(), nextPhase.getRecurring().getRecurringPrice());
    checkEvent(it.next(), nextPlan, account.getBillCycleDayLocal(), subId, now.plusDays(1), nextPhase, SubscriptionBaseTransitionType.START_BILLING_DISABLED.toString(), null, null);
    checkEvent(it.next(), nextPlan, account.getBillCycleDayLocal(), subId, now.plusDays(2), nextPhase, SubscriptionBaseTransitionType.END_BILLING_DISABLED.toString(), nextPhase.getFixed().getPrice(), nextPhase.getRecurring().getRecurringPrice());
}
Also used : Account(org.killbill.billing.account.api.Account) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) BlockingState(org.killbill.billing.entitlement.api.BlockingState) BillingEvent(org.killbill.billing.junction.BillingEvent) Plan(org.killbill.billing.catalog.api.Plan) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) Test(org.testng.annotations.Test)

Example 58 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class TestBillingApi method testBillingEventsSubscriptionAligned.

@Test(groups = "fast")
public void testBillingEventsSubscriptionAligned() throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
    final Plan nextPlan = catalog.findPlan("3-PickupTrialEvergreen10USD", clock.getUTCNow());
    final PlanPhase nextPhase = nextPlan.getAllPhases()[1];
    final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase);
    final Account account = createAccount(1);
    catalog.setBillingAlignment(BillingAlignment.SUBSCRIPTION);
    final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext);
    // The expected BCD is when the subscription started since we skip the trial phase
    checkFirstEvent(events, nextPlan, subscription.getStartDate().getDayOfMonth(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString());
}
Also used : Account(org.killbill.billing.account.api.Account) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) BillingEvent(org.killbill.billing.junction.BillingEvent) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 59 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class BlockingCalculator method createBundleSubscriptionMap.

protected Hashtable<UUID, List<SubscriptionBase>> createBundleSubscriptionMap(final SortedSet<BillingEvent> billingEvents) {
    final Hashtable<UUID, List<SubscriptionBase>> result = new Hashtable<UUID, List<SubscriptionBase>>();
    for (final BillingEvent event : billingEvents) {
        final UUID bundleId = event.getSubscription().getBundleId();
        List<SubscriptionBase> subs = result.get(bundleId);
        if (subs == null) {
            subs = new ArrayList<SubscriptionBase>();
            result.put(bundleId, subs);
        }
        if (!result.get(bundleId).contains(event.getSubscription())) {
            subs.add(event.getSubscription());
        }
    }
    return result;
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BillingEvent(org.killbill.billing.junction.BillingEvent) UUID(java.util.UUID)

Example 60 with BillingEvent

use of org.killbill.billing.junction.BillingEvent in project killbill by killbill.

the class BlockingCalculator method createNewEvents.

protected SortedSet<BillingEvent> createNewEvents(final List<DisabledDuration> disabledDuration, final SortedSet<BillingEvent> billingEvents, final SubscriptionBase subscription, final InternalTenantContext context) throws CatalogApiException {
    final SortedSet<BillingEvent> result = new TreeSet<BillingEvent>();
    final Catalog catalog = catalogService.getFullCatalog(true, true, context);
    for (final DisabledDuration duration : disabledDuration) {
        // The first one before the blocked duration
        final BillingEvent precedingInitialEvent = precedingBillingEventForSubscription(duration.getStart(), billingEvents, subscription);
        // The last one during of before the duration
        final BillingEvent precedingFinalEvent = precedingBillingEventForSubscription(duration.getEnd(), billingEvents, subscription);
        if (precedingInitialEvent != null) {
            // there is a preceding billing event
            result.add(createNewDisableEvent(duration.getStart(), precedingInitialEvent, catalog, context));
            if (duration.getEnd() != null) {
                // no second event in the pair means they are still disabled (no re-enable)
                result.add(createNewReenableEvent(duration.getEnd(), precedingFinalEvent, catalog, context));
            }
        } else if (precedingFinalEvent != null) {
            // can happen - e.g. phase event
            result.add(createNewReenableEvent(duration.getEnd(), precedingFinalEvent, catalog, context));
        }
    // N.B. if there's no precedingInitial and no precedingFinal then there's nothing to do
    }
    return result;
}
Also used : TreeSet(java.util.TreeSet) BillingEvent(org.killbill.billing.junction.BillingEvent) Catalog(org.killbill.billing.catalog.api.Catalog)

Aggregations

BillingEvent (org.killbill.billing.junction.BillingEvent)98 Test (org.testng.annotations.Test)82 DateTime (org.joda.time.DateTime)52 LocalDate (org.joda.time.LocalDate)49 Plan (org.killbill.billing.catalog.api.Plan)42 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)41 MockPlan (org.killbill.billing.catalog.MockPlan)40 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)40 BigDecimal (java.math.BigDecimal)36 ArrayList (java.util.ArrayList)36 UUID (java.util.UUID)35 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)35 BillingEventSet (org.killbill.billing.junction.BillingEventSet)33 Invoice (org.killbill.billing.invoice.api.Invoice)32 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)32 TreeSet (java.util.TreeSet)30 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)27 FixedPriceInvoiceItem (org.killbill.billing.invoice.model.FixedPriceInvoiceItem)26 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)25 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)25