@Override public Entitlement apply(@Nullable final Void dontcare) { try { // Need to fetch again to get latest CTD updated from the system Entitlement refreshedEntitlement = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); refreshedEntitlement = refreshedEntitlement.cancelEntitlementWithDate(requestedDate, false, ImmutableList.<PluginProperty>of(), callContext); return refreshedEntitlement; } catch (final EntitlementApiException e) { fail(e.getMessage()); return null; } } }, events);
@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(); }
createdEntitlement.cancelEntitlementWithDate(futureStartDate, true, ImmutableList.<PluginProperty>of(), callContext);
entitlement = entitlement.cancelEntitlementWithDate(cancellationDate, true, ImmutableList.<PluginProperty>of(), callContext);
entitlement = entitlement.cancelEntitlementWithDate(cancellationDate, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
@Test(groups = "slow") public void testCancelWithEntitlementDate() throws AccountApiException, EntitlementApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); // Create entitlement and check each field testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(planPhaseSpecifier), account.getExternalKey(), null, null, false, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); assertEquals(entitlement.getSourceType(), EntitlementSourceType.NATIVE); clock.addDays(5); testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK); entitlement.cancelEntitlementWithDate(null, true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement2.getState(), EntitlementState.CANCELLED); assertEquals(entitlement2.getEffectiveEndDate(), clock.getUTCToday()); assertEquals(entitlement2.getSourceType(), EntitlementSourceType.NATIVE); }
entitlement.cancelEntitlementWithDate(new LocalDate(clock.getUTCNow(), account.getTimeZone()), true, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
entitlement.cancelEntitlementWithDate(effectiveCancellationDate, true, ImmutableList.<PluginProperty>of(), callContext);
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/840") public void testUncancelEntitlementFor_STANDALONE_Product() throws AccountApiException, EntitlementApiException { final LocalDate initialDate = new LocalDate(2013, 8, 7); clock.setDay(initialDate); final Account account = createAccount(getAccountData(7)); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Knife", BillingPeriod.MONTHLY, "notrial", null); // Create entitlement and check each field testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK); final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec), account.getExternalKey(), null, null, false, false, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); clock.addDays(5); final LocalDate cancelDate = new LocalDate(clock.getUTCToday().plusDays(1)); entitlement.cancelEntitlementWithDate(cancelDate, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement2.getState(), EntitlementState.ACTIVE); assertEquals(entitlement2.getEffectiveEndDate(), cancelDate); testListener.pushExpectedEvents(NextEvent.UNCANCEL); entitlement2.uncancelEntitlement(ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); clock.addDays(1); final Entitlement entitlement3 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement3.getState(), EntitlementState.ACTIVE); }
createdEntitlement.cancelEntitlementWithDate(invalidCancelDate, true, null, callContext); Assert.fail("Should not succeed to cancel subscription prior startDate"); } catch (final EntitlementApiException e) { final Entitlement cancelledEntitlement = createdEntitlement.cancelEntitlementWithDate(futureDate, true, null, callContext); assertEquals(cancelledEntitlement.getEffectiveEndDate().compareTo(futureDate), 0); assertListenerStatus();
@Test(groups = "slow") public void testUncancel() throws AccountApiException, EntitlementApiException { 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); // Create entitlement and check each field 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); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); clock.addDays(5); final LocalDate cancelDate = new LocalDate(clock.getUTCToday().plusDays(1)); entitlement.cancelEntitlementWithDate(cancelDate, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement2.getState(), EntitlementState.ACTIVE); assertEquals(entitlement2.getEffectiveEndDate(), cancelDate); testListener.pushExpectedEvents(NextEvent.UNCANCEL); entitlement2.uncancelEntitlement(ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus(); clock.addDays(1); final Entitlement entitlement3 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement3.getState(), EntitlementState.ACTIVE); }
bpEntitlement = bpEntitlement.cancelEntitlementWithDate(new LocalDate("2016-05-01"), true, ImmutableList.<PluginProperty>of(), callContext); assertEquals(bpEntitlement.getState(), EntitlementState.ACTIVE); assertListenerStatus();
addOn2Entitlement.cancelEntitlementWithDate(addOn2CancellationDate, true, ImmutableList.<PluginProperty>of(), callContext);
baseEntitlement.cancelEntitlementWithDate(cancelDate, false, ImmutableList.<PluginProperty>of(), callContext); assertListenerStatus();
@Test(groups = "slow") public void testCancelWithEntitlementDateInFuture() throws AccountApiException, EntitlementApiException { 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); // Create entitlement and check each field 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); assertEquals(entitlement.getState(), EntitlementState.ACTIVE); clock.addDays(5); final LocalDate cancelDate = new LocalDate(clock.getUTCToday().plusDays(1)); entitlement.cancelEntitlementWithDate(cancelDate, true, ImmutableList.<PluginProperty>of(), callContext); final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement2.getState(), EntitlementState.ACTIVE); assertEquals(entitlement2.getEffectiveEndDate(), cancelDate); clock.addDays(1); testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK); assertListenerStatus(); final Entitlement entitlement3 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext); assertEquals(entitlement3.getState(), EntitlementState.CANCELLED); assertEquals(entitlement3.getEffectiveEndDate(), cancelDate); }
baseEntitlement.cancelEntitlementWithDate(cancelDate, true, ImmutableList.<PluginProperty>of(), callContext);
bpEntitlement = bpEntitlement.cancelEntitlementWithDate(new LocalDate("2016-05-01"), true, ImmutableList.<PluginProperty>of(), callContext); assertEquals(bpEntitlement.getState(), EntitlementState.ACTIVE); assertListenerStatus();