@Override public String getPlanPhaseName() { return SubscriptionBaseTransitionType.CANCEL.equals(subscriptionTransitionType) ? null : "BicycleTrialEvergreen1USD-trial"; }
@Override public int hashCode() { int result = account != null ? account.hashCode() : 0; result = 31 * result + billCycleDayLocal; result = 31 * result + (subscription != null ? subscription.hashCode() : 0); result = 31 * result + (effectiveDate != null ? effectiveDate.hashCode() : 0); result = 31 * result + (planPhase != null ? planPhase.hashCode() : 0); result = 31 * result + (plan != null ? plan.hashCode() : 0); result = 31 * result + (fixedPrice != null ? fixedPrice.hashCode() : 0); result = 31 * result + (recurringPrice != null ? recurringPrice.hashCode() : 0); result = 31 * result + (currency != null ? currency.hashCode() : 0); result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (billingModeType != null ? billingModeType.hashCode() : 0); result = 31 * result + (billingPeriod != null ? billingPeriod.hashCode() : 0); result = 31 * result + (type != null ? type.hashCode() : 0); result = 31 * result + (totalOrdering != null ? totalOrdering.hashCode() : 0); result = 31 * result + (timeZone != null ? timeZone.hashCode() : 0); return result; }
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()); }
UUID.randomUUID().toString(), UUID.randomUUID().toString(), SubscriptionBaseTransitionType.CREATE.toString(), PhaseType.DISCOUNT.toString(), auditLogs);
@Test(groups = "fast") public void testBillingEventsWithBlock() throws CatalogApiException, AccountApiException { final Plan nextPlan = catalog.findPlan("PickupTrialEvergreen10USD", clock.getUTCNow()); final PlanPhase nextPhase = nextPlan.getAllPhases()[1]; final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(32); blockingStateDao.setBlockingState(new DefaultBlockingState(bunId, BlockingStateType.SUBSCRIPTION_BUNDLE, DISABLED_BUNDLE, "test", true, true, true, now.plusDays(1)), clock, internalCallContext); blockingStateDao.setBlockingState(new DefaultBlockingState(bunId, BlockingStateType.SUBSCRIPTION_BUNDLE, CLEAR_BUNDLE, "test", false, false, false, now.plusDays(2)), clock, internalCallContext); final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); Assert.assertEquals(events.size(), 3); final Iterator<BillingEvent> it = events.iterator(); checkEvent(it.next(), nextPlan, account.getBillCycleDayLocal(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString(), nextPhase.getFixedPrice(), nextPhase.getRecurringPrice()); checkEvent(it.next(), nextPlan, account.getBillCycleDayLocal(), subId, now.plusDays(1), nextPhase, SubscriptionBaseTransitionType.START_BILLING_DISABLED.toString(), null, null); checkEvent(it.next(), nextPlan, account.getBillCycleDayLocal(), subId, now.plusDays(2), nextPhase, SubscriptionBaseTransitionType.END_BILLING_DISABLED.toString(), nextPhase.getFixedPrice(), nextPhase.getRecurringPrice()); }
@Test(groups = "fast") public void testBillingEventsSubscriptionAligned() throws CatalogApiException, AccountApiException { final Plan nextPlan = catalog.findPlan("PickupTrialEvergreen10USD", clock.getUTCNow()); final PlanPhase nextPhase = nextPlan.getAllPhases()[1]; final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(1); catalog.setBillingAlignment(BillingAlignment.SUBSCRIPTION); final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); // The expected BCD is when the subscription started since we skip the trial phase checkFirstEvent(events, nextPlan, subscription.getStartDate().getDayOfMonth(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString()); }
@Override public PlanPhaseSpecifier getPlanPhaseSpecifier() { return SubscriptionBaseTransitionType.CANCEL.equals(subscriptionTransitionType) ? null : new PlanPhaseSpecifier("BicycleTrialEvergreen1USD", ProductCategory.BASE, BillingPeriod.NO_BILLING_PERIOD, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.FIXEDTERM); }
+ ((subscriptionId == null) ? 0 : subscriptionId.hashCode()); result = prime * result + ((totalOrdering == null) ? 0 : totalOrdering.hashCode()); result = prime * result + ((transitionType == null) ? 0 : transitionType.hashCode());
@Test(groups = "fast") public void testBillingEventsAccountAligned() throws CatalogApiException, AccountApiException { final Plan nextPlan = catalog.findPlan("PickupTrialEvergreen10USD", clock.getUTCNow()); final PlanPhase nextPhase = nextPlan.getAllPhases()[1]; final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(32); final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); // The expected BCD is the account BCD (account aligned by default) checkFirstEvent(events, nextPlan, 32, subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString()); }
if (SubscriptionBaseTransitionType.START_BILLING_DISABLED.equals(getTransitionType())) { if (SubscriptionBaseTransitionType.END_BILLING_DISABLED.equals(e1.getTransitionType())) { return 1; } else if (SubscriptionBaseTransitionType.START_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())) { return -1; } else if (SubscriptionBaseTransitionType.END_BILLING_DISABLED.equals(e1.getTransitionType())) { if (SubscriptionBaseTransitionType.START_BILLING_DISABLED.equals(getTransitionType())) {
@Test(groups = "fast") public void testBillingEventsNoBillingPeriod() throws CatalogApiException, AccountApiException { final Plan nextPlan = catalog.findPlan("PickupTrialEvergreen10USD", clock.getUTCNow()); // The trial has no billing period final PlanPhase nextPhase = nextPlan.getAllPhases()[0]; final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(10); final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); checkFirstEvent(events, nextPlan, account.getBillCycleDayLocal(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString()); }
@Test(groups = "fast") public void testBillingEventsBundleAligned() throws CatalogApiException, AccountApiException { final Plan nextPlan = catalog.findPlan("Horn1USD", clock.getUTCNow()); final PlanPhase nextPhase = nextPlan.getAllPhases()[0]; final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(1); catalog.setBillingAlignment(BillingAlignment.BUNDLE); ((MockSubscription) subscription).setPlan(catalog.findPlan("PickupTrialEvergreen10USD", now)); final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); // The expected BCD is when the subscription started checkFirstEvent(events, nextPlan, subscription.getStartDate().getDayOfMonth(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString()); }
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(); }