Search in sources :

Example 61 with CatalogApiException

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

the class AddonUtils method isAddonAvailableFromPlanName.

public boolean isAddonAvailableFromPlanName(final String basePlanName, final Plan targetAddOnPlan, final DateTime requestedDate, final InternalTenantContext context) {
    try {
        final Plan plan = catalogService.getFullCatalog(true, true, context).findPlan(basePlanName, requestedDate);
        final Product product = plan.getProduct();
        return isAddonAvailable(product, targetAddOnPlan);
    } catch (CatalogApiException e) {
        throw new SubscriptionBaseError(e);
    }
}
Also used : SubscriptionBaseError(org.killbill.billing.subscription.exceptions.SubscriptionBaseError) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) Product(org.killbill.billing.catalog.api.Product) Plan(org.killbill.billing.catalog.api.Plan)

Example 62 with CatalogApiException

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

the class DefaultSubscriptionBaseApiService method changePlanWithRequestedDate.

@Override
public DateTime changePlanWithRequestedDate(final DefaultSubscriptionBase subscription, final PlanSpecifier spec, final List<PlanPhasePriceOverride> overrides, final DateTime requestedDateWithMs, final CallContext context) throws SubscriptionBaseApiException {
    final DateTime effectiveDate = dryRunChangePlan(subscription, spec, requestedDateWithMs, null, context);
    validateEffectiveDate(subscription, effectiveDate);
    validateEntitlementState(subscription);
    try {
        doChangePlan(subscription, spec, overrides, effectiveDate, context);
    } catch (final CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
    return effectiveDate;
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) DateTime(org.joda.time.DateTime) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 63 with CatalogApiException

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

the class DefaultSubscriptionBaseApiService method doCancelPlan.

private boolean doCancelPlan(final Map<DefaultSubscriptionBase, DateTime> subscriptions, final DateTime now, final InternalCallContext internalCallContext) throws SubscriptionBaseApiException {
    final List<DefaultSubscriptionBase> subscriptionsToBeCancelled = new LinkedList<DefaultSubscriptionBase>();
    final List<SubscriptionBaseEvent> cancelEvents = new LinkedList<SubscriptionBaseEvent>();
    try {
        for (final DefaultSubscriptionBase subscription : subscriptions.keySet()) {
            final DateTime effectiveDate = subscriptions.get(subscription);
            validateEffectiveDate(subscription, effectiveDate);
            subscriptionsToBeCancelled.add(subscription);
            cancelEvents.addAll(getEventsOnCancelPlan(subscription, effectiveDate, now, false, internalCallContext));
            if (subscription.getCategory() == ProductCategory.BASE) {
                subscriptionsToBeCancelled.addAll(computeAddOnsToCancel(cancelEvents, null, subscription.getBundleId(), effectiveDate, internalCallContext));
            }
        }
        dao.cancelSubscriptions(subscriptionsToBeCancelled, cancelEvents, internalCallContext);
        boolean allSubscriptionsCancelled = true;
        for (final DefaultSubscriptionBase subscription : subscriptions.keySet()) {
            final Catalog fullCatalog = catalogService.getFullCatalog(true, true, internalCallContext);
            subscription.rebuildTransitions(dao.getEventsForSubscription(subscription.getId(), internalCallContext), fullCatalog);
            allSubscriptionsCancelled = allSubscriptionsCancelled && (subscription.getState() == EntitlementState.CANCELLED);
        }
        return allSubscriptionsCancelled;
    } catch (final CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) LinkedList(java.util.LinkedList) DateTime(org.joda.time.DateTime) Catalog(org.killbill.billing.catalog.api.Catalog)

Example 64 with CatalogApiException

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

the class DefaultSubscriptionBaseApiService method createEvents.

private void createEvents(final Iterable<SubscriptionSpecifier> subscriptions, final CallContext context, final Map<UUID, List<SubscriptionBaseEvent>> eventsMap, final Collection<SubscriptionBase> subscriptionBaseList) throws SubscriptionBaseApiException {
    for (final SubscriptionSpecifier subscription : subscriptions) {
        try {
            final DefaultSubscriptionBase subscriptionBase = new DefaultSubscriptionBase(subscription.getBuilder(), this, clock);
            final InternalCallContext internalCallContext = createCallContextFromBundleId(subscriptionBase.getBundleId(), context);
            final List<SubscriptionBaseEvent> events = getEventsOnCreation(subscriptionBase.getBundleId(), subscriptionBase.getId(), subscriptionBase.getAlignStartDate(), subscriptionBase.getBundleStartDate(), subscription.getPlan(), subscription.getInitialPhase(), subscription.getRealPriceList(), subscription.getEffectiveDate(), subscription.getProcessedDate(), internalCallContext);
            eventsMap.put(subscriptionBase.getId(), events);
            subscriptionBaseList.add(subscriptionBase);
        } catch (final CatalogApiException e) {
            throw new SubscriptionBaseApiException(e);
        }
    }
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent)

Example 65 with CatalogApiException

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

the class DefaultSubscriptionBaseApiService method changePlanWithPolicy.

@Override
public DateTime changePlanWithPolicy(final DefaultSubscriptionBase subscription, final PlanSpecifier spec, final List<PlanPhasePriceOverride> overrides, final BillingActionPolicy policy, final CallContext context) throws SubscriptionBaseApiException {
    validateEntitlementState(subscription);
    final DateTime effectiveDate = dryRunChangePlan(subscription, spec, null, policy, context);
    try {
        doChangePlan(subscription, spec, overrides, effectiveDate, context);
    } catch (final CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
    return effectiveDate;
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) DateTime(org.joda.time.DateTime) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Aggregations

CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)106 DateTime (org.joda.time.DateTime)36 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)28 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)22 ArrayList (java.util.ArrayList)21 SubscriptionCatalog (org.killbill.billing.subscription.catalog.SubscriptionCatalog)20 Plan (org.killbill.billing.catalog.api.Plan)19 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)19 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)17 UUID (java.util.UUID)14 LinkedList (java.util.LinkedList)13 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)13 StaticCatalog (org.killbill.billing.catalog.api.StaticCatalog)13 HashMap (java.util.HashMap)10 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)9 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)9 Test (org.testng.annotations.Test)9