private static ProductCategory getTypeFromSubscription(final Plan plan) { if (plan != null && plan.getProduct() != null) { final Product product = plan.getProduct(); if (product.getCatalogName() != null && product.getCategory() != null) { return product.getCategory(); } } return null; }
@Override public boolean apply(final SubscriptionBase input) { return ProductCategory.BASE.equals(input.getLastActiveProduct().getCategory()); } }).orNull();
@Override public boolean apply(final SubscriptionBase input) { return ProductCategory.BASE.equals(input.getLastActiveProduct().getCategory()); } }).orNull(); // null for standalone subscriptions
private void checkChangePlan(final DefaultSubscriptionBase subscription, final String expProduct, final ProductCategory expCategory, final BillingPeriod expBillingPeriod, final PhaseType expPhase) { final Plan currentPlan = subscription.getCurrentPlan(); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), expProduct); assertEquals(currentPlan.getProduct().getCategory(), expCategory); assertEquals(currentPlan.getBillingPeriod(), expBillingPeriod); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), expPhase); }
@Override public List<Listing> getAvailableBasePlanListings() { final List<Listing> availBasePlans = new ArrayList<Listing>(); for (Plan plan : getCurrentPlans()) { if (plan.getProduct().getCategory().equals(ProductCategory.BASE)) { for (PriceList priceList : getPriceLists().getAllPriceLists()) { for (Plan priceListPlan : priceList.getPlans()) { if (priceListPlan.getName().equals(plan.getName()) && priceListPlan.getProduct().getName().equals(plan.getProduct().getName())) { availBasePlans.add(new DefaultListing(priceListPlan, priceList)); } } } } } return availBasePlans; } }
@Override public SubscriptionBase getBaseSubscription(final UUID bundleId, final InternalTenantContext context) { for (final SubscriptionBase cur : subscriptions) { if (cur.getBundleId().equals(bundleId) && cur.getCurrentPlan().getProduct().getCategory() == ProductCategory.BASE) { return buildSubscription((DefaultSubscriptionBase) cur, context); } } return null; }
ProductJson productJson = productMap.get(product.getName()); if (productJson == null) { productJson = new ProductJson(product.getCategory().toString(), product.getName(), toProductNames(product.getIncluded()),
@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()); }
@Test(groups = "fast") public void testFromSubscription() throws Exception { BusinessSubscriptionEvent event; final DateTime now = new DateTime(); event = BusinessSubscriptionEvent.subscriptionCreated(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.ADD); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "ADD_BASE"); event = BusinessSubscriptionEvent.subscriptionCancelled(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.CANCEL); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "CANCEL_BASE"); event = BusinessSubscriptionEvent.subscriptionChanged(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.CHANGE); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "CHANGE_BASE"); event = BusinessSubscriptionEvent.subscriptionPhaseChanged(subscription.getCurrentPlan().getName(), subscription.getState(), catalog, now, now); // The subscription is still active, it's a system change Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.SYSTEM_CHANGE); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "SYSTEM_CHANGE_BASE"); subscription = new MockSubscription(SubscriptionState.CANCELLED, plan, phase); event = BusinessSubscriptionEvent.subscriptionPhaseChanged(subscription.getCurrentPlan().getName(), subscription.getState(), catalog, now, now); // The subscription is cancelled, it's a system cancellation Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.SYSTEM_CANCEL); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "SYSTEM_CANCEL_BASE"); }
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()); }
assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), newBaseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), newBaseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(subscriptions.size(), 2); final SubscriptionBase baseSubscription = (subscriptions.get(0).getCurrentPlan().getProduct().getCategory() == ProductCategory.BASE) ? subscriptions.get(0) : subscriptions.get(1); assertTrue(baseSubscription.getStartDate().compareTo(initalBPStart) == 0); assertEquals(baseSubscription.getChargedThroughDate(), initalBPStart.plusYears(1)); final SubscriptionBase aoSubscription = (subscriptions.get(0).getCurrentPlan().getProduct().getCategory() == ProductCategory.ADD_ON) ? subscriptions.get(0) : subscriptions.get(1);
@Test(groups = "slow") public void testCreateWithInitialPhase() throws SubscriptionBaseApiException { final DateTime init = clock.getUTCNow(); final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; testListener.pushExpectedEvent(NextEvent.CREATE); final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(bundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, PhaseType.EVERGREEN), clock.getUTCNow(), internalCallContext); assertNotNull(subscription); assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION); //assertEquals(subscription.getAccount(), account.getId()); assertEquals(subscription.getBundleId(), bundle.getId()); testUtil.assertDateWithin(subscription.getStartDate(), init, clock.getUTCNow()); testUtil.assertDateWithin(subscription.getBundleStartDate(), init, clock.getUTCNow()); final Plan currentPlan = subscription.getCurrentPlan(); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), productName); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN); assertListenerStatus(); }
assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), productName); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
assertNotNull(aoCurrentPlan); assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct); assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON); assertEquals(aoCurrentPlan.getBillingPeriod(), aoTerm); assertNotNull(aoCurrentPlan); assertEquals(aoCurrentPlan.getProduct().getName(), aoProduct); assertEquals(aoCurrentPlan.getProduct().getCategory(), ProductCategory.ADD_ON); assertEquals(aoCurrentPlan.getBillingPeriod(), aoTerm);
final Product product = currentPlan.getProduct(); productName = product.getName(); productCategory = product.getCategory();
assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.ANNUAL);
assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), "Assault-Rifle"); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.ANNUAL);
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); }