@Override public boolean cancel(final DefaultSubscriptionBase subscription, final CallContext context) throws SubscriptionBaseApiException { final EntitlementState currentState = subscription.getState(); if (currentState == EntitlementState.CANCELLED) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CANCEL_BAD_STATE, subscription.getId(), currentState); } final Plan currentPlan = subscription.getCurrentOrPendingPlan(); final PlanPhaseSpecifier planPhase = new PlanPhaseSpecifier(currentPlan.getName(), null); try { final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context); final Catalog fullCatalog = catalogInternalApi.getFullCatalog(true, true, internalCallContext); final BillingActionPolicy policy = fullCatalog.planCancelPolicy(planPhase, clock.getUTCNow(), subscription.getStartDate()); Preconditions.checkState(policy != BillingActionPolicy.START_OF_TERM, "A default START_OF_TERM policy is not availaible"); final DateTime effectiveDate = subscription.getPlanChangeEffectiveDate(policy, null, -1, null); return doCancelPlan(ImmutableMap.<DefaultSubscriptionBase, DateTime>of(subscription, effectiveDate), fullCatalog, internalCallContext); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(currentPlan.getName(), subscriptionForCancellation.getCurrentPhase().getPhaseType()); policy = catalog.planCancelPolicy(spec, clock.getUTCNow(), subscriptionForCancellation.getStartDate());
@Override public boolean cancel(final DefaultSubscriptionBase subscription, final CallContext context) throws SubscriptionBaseApiException { final EntitlementState currentState = subscription.getState(); if (currentState == EntitlementState.CANCELLED) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CANCEL_BAD_STATE, subscription.getId(), currentState); } final Plan currentPlan = subscription.getCurrentOrPendingPlan(); final PlanPhaseSpecifier planPhase = new PlanPhaseSpecifier(currentPlan.getName(), null); try { final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context); final Catalog fullCatalog = catalogInternalApi.getFullCatalog(true, true, internalCallContext); final BillingActionPolicy policy = fullCatalog.planCancelPolicy(planPhase, clock.getUTCNow(), subscription.getStartDate()); Preconditions.checkState(policy != BillingActionPolicy.START_OF_TERM, "A default START_OF_TERM policy is not availaible"); final DateTime effectiveDate = subscription.getPlanChangeEffectiveDate(policy, null, -1, null); return doCancelPlan(ImmutableMap.<DefaultSubscriptionBase, DateTime>of(subscription, effectiveDate), fullCatalog, internalCallContext); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(currentPlan.getName(), subscriptionForCancellation.getCurrentPhase().getPhaseType()); policy = catalog.planCancelPolicy(spec, clock.getUTCNow(), subscriptionForCancellation.getStartDate());