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); }
initialPhaseType = null; } else { initialPhaseType = initialPhase.getPhaseType();
final PhaseJson phaseJson = new PhaseJson(phase.getPhaseType().toString(), prices); phases.add(phaseJson);
@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()); }
@Override public DateTime dateOfFirstRecurringNonZeroCharge(final DateTime subscriptionStartDate, final PhaseType initialPhaseType) { DateTime result = subscriptionStartDate.toDateTime(); boolean skipPhase = initialPhaseType == null ? false : true; for (final PlanPhase phase : getAllPhases()) { if (skipPhase) { if (phase.getPhaseType() != initialPhaseType) { continue; } else { skipPhase = false; } } if (phase.getRecurringPrice() == null || phase.getRecurringPrice().isZero()) { result = phase.getDuration().addToDateTime(result); } else { break; } } return result; }
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()); }
assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
@Test(groups = "slow") public void testSingleBasePlan() throws SubscriptionBaseMigrationApiException { final DateTime startDate = clock.getUTCNow().minusMonths(2); final DateTime beforeMigration = clock.getUTCNow(); final AccountMigration toBeMigrated = testUtil.createAccountForMigrationWithRegularBasePlan(startDate); final DateTime afterMigration = clock.getUTCNow(); testListener.pushExpectedEvent(NextEvent.MIGRATE_ENTITLEMENT); migrationApi.migrate(toBeMigrated, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundles = subscriptionInternalApi.getBundlesForAccount(toBeMigrated.getAccountKey(), internalCallContext); assertEquals(bundles.size(), 1); final SubscriptionBaseBundle bundle = bundles.get(0); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(bundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1); final SubscriptionBase subscription = subscriptions.get(0); assertTrue(subscription.getStartDate().compareTo(startDate) == 0); assertEquals(subscription.getEndDate(), null); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "shotgun-annual"); assertEquals(subscription.getChargedThroughDate(), startDate.plusYears(1)); assertListenerStatus(); }
assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
assertEquals(subscription.getEndDate(), null); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-monthly"); assertEquals(subscription.getEndDate(), null); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-monthly");
assertEquals(baseSubscription.getEndDate(), null); assertEquals(baseSubscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(baseSubscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(baseSubscription.getState(), EntitlementState.ACTIVE); assertEquals(baseSubscription.getCurrentPlan().getName(), "shotgun-annual"); assertEquals(aoSubscription.getEndDate(), null); assertEquals(aoSubscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(aoSubscription.getCurrentPhase().getPhaseType(), PhaseType.DISCOUNT); assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE); assertEquals(aoSubscription.getCurrentPlan().getName(), "telescopic-scope-monthly");
assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL); assertListenerStatus(); currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT); currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-monthly"); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "shotgun-annual");
assertEquals(newBaseSubscription.getCurrentPhase().getPhaseType(), PhaseType.TRIAL);
@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(); }
assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL); assertListenerStatus();
assertTrue(subscription.getStartDate().compareTo(startDate) == 0); assertEquals(subscription.getCurrentPriceList().getName(), PriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(subscription.getCurrentPhase().getPhaseType(), PhaseType.EVERGREEN); assertEquals(subscription.getState(), EntitlementState.ACTIVE); assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-annual");
@Test(groups = "slow") public void testCancelSubscriptionEOTWithNoChargeThroughDate() throws SubscriptionBaseApiException { final String prod = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME; // CREATE final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, prod, term, planSet); PlanPhase trialPhase = subscription.getCurrentPhase(); assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL); // NEXT PHASE final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration()); testUtil.checkNextPhaseChange(subscription, 1, expectedPhaseTrialChange); // MOVE TO NEXT PHASE testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); trialPhase = subscription.getCurrentPhase(); assertEquals(trialPhase.getPhaseType(), PhaseType.EVERGREEN); testListener.pushExpectedEvent(NextEvent.CANCEL); // CANCEL subscription.cancel(callContext); assertListenerStatus(); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNull(currentPhase); testUtil.checkNextPhaseChange(subscription, 0, null); assertListenerStatus(); }
assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL);
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); }