@Override public BigDecimal getPrice(final Currency currency) throws CatalogApiException { for (final Price p : prices) { if (p.getCurrency() == currency) { return p.getValue(); } } throw new CatalogApiException(ErrorCode.CAT_NO_PRICE_FOR_CURRENCY, currency); }
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; }
public IllegalPlanChange(final Throwable cause, final PlanPhaseSpecifier from, final PlanSpecifier to) { super(cause, ErrorCode.CAT_ILLEGAL_CHANGE_REQUEST, from.getProductName(), from.getBillingPeriod(), from.getPriceListName(), to.getProductName(), to.getBillingPeriod(), to.getPriceListName()); }
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()); }
/** * For unit tests only. * <p/> * You can't really use this constructor in real life because the start date is likely not the one you want (you likely * want the phase start date). * * @param subscription Subscription to use as a model * @param currency ACCOUNT currency * @param catalog Catalog to use */ BusinessSubscription(final Subscription subscription, final Currency currency, final Catalog catalog) { this(subscription.getCurrentPriceList() == null ? null : subscription.getCurrentPriceList().getName(), subscription.getCurrentPlan().getName(), subscription.getCurrentPhase().getName(), currency, subscription.getStartDate(), subscription.getState(), catalog); }
public PlanSpecifier(final PlanPhaseSpecifier planPhase) { super(); this.productName = planPhase.getProductName(); this.productCategory = planPhase.getProductCategory(); this.billingPeriod = planPhase.getBillingPeriod(); this.priceListName = planPhase.getPriceListName(); }
@Override public boolean apply(final SubscriptionBase input) { return ProductCategory.BASE.equals(input.getLastActiveProduct().getCategory()); } }).orNull();
public PriceJson(final Price price) throws CurrencyValueNull { this(price.getCurrency().toString(), price.getValue()); }
public static String planName(final String phaseName) throws CatalogApiException { for (final PhaseType type : PhaseType.values()) { if (phaseName.endsWith(type.toString().toLowerCase())) { return phaseName.substring(0, phaseName.length() - type.toString().length() - 1); } } throw new CatalogApiException(ErrorCode.CAT_BAD_PHASE_NAME, phaseName); }
@Override public boolean compliesWithLimits(String unit, double value) { Limit l = findLimit(unit); if (l == null) { return getPlan().getProduct().compliesWithLimits(unit, value); } return l.compliesWith(value); }
@Override public String apply(final Product product) { return product.getName(); } });
@Override public String getName() { if (plan == null) { return null; } else { return plan.getName() + "-" + cohort; } }
@Override public boolean canCreatePlan(final PlanSpecifier specifier) throws CatalogApiException { final Product product = findCurrentProduct(specifier.getProductName()); final Plan plan = findCurrentPlan(specifier.getProductName(), specifier.getBillingPeriod(), specifier.getPriceListName()); final DefaultPriceList priceList = findCurrentPriceList(specifier.getPriceListName()); return (!product.isRetired()) && (!plan.isRetired()) && (!priceList.isRetired()); }
@Override public Catalog getCatalog(final String catalogName, final TenantContext context) { // STEPH TODO this is hack until we decides what do do exactly: // Probably we want one catalog for tenant but but TBD return catalogService.getFullCatalog(); } }
@Override public PlanPhaseSpecifier getPlanPhaseSpecifier() { return new PlanPhaseSpecifier("BicycleTrialEvergreen1USD", ProductCategory.BASE, BillingPeriod.NO_BILLING_PERIOD, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.FIXEDTERM); }
@Override public Currency getCurrency() { if (currency == null) { return null; } else { return Currency.valueOf(currency); } }
@Override public BigDecimal getValue() throws CurrencyValueNull { if (value == null) { throw new CurrencyValueNull(currency); } return value; }
public IllegalPlanChange(final PlanPhaseSpecifier from, final PlanSpecifier to) { super(ErrorCode.CAT_ILLEGAL_CHANGE_REQUEST, from.getProductName(), from.getBillingPeriod(), from.getPriceListName(), to.getProductName(), to.getBillingPeriod(), to.getPriceListName()); }