Search in sources :

Example 1 with PlanAlignmentChange

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

the class DefaultPlanRules method planChange.

public PlanChangeResult planChange(final PlanPhaseSpecifier from, final PlanSpecifier to, final StaticCatalog catalog) throws CatalogApiException {
    final DefaultPriceList toPriceList = to.getPriceListName() != null ? (DefaultPriceList) catalog.findCurrentPricelist(to.getPriceListName()) : findPriceList(from, catalog);
    // If we use old scheme {product, billingPeriod, pricelist}, ensure pricelist is correct
    // (Pricelist may be null because if it is unspecified this is the principal use-case)
    final PlanSpecifier toWithPriceList = to.getPlanName() == null ? new PlanSpecifier(to.getProductName(), to.getBillingPeriod(), toPriceList.getName()) : to;
    final BillingActionPolicy policy = getPlanChangePolicy(from, toWithPriceList, catalog);
    if (policy == BillingActionPolicy.ILLEGAL) {
        throw new IllegalPlanChange(from, toWithPriceList);
    }
    final PlanAlignmentChange alignment = getPlanChangeAlignment(from, toWithPriceList, catalog);
    return new PlanChangeResult(toPriceList, policy, alignment);
}
Also used : BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) IllegalPlanChange(org.killbill.billing.catalog.api.IllegalPlanChange) PlanAlignmentChange(org.killbill.billing.catalog.api.PlanAlignmentChange) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Example 2 with PlanAlignmentChange

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

the class DefaultPlanRules method getPlanChangeResult.

@Override
public PlanChangeResult getPlanChangeResult(final PlanPhaseSpecifier from, final PlanSpecifier to) throws CatalogApiException {
    final DefaultPriceList toPriceList = to.getPriceListName() != null ? (DefaultPriceList) root.findPriceList(to.getPriceListName()) : findPriceList(from);
    // If we use old scheme {product, billingPeriod, pricelist}, ensure pricelist is correct
    // (Pricelist may be null because if it is unspecified this is the principal use-case)
    final PlanSpecifier toWithPriceList = to.getPlanName() == null ? new PlanSpecifier(to.getProductName(), to.getBillingPeriod(), toPriceList.getName()) : to;
    final BillingActionPolicy policy = getPlanChangePolicy(from, toWithPriceList);
    if (policy == BillingActionPolicy.ILLEGAL) {
        throw new IllegalPlanChange(from, toWithPriceList);
    }
    final PlanAlignmentChange alignment = getPlanChangeAlignment(from, toWithPriceList);
    return new PlanChangeResult(toPriceList, policy, alignment);
}
Also used : BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) IllegalPlanChange(org.killbill.billing.catalog.api.IllegalPlanChange) PlanAlignmentChange(org.killbill.billing.catalog.api.PlanAlignmentChange) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Example 3 with PlanAlignmentChange

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

the class PlanAligner method getTimedPhaseOnChange.

private TimedPhase getTimedPhaseOnChange(final DateTime subscriptionStartDate, final DateTime bundleStartDate, final PlanPhase currentPhase, final Plan currentPlan, final Plan nextPlan, final DateTime effectiveDate, final DateTime lastOrCurrentChangeEffectiveDate, final PhaseType originalInitialPhase, @Nullable final PhaseType newPlanInitialPhaseType, final WhichPhase which, final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException {
    final Catalog catalog = catalogService.getFullCatalog(true, true, context);
    final PlanPhaseSpecifier fromPlanPhaseSpecifier = new PlanPhaseSpecifier(currentPlan.getName(), currentPhase.getPhaseType());
    final PlanSpecifier toPlanSpecifier = new PlanSpecifier(nextPlan.getName());
    final PhaseType initialPhase;
    final DateTime planStartDate;
    final PlanAlignmentChange alignment = catalog.planChangeAlignment(fromPlanPhaseSpecifier, toPlanSpecifier, effectiveDate);
    switch(alignment) {
        case START_OF_SUBSCRIPTION:
            planStartDate = subscriptionStartDate;
            initialPhase = newPlanInitialPhaseType != null ? newPlanInitialPhaseType : (isPlanContainPhaseType(nextPlan, originalInitialPhase) ? originalInitialPhase : null);
            break;
        case START_OF_BUNDLE:
            planStartDate = bundleStartDate;
            initialPhase = newPlanInitialPhaseType != null ? newPlanInitialPhaseType : (isPlanContainPhaseType(nextPlan, originalInitialPhase) ? originalInitialPhase : null);
            break;
        case CHANGE_OF_PLAN:
            planStartDate = lastOrCurrentChangeEffectiveDate;
            initialPhase = newPlanInitialPhaseType;
            break;
        case CHANGE_OF_PRICELIST:
            throw new SubscriptionBaseError(String.format("Not implemented yet %s", alignment));
        default:
            throw new SubscriptionBaseError(String.format("Unknown PlanAlignmentChange %s", alignment));
    }
    final List<TimedPhase> timedPhases = getPhaseAlignments(nextPlan, initialPhase, planStartDate);
    return getTimedPhase(timedPhases, effectiveDate, which);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) SubscriptionBaseError(org.killbill.billing.subscription.exceptions.SubscriptionBaseError) PlanAlignmentChange(org.killbill.billing.catalog.api.PlanAlignmentChange) PhaseType(org.killbill.billing.catalog.api.PhaseType) Catalog(org.killbill.billing.catalog.api.Catalog) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Example 4 with PlanAlignmentChange

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

the class PlanAligner method getTimedPhaseOnChange.

private TimedPhase getTimedPhaseOnChange(final DateTime subscriptionStartDate, final DateTime bundleStartDate, final PlanPhase currentPhase, final Plan currentPlan, final Plan nextPlan, final DateTime effectiveDate, final DateTime catalogEffectiveDate, final DateTime lastOrCurrentChangeEffectiveDate, final PhaseType originalInitialPhase, @Nullable final PhaseType newPlanInitialPhaseType, final WhichPhase which, final SubscriptionCatalog catalog, final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException {
    final PlanPhaseSpecifier fromPlanPhaseSpecifier = new PlanPhaseSpecifier(currentPlan.getName(), currentPhase.getPhaseType());
    final PlanSpecifier toPlanSpecifier = new PlanSpecifier(nextPlan.getName());
    final PhaseType initialPhase;
    final DateTime planStartDate;
    final PlanAlignmentChange alignment = catalog.getPlanChangeResult(fromPlanPhaseSpecifier, toPlanSpecifier, catalogEffectiveDate).getAlignment();
    switch(alignment) {
        case START_OF_SUBSCRIPTION:
            planStartDate = subscriptionStartDate;
            initialPhase = newPlanInitialPhaseType != null ? newPlanInitialPhaseType : (isPlanContainPhaseType(nextPlan, originalInitialPhase) ? originalInitialPhase : null);
            break;
        case START_OF_BUNDLE:
            planStartDate = bundleStartDate;
            initialPhase = newPlanInitialPhaseType != null ? newPlanInitialPhaseType : (isPlanContainPhaseType(nextPlan, originalInitialPhase) ? originalInitialPhase : null);
            break;
        case CHANGE_OF_PLAN:
            planStartDate = lastOrCurrentChangeEffectiveDate;
            initialPhase = newPlanInitialPhaseType;
            break;
        case CHANGE_OF_PRICELIST:
            throw new SubscriptionBaseError(String.format("Not implemented yet %s", alignment));
        default:
            throw new SubscriptionBaseError(String.format("Unknown PlanAlignmentChange %s", alignment));
    }
    final List<TimedPhase> timedPhases = getPhaseAlignments(nextPlan, initialPhase, planStartDate);
    return getTimedPhase(timedPhases, effectiveDate, which);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) SubscriptionBaseError(org.killbill.billing.subscription.exceptions.SubscriptionBaseError) PlanAlignmentChange(org.killbill.billing.catalog.api.PlanAlignmentChange) PhaseType(org.killbill.billing.catalog.api.PhaseType) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Aggregations

PlanAlignmentChange (org.killbill.billing.catalog.api.PlanAlignmentChange)4 PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)4 DateTime (org.joda.time.DateTime)2 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)2 BillingActionPolicy (org.killbill.billing.catalog.api.BillingActionPolicy)2 IllegalPlanChange (org.killbill.billing.catalog.api.IllegalPlanChange)2 PhaseType (org.killbill.billing.catalog.api.PhaseType)2 PlanChangeResult (org.killbill.billing.catalog.api.PlanChangeResult)2 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)2 SubscriptionBaseError (org.killbill.billing.subscription.exceptions.SubscriptionBaseError)2 Catalog (org.killbill.billing.catalog.api.Catalog)1