@Override public DateTime changePlanWithPolicy(final String productName, final BillingPeriod term, final String priceList, final BillingActionPolicy policy, final CallContext context) throws SubscriptionBaseApiException { return sub.changePlanWithPolicy(productName, term, priceList, policy, context); }
@Test(groups = "fast") public void testChangeSubscriptionWithPolicy() throws Exception { final SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME); try { subscription.changePlanWithPolicy("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, BillingActionPolicy.ILLEGAL, callContext); Assert.fail(); } catch (SubscriptionBaseError error) { assertTrue(true); assertEquals(subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext).getCurrentPlan().getBillingPeriod(), BillingPeriod.ANNUAL); } // Assume the call takes less than a second assertEquals(DefaultClock.truncateMs(subscription.changePlanWithPolicy("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, BillingActionPolicy.IMMEDIATE, callContext)), DefaultClock.truncateMs(clock.getUTCNow())); assertEquals(subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext).getCurrentPlan().getBillingPeriod(), BillingPeriod.MONTHLY); }
@Override public Entitlement changePlanOverrideBillingPolicy(final String productName, final BillingPeriod billingPeriod, final String priceList, final LocalDate localDateX, final BillingActionPolicy actionPolicy, final CallContext callContext) throws EntitlementApiException { // Get the latest state from disk refresh(callContext); if (!eventsStream.isEntitlementActive()) { throw new EntitlementApiException(ErrorCode.SUB_CHANGE_NON_ACTIVE, getId(), getState()); } final InternalCallContext context = internalCallContextFactory.createInternalCallContext(getAccountId(), callContext); try { checker.checkBlockedChange(getSubscriptionBase(), context); } catch (BlockingApiException e) { throw new EntitlementApiException(e, e.getCode(), e.getMessage()); } final DateTime effectiveChangeDate; try { effectiveChangeDate = getSubscriptionBase().changePlanWithPolicy(productName, billingPeriod, priceList, actionPolicy, callContext); } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } blockAddOnsIfRequired(effectiveChangeDate, callContext, context); return entitlementApi.getEntitlementForId(getId(), callContext); }