if (thePhase.getBillingPeriod() != null) { billingPeriod = thePhase.getBillingPeriod().toString(); } else { billingPeriod = null; mrr = getMrrFromBillingPeriod(thePhase.getBillingPeriod(), price); } else { price = BigDecimal.ZERO;
if (currentPhase.getBillingPeriod() != null) { billingPeriod = currentPhase.getBillingPeriod().toString(); } else { billingPeriod = null; mrr = getMrrFromBillingPeriod(currentPhase.getBillingPeriod(), price); } else { price = BigDecimal.ZERO;
@Test(groups = "fast") public void testConstructor() throws Exception { Assert.assertEquals(subscription.getRoundedMrr(), 0.0); Assert.assertEquals(subscription.getSlug(), phase.getName()); Assert.assertEquals(subscription.getPhase(), phase.getPhaseType().toString()); Assert.assertEquals(subscription.getBillingPeriod(), phase.getBillingPeriod()); Assert.assertEquals(subscription.getPrice(), phase.getRecurringPrice().getPrice(null)); Assert.assertEquals(subscription.getProductCategory(), product.getCategory()); Assert.assertEquals(subscription.getProductName(), product.getName()); Assert.assertEquals(subscription.getProductType(), product.getCatalogName()); Assert.assertEquals(subscription.getStartDate(), isubscription.getStartDate()); }
private void checkEvent(final BillingEvent event, final Plan nextPlan, final int BCD, final UUID id, final DateTime time, final PlanPhase nextPhase, final String desc, final InternationalPrice fixedPrice, final InternationalPrice recurringPrice) throws CatalogApiException { if (fixedPrice != null) { Assert.assertEquals(fixedPrice.getPrice(Currency.USD), event.getFixedPrice()); } else { assertNull(event.getFixedPrice()); } if (recurringPrice != null) { Assert.assertEquals(recurringPrice.getPrice(Currency.USD), event.getRecurringPrice()); } else { assertNull(event.getRecurringPrice()); } Assert.assertEquals(BCD, event.getBillCycleDayLocal()); Assert.assertEquals(id, event.getSubscription().getId()); Assert.assertEquals(time.getDayOfMonth(), event.getEffectiveDate().getDayOfMonth()); Assert.assertEquals(nextPhase, event.getPlanPhase()); Assert.assertEquals(nextPlan, event.getPlan()); if (!SubscriptionBaseTransitionType.START_BILLING_DISABLED.equals(event.getTransitionType())) { Assert.assertEquals(nextPhase.getBillingPeriod(), event.getBillingPeriod()); } Assert.assertEquals(BillingModeType.IN_ADVANCE, event.getBillingMode()); Assert.assertEquals(desc, event.getTransitionType().toString()); }
public BusinessInvoiceItemModelDao(@Nullable final String externalKey, final InvoiceItem invoiceItem, @Nullable final Plan plan, @Nullable final PlanPhase planPhase) { this(invoiceItem.getAmount(), planPhase != null ? planPhase.getBillingPeriod().toString() : null, invoiceItem.getCreatedDate(), invoiceItem.getCurrency(), /* Populate end date for fixed items for convenience (null in invoice_items table) */ (invoiceItem.getEndDate() == null && planPhase != null) ? invoiceItem.getStartDate().plus(planPhase.getDuration().toJodaPeriod()) : invoiceItem.getEndDate(), externalKey, invoiceItem.getInvoiceId(), invoiceItem.getId(), invoiceItem.getLinkedItemId(), invoiceItem.getInvoiceItemType().toString(), planPhase != null ? planPhase.getPhaseType().toString() : null, plan != null ? plan.getProduct().getCategory().toString() : null, plan != null ? plan.getProduct().getName() : null, plan != null ? plan.getProduct().getCatalogName() : null, planPhase != null ? planPhase.getName() : null, invoiceItem.getStartDate(), invoiceItem.getUpdatedDate()); }
private BillingEvent createBillingEvent(final UUID subscriptionId, final UUID bundleId, final LocalDate startDate, final Plan plan, final PlanPhase planPhase, final int billCycleDayLocal) throws CatalogApiException { final SubscriptionBase sub = createSubscription(subscriptionId, bundleId); final Currency currency = Currency.USD; return invoiceUtil.createMockBillingEvent(null, sub, startDate.toDateTimeAtStartOfDay(), plan, planPhase, planPhase.getFixedPrice() == null ? null : planPhase.getFixedPrice().getPrice(currency), planPhase.getRecurringPrice() == null ? null : planPhase.getRecurringPrice().getPrice(currency), currency, planPhase.getBillingPeriod(), billCycleDayLocal, BillingModeType.IN_ADVANCE, "Test", 1L, SubscriptionBaseTransitionType.CREATE); }
public DefaultBillingEvent(final Account account, final EffectiveSubscriptionInternalEvent transition, final SubscriptionBase subscription, final int billCycleDayLocal, final Currency currency, final Catalog catalog) throws CatalogApiException { this.account = account; this.billCycleDayLocal = billCycleDayLocal; this.subscription = subscription; effectiveDate = transition.getEffectiveTransitionTime(); final String planPhaseName = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? transition.getNextPhase() : transition.getPreviousPhase(); planPhase = (planPhaseName != null) ? catalog.findPhase(planPhaseName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final String planName = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? transition.getNextPlan() : transition.getPreviousPlan(); plan = (planName != null) ? catalog.findPlan(planName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final String nextPhaseName = transition.getNextPhase(); final PlanPhase nextPhase = (nextPhaseName != null) ? catalog.findPhase(nextPhaseName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final String prevPhaseName = transition.getPreviousPhase(); final PlanPhase prevPhase = (prevPhaseName != null) ? catalog.findPhase(prevPhaseName, transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; fixedPrice = (nextPhase != null && nextPhase.getFixedPrice() != null) ? nextPhase.getFixedPrice().getPrice(currency) : null; recurringPrice = (nextPhase != null && nextPhase.getRecurringPrice() != null) ? nextPhase.getRecurringPrice().getPrice(currency) : null; this.currency = currency; description = transition.getTransitionType().toString(); billingModeType = BillingModeType.IN_ADVANCE; billingPeriod = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? nextPhase.getBillingPeriod() : prevPhase.getBillingPeriod(); type = transition.getTransitionType(); totalOrdering = transition.getTotalOrdering(); timeZone = account.getTimeZone(); }
protected int calculateBcd(final SubscriptionBaseBundle bundle, final SubscriptionBase subscription, final EffectiveSubscriptionInternalEvent transition, final Account account, final InternalCallContext context) throws CatalogApiException, AccountApiException, SubscriptionBaseApiException { final Catalog catalog = catalogService.getFullCatalog(); final Plan prevPlan = (transition.getPreviousPlan() != null) ? catalog.findPlan(transition.getPreviousPlan(), transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final Plan nextPlan = (transition.getNextPlan() != null) ? catalog.findPlan(transition.getNextPlan(), transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final Plan plan = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? nextPlan : prevPlan; final Product product = plan.getProduct(); final PlanPhase prevPhase = (transition.getPreviousPhase() != null) ? catalog.findPhase(transition.getPreviousPhase(), transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final PlanPhase nextPhase = (transition.getNextPhase() != null) ? catalog.findPhase(transition.getNextPhase(), transition.getEffectiveTransitionTime(), transition.getSubscriptionStartDate()) : null; final PlanPhase phase = (transition.getTransitionType() != SubscriptionBaseTransitionType.CANCEL) ? nextPhase : prevPhase; final BillingAlignment alignment = catalog.billingAlignment( new PlanPhaseSpecifier(product.getName(), product.getCategory(), phase.getBillingPeriod(), transition.getNextPriceList(), phase.getPhaseType()), transition.getRequestedTransitionTime()); return calculateBcdForAlignment(alignment, bundle, subscription, account, catalog, plan, context); }