protected BillingEvent createRealEvent(final DateTime effectiveDate, final SubscriptionBase subscription, final SubscriptionBaseTransitionType type) { final Account account = this.account; final Integer billCycleDay = 1; final PlanPhase planPhase = new MockPlanPhase(); final Plan plan = new MockPlan(); final BigDecimal fixedPrice = BigDecimal.TEN; final BigDecimal recurringPrice = BigDecimal.TEN; final Currency currency = Currency.USD; final String description = ""; final BillingModeType billingModeType = BillingModeType.IN_ADVANCE; final BillingPeriod billingPeriod = BillingPeriod.MONTHLY; final Long totalOrdering = 0L; final DateTimeZone tz = DateTimeZone.UTC; return new DefaultBillingEvent(account, subscription, effectiveDate, plan, planPhase, fixedPrice, recurringPrice, currency, billingPeriod, billCycleDay, billingModeType, description, totalOrdering, type, tz); }
@Override public int compareTo(final BillingEvent e1) { if (!getSubscription().getId().equals(e1.getSubscription().getId())) { // First order by subscription return getSubscription().getId().compareTo(e1.getSubscription().getId()); } else { // subscriptions are the same if (!getEffectiveDate().equals(e1.getEffectiveDate())) { // Secondly order by date return getEffectiveDate().compareTo(e1.getEffectiveDate()); } else { // dates and subscriptions are the same if (SubscriptionBaseTransitionType.START_BILLING_DISABLED.equals(getTransitionType())) { if (SubscriptionBaseTransitionType.END_BILLING_DISABLED.equals(e1.getTransitionType())) { if (SubscriptionBaseTransitionType.END_BILLING_DISABLED.equals(getTransitionType())) { return -1; } else if (SubscriptionBaseTransitionType.END_BILLING_DISABLED.equals(getTransitionType())) { if (SubscriptionBaseTransitionType.START_BILLING_DISABLED.equals(e1.getTransitionType())) { if (SubscriptionBaseTransitionType.START_BILLING_DISABLED.equals(getTransitionType())) { return getTotalOrdering().compareTo(e1.getTotalOrdering());
private void addBillingEventsForSubscription(final List<SubscriptionBase> subscriptions, final SubscriptionBaseBundle bundle, final Account account, final InternalCallContext context, final DefaultBillingEventSet result) { boolean updatedAccountBCD = false; for (final SubscriptionBase subscription : subscriptions) { for (final EffectiveSubscriptionInternalEvent transition : subscriptionApi.getBillingTransitions(subscription, context)) { try { final int bcdLocal = bcdCalculator.calculateBcd(bundle, subscription, transition, account, context); if (account.getBillCycleDayLocal() == 0 && !updatedAccountBCD) { final MutableAccountData modifiedData = account.toMutableAccountData(); modifiedData.setBillCycleDayLocal(bcdLocal); accountApi.updateAccount(account.getExternalKey(), modifiedData, context); updatedAccountBCD = true; } final BillingEvent event = new DefaultBillingEvent(account, transition, subscription, bcdLocal, account.getCurrency(), catalogService.getFullCatalog()); result.add(event); } catch (CatalogApiException e) { log.error("Failing to identify catalog components while creating BillingEvent from transition: " + transition.getId().toString(), e); } catch (Exception e) { log.warn("Failed while getting BillingEvent", e); } } } }
protected BillingEvent createNewDisableEvent(final DateTime odEventTime, final BillingEvent previousEvent) { final Account account = previousEvent.getAccount(); final int billCycleDay = previousEvent.getBillCycleDayLocal(); final SubscriptionBase subscription = previousEvent.getSubscription(); final DateTime effectiveDate = odEventTime; 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 BigDecimal recurringPrice = null; final BillingPeriod billingPeriod = BillingPeriod.NO_BILLING_PERIOD; final Currency currency = previousEvent.getCurrency(); final String description = ""; final BillingModeType billingModeType = previousEvent.getBillingMode(); final SubscriptionBaseTransitionType type = SubscriptionBaseTransitionType.START_BILLING_DISABLED; final Long totalOrdering = globaltotalOrder.getAndIncrement(); final DateTimeZone tz = previousEvent.getTimeZone(); return new DefaultBillingEvent(account, subscription, effectiveDate, plan, planPhase, fixedPrice, recurringPrice, currency, billingPeriod, billCycleDay, billingModeType, description, totalOrdering, type, tz); }
private BillingEvent createEvent(final SubscriptionBase sub, final DateTime effectiveDate, final SubscriptionBaseTransitionType type, final long totalOrdering) { final int billCycleDay = 1; final Plan shotgun = new MockPlan(); final PlanPhase shotgunMonthly = createMockMonthlyPlanPhase(null, BigDecimal.ZERO, PhaseType.TRIAL); final Account account = new MockAccountBuilder().build(); return new DefaultBillingEvent(account, sub, effectiveDate, shotgun, shotgunMonthly, BigDecimal.ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, billCycleDay, BillingModeType.IN_ADVANCE, "Test Event 1", totalOrdering, type, DateTimeZone.UTC); }
protected BillingEvent createNewReenableEvent(final DateTime odEventTime, final BillingEvent previousEvent) { // All fields are populated with the event state from before the blocking period, for invoice to resume invoicing final Account account = previousEvent.getAccount(); final int billCycleDay = previousEvent.getBillCycleDayLocal(); final SubscriptionBase subscription = previousEvent.getSubscription(); final DateTime effectiveDate = odEventTime; final PlanPhase planPhase = previousEvent.getPlanPhase(); final Plan plan = previousEvent.getPlan(); final BigDecimal fixedPrice = previousEvent.getFixedPrice(); final BigDecimal recurringPrice = previousEvent.getRecurringPrice(); final Currency currency = previousEvent.getCurrency(); final String description = ""; final BillingModeType billingModeType = previousEvent.getBillingMode(); final BillingPeriod billingPeriod = previousEvent.getBillingPeriod(); final SubscriptionBaseTransitionType type = SubscriptionBaseTransitionType.END_BILLING_DISABLED; final Long totalOrdering = globaltotalOrder.getAndIncrement(); final DateTimeZone tz = previousEvent.getTimeZone(); return new DefaultBillingEvent(account, subscription, effectiveDate, plan, planPhase, fixedPrice, recurringPrice, currency, billingPeriod, billCycleDay, billingModeType, description, totalOrdering, type, tz); }