private void checkFirstEvent(final SortedSet<BillingEvent> events, final Plan nextPlan, final int BCD, final UUID id, final DateTime time, final PlanPhase nextPhase, final String desc) throws CatalogApiException { Assert.assertEquals(events.size(), 1); checkEvent(events.first(), nextPlan, BCD, id, time, nextPhase, desc, nextPhase.getFixedPrice(), nextPhase.getRecurringPrice()); }
@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 PlanDetailJson(final Listing listing) { final Plan plan = listing.getPlan(); if (plan == null) { this.productName = null; this.planName = null; this.billingPeriod = null; this.finalPhasePrice = ImmutableList.<PriceJson>of(); } else { this.productName = plan.getProduct() == null ? null : plan.getProduct().getName(); this.planName = plan.getName(); this.billingPeriod = plan.getBillingPeriod(); if (plan.getFinalPhase() == null || plan.getFinalPhase().getRecurringPrice() == null || plan.getFinalPhase().getRecurringPrice().getPrices() == null) { this.finalPhasePrice = ImmutableList.<PriceJson>of(); } else { this.finalPhasePrice = Lists.transform(ImmutableList.<Price>copyOf(plan.getFinalPhase().getRecurringPrice().getPrices()), new Function<Price, PriceJson>() { @Override public PriceJson apply(final Price price) { try { return new PriceJson(price); } catch (CurrencyValueNull e) { return new PriceJson(price.getCurrency().toString(), BigDecimal.ZERO); } } }); } } this.priceListName = listing.getPriceList() == null ? null : listing.getPriceList().getName(); }
for (final PlanPhase phase : plan.getAllPhases()) { final List<PriceJson> prices = new LinkedList<PriceJson>(); if (phase.getRecurringPrice() != null) { for (final Price price : phase.getRecurringPrice().getPrices()) { prices.add(new PriceJson(price));
@Test(groups = "fast") public void testFromListing() throws Exception { final Product product = Mockito.mock(Product.class); Mockito.when(product.getName()).thenReturn(UUID.randomUUID().toString()); final InternationalPrice price = Mockito.mock(InternationalPrice.class); final PlanPhase planPhase = Mockito.mock(PlanPhase.class); Mockito.when(planPhase.getRecurringPrice()).thenReturn(price); final Plan plan = Mockito.mock(Plan.class); Mockito.when(plan.getProduct()).thenReturn(product); Mockito.when(plan.getName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(plan.getBillingPeriod()).thenReturn(BillingPeriod.QUARTERLY); Mockito.when(plan.getFinalPhase()).thenReturn(planPhase); final PriceList priceList = Mockito.mock(PriceList.class); Mockito.when(priceList.getName()).thenReturn(UUID.randomUUID().toString()); final Listing listing = Mockito.mock(Listing.class); Mockito.when(listing.getPlan()).thenReturn(plan); Mockito.when(listing.getPriceList()).thenReturn(priceList); final PlanDetailJson planDetailJason = new PlanDetailJson(listing); Assert.assertEquals(planDetailJason.getProductName(), plan.getProduct().getName()); Assert.assertEquals(planDetailJason.getPlanName(), plan.getName()); Assert.assertEquals(planDetailJason.getBillingPeriod(), plan.getBillingPeriod()); Assert.assertEquals(planDetailJason.getPriceListName(), priceList.getName()); Assert.assertEquals(planDetailJason.getFinalPhasePrice().size(), 0); } }
final Plan newSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt3); Assert.assertEquals(newSubPlan1.getAllPhases()[1].getRecurringPrice().getPrice(Currency.USD), new BigDecimal("1.0")); Assert.assertEquals(newSubPlan2.getAllPhases()[1].getRecurringPrice().getPrice(Currency.USD), new BigDecimal("2.0")); Assert.assertEquals(newSubPlan214.getAllPhases()[1].getRecurringPrice().getPrice(Currency.USD), new BigDecimal("2.0")); Assert.assertEquals(newSubPlan3.getAllPhases()[1].getRecurringPrice().getPrice(Currency.USD), new BigDecimal("3.0")); final Plan exSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt1); Assert.assertEquals(exSubPlan2.getAllPhases()[1].getRecurringPrice().getPrice(Currency.USD), new BigDecimal("1.0")); Assert.assertEquals(exSubPlan214.getAllPhases()[1].getRecurringPrice().getPrice(Currency.USD), new BigDecimal("2.0")); Assert.assertEquals(exSubPlan3.getAllPhases()[1].getRecurringPrice().getPrice(Currency.USD), new BigDecimal("2.0"));
@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 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); }
@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()); }
if (thePhase.getRecurringPrice() != null) { tmpPrice = thePhase.getRecurringPrice().getPrice(USD); } catch (CatalogApiException e) { tmpPrice = new BigDecimal(0);
if (currentPhase.getRecurringPrice() != null) { tmpPrice = currentPhase.getRecurringPrice().getPrice(USD); } catch (CatalogApiException e) { tmpPrice = new BigDecimal(0);
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(); }