Search in sources :

Example 6 with PlanChangeResult

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

the class DefaultSubscriptionBaseApiService method dryRunChangePlan.

@Override
public DateTime dryRunChangePlan(final DefaultSubscriptionBase subscription, final PlanSpecifier spec, @Nullable final DateTime requestedDateWithMs, @Nullable final BillingActionPolicy requestedPolicy, final TenantContext context) throws SubscriptionBaseApiException {
    final DateTime now = clock.getUTCNow();
    BillingActionPolicy policyMaybeNull = requestedPolicy;
    if (requestedDateWithMs == null && requestedPolicy == null) {
        final PlanChangeResult planChangeResult = getPlanChangeResult(subscription, spec, now, context);
        policyMaybeNull = planChangeResult.getPolicy();
    }
    if (policyMaybeNull != null) {
        return subscription.getPlanChangeEffectiveDate(policyMaybeNull, null, null, -1, null);
    } else if (requestedDateWithMs != null) {
        return DefaultClock.truncateMs(requestedDateWithMs);
    } else {
        return now;
    }
}
Also used : BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) DateTime(org.joda.time.DateTime) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 7 with PlanChangeResult

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

the class DefaultSubscriptionBaseApiService method changePlan.

@Override
public DateTime changePlan(final DefaultSubscriptionBase subscription, final PlanSpecifier spec, final List<PlanPhasePriceOverride> overrides, final CallContext context) throws SubscriptionBaseApiException {
    final DateTime now = clock.getUTCNow();
    validateEntitlementState(subscription);
    final PlanChangeResult planChangeResult = getPlanChangeResult(subscription, spec, now, context);
    final DateTime effectiveDate = dryRunChangePlan(subscription, spec, null, planChangeResult.getPolicy(), context);
    validateEffectiveDate(subscription, effectiveDate);
    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) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) DateTime(org.joda.time.DateTime) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Aggregations

PlanChangeResult (org.killbill.billing.catalog.api.PlanChangeResult)7 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)5 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)4 DateTime (org.joda.time.DateTime)3 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)3 BillingActionPolicy (org.killbill.billing.catalog.api.BillingActionPolicy)3 IllegalPlanChange (org.killbill.billing.catalog.api.IllegalPlanChange)3 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)3 PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)3 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)2 Plan (org.killbill.billing.catalog.api.Plan)2 Test (org.testng.annotations.Test)2 UUID (java.util.UUID)1 Catalog (org.killbill.billing.catalog.api.Catalog)1 PlanAlignmentChange (org.killbill.billing.catalog.api.PlanAlignmentChange)1 PlanPhasePriceOverridesWithCallContext (org.killbill.billing.catalog.api.PlanPhasePriceOverridesWithCallContext)1 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)1 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)1 SubscriptionBuilder (org.killbill.billing.subscription.api.user.SubscriptionBuilder)1