Search in sources :

Example 16 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class StandaloneCatalogMapper method toFilteredDefaultProduct.

private Collection<Product> toFilteredDefaultProduct(final Collection<Product> input) {
    if (!input.iterator().hasNext()) {
        return Collections.emptyList();
    }
    final Iterable<String> inputProductNames = Iterables.transform(input, new Function<Product, String>() {

        @Override
        public String apply(final Product input) {
            return input.getName();
        }
    });
    final Collection<Product> filteredAndOrdered = new ArrayList<Product>(input.size());
    for (final String cur : inputProductNames) {
        final Product found = tmpDefaultProducts.get(cur);
        if (found == null)
            throw new IllegalStateException("Failed to find product " + cur);
        filteredAndOrdered.add(found);
    }
    return filteredAndOrdered;
}
Also used : ArrayList(java.util.ArrayList) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) Product(org.killbill.billing.catalog.api.Product)

Example 17 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class StandaloneCatalog method initialize.

@Override
public void initialize(final StandaloneCatalog catalog, final URI sourceURI) {
    super.initialize(catalog, sourceURI);
    CatalogSafetyInitializer.initializeNonRequiredNullFieldsWithDefaultValue(this);
    catalogURI = sourceURI;
    planRules.initialize(catalog, sourceURI);
    priceLists.initialize(catalog, sourceURI);
    for (final DefaultUnit cur : units) {
        cur.initialize(catalog, sourceURI);
    }
    for (final Product p : products.getEntries()) {
        ((DefaultProduct) p).initialize(catalog, sourceURI);
    }
    for (final Plan p : plans.getEntries()) {
        ((DefaultPlan) p).initialize(catalog, sourceURI);
    }
}
Also used : Product(org.killbill.billing.catalog.api.Product) Plan(org.killbill.billing.catalog.api.Plan)

Example 18 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class StandaloneCatalog method canCreatePlan.

@Override
public boolean canCreatePlan(final PlanSpecifier specifier) throws CatalogApiException {
    final Product product = findCurrentProduct(specifier.getProductName());
    final Plan plan = createOrFindCurrentPlan(specifier, null);
    final DefaultPriceList priceList = findCurrentPriceList(specifier.getPriceListName());
    return (product != null) && (plan != null) && (priceList != null);
}
Also used : Product(org.killbill.billing.catalog.api.Product) Plan(org.killbill.billing.catalog.api.Plan)

Example 19 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class DefaultCase method satisfiesCase.

protected boolean satisfiesCase(final PlanSpecifier planPhase, final StaticCatalog c) throws CatalogApiException {
    final Product product;
    final BillingPeriod billingPeriod;
    final ProductCategory productCategory;
    final PriceList priceList;
    if (planPhase.getPlanName() != null) {
        final Plan plan = c.findCurrentPlan(planPhase.getPlanName());
        product = plan.getProduct();
        billingPeriod = plan.getRecurringBillingPeriod();
        productCategory = plan.getProduct().getCategory();
        priceList = c.findCurrentPricelist(plan.getPriceListName());
    } else {
        product = c.findCurrentProduct(planPhase.getProductName());
        billingPeriod = planPhase.getBillingPeriod();
        productCategory = product.getCategory();
        priceList = getPriceList() != null ? c.findCurrentPricelist(planPhase.getPriceListName()) : null;
    }
    return (getProduct() == null || getProduct().equals(product)) && (getProductCategory() == null || getProductCategory().equals(productCategory)) && (getBillingPeriod() == null || getBillingPeriod().equals(billingPeriod)) && (getPriceList() == null || getPriceList().equals(priceList));
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) ProductCategory(org.killbill.billing.catalog.api.ProductCategory) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) Product(org.killbill.billing.catalog.api.Product) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList)

Example 20 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class BlockingStateOrdering method toSubscriptionEvent.

private SubscriptionEvent toSubscriptionEvent(@Nullable final SubscriptionEvent prev, @Nullable final SubscriptionEvent next, final UUID entitlementId, final BlockingState in, final SubscriptionEventType eventType, final InternalTenantContext internalTenantContext) {
    final Product prevProduct;
    final Plan prevPlan;
    final PlanPhase prevPlanPhase;
    final PriceList prevPriceList;
    final BillingPeriod prevBillingPeriod;
    // Enforce prev = null for start events
    if (prev == null || SubscriptionEventType.START_ENTITLEMENT.equals(eventType) || SubscriptionEventType.START_BILLING.equals(eventType)) {
        prevProduct = null;
        prevPlan = null;
        prevPlanPhase = null;
        prevPriceList = null;
        prevBillingPeriod = null;
    } else {
        // We look for the next for the 'prev' meaning we we are headed to, but if this is null -- for example on cancellation we get the prev which gives the correct state.
        prevProduct = (prev.getNextProduct() != null ? prev.getNextProduct() : prev.getPrevProduct());
        prevPlan = (prev.getNextPlan() != null ? prev.getNextPlan() : prev.getPrevPlan());
        prevPlanPhase = (prev.getNextPhase() != null ? prev.getNextPhase() : prev.getPrevPhase());
        prevPriceList = (prev.getNextPriceList() != null ? prev.getNextPriceList() : prev.getPrevPriceList());
        prevBillingPeriod = (prev.getNextBillingPeriod() != null ? prev.getNextBillingPeriod() : prev.getPrevBillingPeriod());
    }
    final Product nextProduct;
    final Plan nextPlan;
    final PlanPhase nextPlanPhase;
    final PriceList nextPriceList;
    final BillingPeriod nextBillingPeriod;
    if (SubscriptionEventType.PAUSE_ENTITLEMENT.equals(eventType) || SubscriptionEventType.PAUSE_BILLING.equals(eventType) || SubscriptionEventType.RESUME_ENTITLEMENT.equals(eventType) || SubscriptionEventType.RESUME_BILLING.equals(eventType) || (SubscriptionEventType.SERVICE_STATE_CHANGE.equals(eventType) && (prev == null || (!SubscriptionEventType.STOP_ENTITLEMENT.equals(prev.getSubscriptionEventType()) && !SubscriptionEventType.STOP_BILLING.equals(prev.getSubscriptionEventType()))))) {
        // Enforce next = prev for pause/resume events as well as service changes
        nextProduct = prevProduct;
        nextPlan = prevPlan;
        nextPlanPhase = prevPlanPhase;
        nextPriceList = prevPriceList;
        nextBillingPeriod = prevBillingPeriod;
    } else if (next == null) {
        // Enforce next = null for stop events
        if (prev == null || SubscriptionEventType.STOP_ENTITLEMENT.equals(eventType) || SubscriptionEventType.STOP_BILLING.equals(eventType)) {
            nextProduct = null;
            nextPlan = null;
            nextPlanPhase = null;
            nextPriceList = null;
            nextBillingPeriod = null;
        } else {
            nextProduct = prev.getNextProduct();
            nextPlan = prev.getNextPlan();
            nextPlanPhase = prev.getNextPhase();
            nextPriceList = prev.getNextPriceList();
            nextBillingPeriod = prev.getNextBillingPeriod();
        }
    } else if (prev != null && (SubscriptionEventType.START_ENTITLEMENT.equals(eventType) || SubscriptionEventType.START_BILLING.equals(eventType))) {
        // For start events, next is actually the prev (e.g. the trial, not the phase)
        nextProduct = prev.getNextProduct();
        nextPlan = prev.getNextPlan();
        nextPlanPhase = prev.getNextPhase();
        nextPriceList = prev.getNextPriceList();
        nextBillingPeriod = prev.getNextBillingPeriod();
    } else {
        nextProduct = next.getNextProduct();
        nextPlan = next.getNextPlan();
        nextPlanPhase = next.getNextPhase();
        nextPriceList = next.getNextPriceList();
        nextBillingPeriod = next.getNextBillingPeriod();
    }
    // See https://github.com/killbill/killbill/issues/135
    final String serviceName = getRealServiceNameForEntitlementOrExternalServiceName(in.getService(), eventType);
    return new DefaultSubscriptionEvent(in.getId(), entitlementId, in.getEffectiveDate(), eventType, in.isBlockEntitlement(), in.isBlockBilling(), serviceName, in.getStateName(), prevProduct, prevPlan, prevPlanPhase, prevPriceList, prevBillingPeriod, nextProduct, nextPlan, nextPlanPhase, nextPriceList, nextBillingPeriod, in.getCreatedDate(), internalTenantContext);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Product(org.killbill.billing.catalog.api.Product) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList)

Aggregations

Product (org.killbill.billing.catalog.api.Product)29 Plan (org.killbill.billing.catalog.api.Plan)15 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)8 PriceList (org.killbill.billing.catalog.api.PriceList)7 Test (org.testng.annotations.Test)6 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)5 DateTime (org.joda.time.DateTime)4 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)4 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)4 ArrayList (java.util.ArrayList)3 ProductCategory (org.killbill.billing.catalog.api.ProductCategory)3 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)3 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)2 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)2 StandaloneCatalogWithPriceOverride (org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)2 VersionedCatalog (org.killbill.billing.catalog.VersionedCatalog)2 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)2 SimplePlanDescriptor (org.killbill.billing.catalog.api.SimplePlanDescriptor)2 DefaultSimplePlanDescriptor (org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor)2