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;
}
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);
}
}
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);
}
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));
}
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);
}
Aggregations