Search in sources :

Example 91 with CatalogApiException

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

the class DefaultSubscriptionBaseApiService method changePlan.

@Override
public DateTime changePlan(final DefaultSubscriptionBase subscription, final EntitlementSpecifier spec, final CallContext context) throws SubscriptionBaseApiException {
    validateSubscriptionStateForChangePlan(subscription, null);
    final PlanChangeResult planChangeResult = getPlanChangeResult(subscription, spec.getPlanPhaseSpecifier(), context.getCreatedDate(), context);
    final DateTime effectiveDate = dryRunChangePlan(subscription, spec, null, planChangeResult.getPolicy(), context);
    validateEffectiveDate(subscription, effectiveDate);
    logger.debug("changePlan: effectiveDate='{}'", effectiveDate);
    try {
        doChangePlan(subscription, spec, effectiveDate, context);
    } catch (final CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
    return effectiveDate;
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) DateTime(org.joda.time.DateTime)

Example 92 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, final SubscriptionCatalog catalog) 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.getId(), subscriptionBase.getAlignStartDate(), subscriptionBase.getBundleStartDate(), subscription.getPlan(), subscription.getInitialPhase(), subscription.getRealPriceList(), subscription.getEffectiveDate(), subscription.getBuilder().getSubscriptionBCD(), catalog, 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 93 with CatalogApiException

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

the class DefaultSubscriptionBaseApiService method cancelWithRequestedDate.

@Override
public boolean cancelWithRequestedDate(final DefaultSubscriptionBase subscription, final DateTime requestedDateWithMs, final CallContext context) throws SubscriptionBaseApiException {
    final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context);
    try {
        final SubscriptionCatalog catalog = subscriptionCatalogApi.getFullCatalog(internalCallContext);
        final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : context.getCreatedDate();
        return doCancelPlan(ImmutableMap.<DefaultSubscriptionBase, DateTime>of(subscription, effectiveDate), catalog, internalCallContext);
    } catch (final CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) SubscriptionCatalog(org.killbill.billing.subscription.catalog.SubscriptionCatalog) DateTime(org.joda.time.DateTime)

Example 94 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 EntitlementSpecifier spec, final BillingActionPolicy policy, final CallContext context) throws SubscriptionBaseApiException {
    final DateTime effectiveDate = dryRunChangePlan(subscription, spec, null, policy, context);
    validateSubscriptionStateForChangePlan(subscription, effectiveDate);
    logger.debug("changePlan: policy='{}', effectiveDate='{}'", policy, effectiveDate);
    try {
        doChangePlan(subscription, spec, 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)

Example 95 with CatalogApiException

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

the class DefaultSubscriptionInternalApi method createBaseSubscriptionsWithAddOns.

@Override
public List<SubscriptionBaseWithAddOns> createBaseSubscriptionsWithAddOns(final VersionedCatalog publicCatalog, final Iterable<SubscriptionBaseWithAddOnsSpecifier> subscriptionWithAddOnsSpecifiers, final boolean renameCancelledBundleIfExist, final InternalCallContext context) throws SubscriptionBaseApiException {
    try {
        final SubscriptionCatalog catalog = DefaultSubscriptionCatalogApi.wrapCatalog(publicCatalog, clock);
        final CallContext callContext = internalCallContextFactory.createCallContext(context);
        return super.createBaseSubscriptionsWithAddOns(subscriptionWithAddOnsSpecifiers, renameCancelledBundleIfExist, catalog, addonUtils, accountIdCacheController, bundleIdCacheController, callContext, context);
    } catch (final CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) SubscriptionCatalog(org.killbill.billing.subscription.catalog.SubscriptionCatalog) PlanPhasePriceOverridesWithCallContext(org.killbill.billing.catalog.api.PlanPhasePriceOverridesWithCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

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