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;
}
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());
}
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());
}
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;
}
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;
}
Aggregations