@Override public Response doOperation(final CallContext ctx) throws EntitlementApiException, SubscriptionApiException { final Entitlement current = entitlementApi.getEntitlementForId(subscriptionId, ctx); final LocalDate inputLocalDate = toLocalDate(requestedDate); final Entitlement newEntitlement; if (billingPolicy == null && entitlementPolicy == null) { newEntitlement = current.cancelEntitlementWithDate(inputLocalDate, useRequestedDateForBilling, pluginProperties, ctx); } else if (billingPolicy == null && entitlementPolicy != null) { newEntitlement = current.cancelEntitlementWithPolicy(entitlementPolicy, pluginProperties, ctx); } else if (billingPolicy != null && entitlementPolicy == null) { newEntitlement = current.cancelEntitlementWithDateOverrideBillingPolicy(inputLocalDate, billingPolicy, pluginProperties, ctx); } else { newEntitlement = current.cancelEntitlementWithPolicyOverrideBillingPolicy(entitlementPolicy, billingPolicy, pluginProperties, ctx); } final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(newEntitlement.getId(), ctx); final LocalDate nowInAccountTimeZone = new LocalDate(callContext.getCreatedDate(), subscription.getBillingEndDate().getChronology().getZone()); isImmediateOp = subscription.getBillingEndDate() != null && !subscription.getBillingEndDate().isAfter(nowInAccountTimeZone); return Response.status(Status.NO_CONTENT).build(); }
entitlement.cancelEntitlementWithDateOverrideBillingPolicy(clock.getUTCToday(), BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); entitlement.cancelEntitlementWithDateOverrideBillingPolicy(clock.getUTCToday(), BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Entitlement is already cancelled"); } catch (final EntitlementApiException e) { addOnEntitlement.cancelEntitlementWithDateOverrideBillingPolicy(clock.getUTCToday(), BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Add-On Entitlement is already cancelled"); } catch (final EntitlementApiException e) {
baseEntitlement.cancelEntitlementWithDateOverrideBillingPolicy(clock.getUTCToday(), BillingActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), testCallContext); assertListenerStatus();
@Test(groups = "slow") public void testUncancelEffectiveCancelledEntitlement() throws AccountApiException, EntitlementApiException, SubscriptionBaseApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); // Keep the same object for the whole test, to make sure we refresh its state before r/w calls testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); testListener.pushExpectedEvent(NextEvent.PHASE); clock.addDays(30); assertListenerStatus(); subscriptionInternalApi.setChargedThroughDate(entitlement.getId(), clock.getUTCNow().plusMonths(1), internalCallContext); final LocalDate entitlementCancelledDate = clock.getToday(account.getTimeZone()); testListener.pushExpectedEvent(NextEvent.BLOCK); final Entitlement cancelledEntitlement = entitlement.cancelEntitlementWithDateOverrideBillingPolicy(clock.getToday(account.getTimeZone()), BillingActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); Assert.assertEquals(cancelledEntitlement.getEffectiveEndDate(), entitlementCancelledDate); testListener.pushExpectedEvent(NextEvent.UNCANCEL); cancelledEntitlement.uncancelEntitlement(ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement reactivatedEntitlement = entitlementApi.getEntitlementForId(cancelledEntitlement.getId(), callContext); Assert.assertNull(reactivatedEntitlement.getEffectiveEndDate()); }