Search in sources :

Example 26 with Product

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

the class AddonUtils method isAddonAvailable.

private boolean isAddonAvailable(final Product baseProduct, final Plan targetAddOnPlan) {
    final Product targetAddonProduct = targetAddOnPlan.getProduct();
    final Collection<Product> availableAddOns = baseProduct.getAvailable();
    for (final Product curAv : availableAddOns) {
        if (curAv.getName().equals(targetAddonProduct.getName())) {
            return true;
        }
    }
    return false;
}
Also used : Product(org.killbill.billing.catalog.api.Product)

Example 27 with Product

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

the class DefaultSubscriptionBaseApiService method getEventsOnCancelPlan.

@Override
public List<SubscriptionBaseEvent> getEventsOnCancelPlan(final DefaultSubscriptionBase subscription, final DateTime effectiveDate, final DateTime processedDate, final boolean addCancellationAddOnForEventsIfRequired, final InternalTenantContext internalTenantContext) throws CatalogApiException {
    final List<SubscriptionBaseEvent> cancelEvents = new ArrayList<SubscriptionBaseEvent>();
    final SubscriptionBaseEvent cancelEvent = new ApiEventCancel(new ApiEventBuilder().setSubscriptionId(subscription.getId()).setEffectiveDate(effectiveDate).setFromDisk(true));
    cancelEvents.add(cancelEvent);
    if (subscription.getCategory() == ProductCategory.BASE && addCancellationAddOnForEventsIfRequired) {
        final Product currentBaseProduct = cancelEvent.getEffectiveDate().compareTo(clock.getUTCNow()) <= 0 ? null : subscription.getCurrentPlan().getProduct();
        addCancellationAddOnForEventsIfRequired(cancelEvents, currentBaseProduct, subscription.getBundleId(), effectiveDate, internalTenantContext);
    }
    return cancelEvents;
}
Also used : ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) ArrayList(java.util.ArrayList) Product(org.killbill.billing.catalog.api.Product) ApiEventCancel(org.killbill.billing.subscription.events.user.ApiEventCancel) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 28 with Product

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

the class DefaultSubscriptionBaseApiService method getEventsOnChangePlan.

private List<SubscriptionBaseEvent> getEventsOnChangePlan(final DefaultSubscriptionBase subscription, final Plan newPlan, final String newPriceList, final DateTime effectiveDate, final boolean addCancellationAddOnForEventsIfRequired, final Collection<DefaultSubscriptionBase> addOnSubscriptionsToBeCancelled, final Collection<SubscriptionBaseEvent> addOnCancelEvents, final PhaseType initialPhaseType, final InternalTenantContext internalTenantContext) throws CatalogApiException, SubscriptionBaseApiException {
    final TimedPhase currentTimedPhase = planAligner.getCurrentTimedPhaseOnChange(subscription, newPlan, effectiveDate, initialPhaseType, internalTenantContext);
    final SubscriptionBaseEvent changeEvent = new ApiEventChange(new ApiEventBuilder().setSubscriptionId(subscription.getId()).setEventPlan(newPlan.getName()).setEventPlanPhase(currentTimedPhase.getPhase().getName()).setEventPriceList(newPriceList).setEffectiveDate(effectiveDate).setFromDisk(true));
    final TimedPhase nextTimedPhase = planAligner.getNextTimedPhaseOnChange(subscription, newPlan, effectiveDate, initialPhaseType, internalTenantContext);
    final PhaseEvent nextPhaseEvent = (nextTimedPhase != null) ? PhaseEventData.createNextPhaseEvent(subscription.getId(), nextTimedPhase.getPhase().getName(), nextTimedPhase.getStartPhase()) : null;
    final List<SubscriptionBaseEvent> changeEvents = new ArrayList<SubscriptionBaseEvent>();
    // Only add the PHASE if it does not coincide with the CHANGE, if not this is 'just' a CHANGE.
    changeEvents.add(changeEvent);
    if (nextPhaseEvent != null && !nextPhaseEvent.getEffectiveDate().equals(changeEvent.getEffectiveDate())) {
        changeEvents.add(nextPhaseEvent);
    }
    if (subscription.getCategory() == ProductCategory.BASE && addCancellationAddOnForEventsIfRequired) {
        final Product currentBaseProduct = changeEvent.getEffectiveDate().compareTo(clock.getUTCNow()) <= 0 ? newPlan.getProduct() : subscription.getCurrentPlan().getProduct();
        addOnSubscriptionsToBeCancelled.addAll(addCancellationAddOnForEventsIfRequired(addOnCancelEvents, currentBaseProduct, subscription.getBundleId(), effectiveDate, internalTenantContext));
    }
    return changeEvents;
}
Also used : PhaseEvent(org.killbill.billing.subscription.events.phase.PhaseEvent) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) TimedPhase(org.killbill.billing.subscription.alignment.TimedPhase) ArrayList(java.util.ArrayList) Product(org.killbill.billing.catalog.api.Product) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) ApiEventChange(org.killbill.billing.subscription.events.user.ApiEventChange)

Example 29 with Product

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

the class DefaultSubscriptionBaseApiService method handleBasePlanEvent.

@Override
public int handleBasePlanEvent(final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent event, final CallContext context) throws CatalogApiException {
    final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context);
    if (((ApiEvent) event).getApiEventType() == ApiEventType.CANCEL || ((ApiEvent) event).getApiEventType() == ApiEventType.CHANGE) {
        final Product baseProduct = (subscription.getState() == EntitlementState.CANCELLED) ? null : subscription.getCurrentPlan().getProduct();
        final List<SubscriptionBaseEvent> cancelEvents = new LinkedList<SubscriptionBaseEvent>();
        final List<DefaultSubscriptionBase> subscriptionsToBeCancelled = computeAddOnsToCancel(cancelEvents, baseProduct, subscription.getBundleId(), event.getEffectiveDate(), internalCallContext);
        dao.cancelSubscriptionsOnBasePlanEvent(subscription, event, subscriptionsToBeCancelled, cancelEvents, internalCallContext);
        return subscriptionsToBeCancelled.size();
    } else {
        dao.notifyOnBasePlanEvent(subscription, event, internalCallContext);
        return 0;
    }
}
Also used : ApiEvent(org.killbill.billing.subscription.events.user.ApiEvent) Product(org.killbill.billing.catalog.api.Product) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) LinkedList(java.util.LinkedList) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

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