final LocalDate transitionStartDate = internalTenantContext.toLocalDate(billingEvent.getEffectiveDate()); if (i == billingEvents.size() - 1) { addTransitionTimesForBillingEvent(transitionStartDate, endDate, billingEvent.getBillCycleDayLocal()); } else { final BillingEvent nextBillingEvent = billingEvents.get(i + 1); final LocalDate nextEndDate = internalTenantContext.toLocalDate(nextBillingEvent.getEffectiveDate()); addTransitionTimesForBillingEvent(transitionStartDate, nextEndDate, billingEvent.getBillCycleDayLocal());
protected BillingEvent createNewDisableEvent(final DateTime disabledDurationStart, final BillingEvent previousEvent, final Catalog catalog) throws CatalogApiException { final int billCycleDay = previousEvent.getBillCycleDayLocal(); final SubscriptionBase subscription = previousEvent.getSubscription(); final DateTime effectiveDate = disabledDurationStart; final PlanPhase planPhase = previousEvent.getPlanPhase(); final Plan plan = previousEvent.getPlan(); // Make sure to set the fixed price to null and the billing period to NO_BILLING_PERIOD, // which makes invoice disregard this event final BigDecimal fixedPrice = null; final BillingPeriod billingPeriod = BillingPeriod.NO_BILLING_PERIOD; final Currency currency = previousEvent.getCurrency(); final String description = ""; final SubscriptionBaseTransitionType type = SubscriptionBaseTransitionType.START_BILLING_DISABLED; final Long totalOrdering = globaltotalOrder.getAndIncrement(); return new DefaultBillingEvent(subscription, effectiveDate, true, plan, planPhase, fixedPrice, currency, billingPeriod, billCycleDay, description, totalOrdering, type, catalog, true); }
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; }
protected BillingEvent createMockBillingEvent(final int bcd, final DateTime effectiveDate, final BillingPeriod billingPeriod, final List<Usage> usages) { final BillingEvent result = Mockito.mock(BillingEvent.class); Mockito.when(result.getCurrency()).thenReturn(Currency.BTC); Mockito.when(result.getBillCycleDayLocal()).thenReturn(bcd); Mockito.when(result.getEffectiveDate()).thenReturn(effectiveDate); Mockito.when(result.getBillingPeriod()).thenReturn(billingPeriod); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getId()).thenReturn(subscriptionId); Mockito.when(subscription.getBundleId()).thenReturn(bundleId); Mockito.when(result.getSubscription()).thenReturn(subscription); final Product product = Mockito.mock(Product.class); Mockito.when(product.getName()).thenReturn(productName); final Plan plan = Mockito.mock(Plan.class); Mockito.when(plan.getName()).thenReturn(planName); Mockito.when(plan.getProduct()).thenReturn(product); Mockito.when(result.getPlan()).thenReturn(plan); final PlanPhase phase = Mockito.mock(PlanPhase.class); Mockito.when(phase.getName()).thenReturn(phaseName); Mockito.when(result.getPlanPhase()).thenReturn(phase); Mockito.when(result.getUsages()).thenReturn(usages); return result; }
protected BillingEvent createNewReenableEvent(final DateTime odEventTime, final BillingEvent previousEvent, final Catalog catalog, final InternalTenantContext context) throws CatalogApiException { // All fields are populated with the event state from before the blocking period, for invoice to resume invoicing final int billCycleDay = previousEvent.getBillCycleDayLocal(); final SubscriptionBase subscription = previousEvent.getSubscription(); final DateTime effectiveDate = odEventTime; final PlanPhase planPhase = previousEvent.getPlanPhase(); final BigDecimal fixedPrice = previousEvent.getFixedPrice(); final Plan plan = previousEvent.getPlan(); final Currency currency = previousEvent.getCurrency(); final String description = ""; final BillingPeriod billingPeriod = previousEvent.getBillingPeriod(); final SubscriptionBaseTransitionType type = SubscriptionBaseTransitionType.END_BILLING_DISABLED; final Long totalOrdering = globaltotalOrder.getAndIncrement(); return new DefaultBillingEvent(subscription, effectiveDate, true, plan, planPhase, fixedPrice, currency, billingPeriod, billCycleDay, description, totalOrdering, type, catalog, false); }
private Integer computeAccountBCD(final BillingEventSet result) throws CatalogApiException { BillingEvent oldestAccountAlignedBillingEvent = null; for (final BillingEvent event : result) { if (event.getBillingAlignment() != BillingAlignment.ACCOUNT) { continue; } final BigDecimal recurringPrice = event.getRecurringPrice(event.getEffectiveDate()); final boolean hasRecurringPrice = recurringPrice != null; // Note: could be zero (BCD would still be set, by convention) final boolean hasUsage = event.getUsages() != null && !event.getUsages().isEmpty(); if (!hasRecurringPrice && !hasUsage) { // Nothing to bill, ignored for the purpose of BCD calculation continue; } if (oldestAccountAlignedBillingEvent == null || event.getEffectiveDate().compareTo(oldestAccountAlignedBillingEvent.getEffectiveDate()) < 0 || (event.getEffectiveDate().compareTo(oldestAccountAlignedBillingEvent.getEffectiveDate()) == 0 && event.getTotalOrdering().compareTo(oldestAccountAlignedBillingEvent.getTotalOrdering()) < 0)) { oldestAccountAlignedBillingEvent = event; } } if (oldestAccountAlignedBillingEvent == null) { return null; } // BCD in the account timezone final int accountBCDCandidate = oldestAccountAlignedBillingEvent.getBillCycleDayLocal(); Preconditions.checkState(accountBCDCandidate > 0, "Wrong Account BCD calculation for event: " + oldestAccountAlignedBillingEvent); return accountBCDCandidate; }
final LocalDate endDate = (nextEvent == null) ? null : internalCallContext.toLocalDate(nextEvent.getEffectiveDate()); final int billCycleDayLocal = thisEvent.getBillCycleDayLocal();