Search in sources :

Example 6 with PlanSpecifier

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

the class TestUserApiChangePlan method tChangePlanBundleAlignEOTWithNoChargeThroughDate.

private void tChangePlanBundleAlignEOTWithNoChargeThroughDate(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet, final String toProd, final BillingPeriod toTerm, final String toPlanSet) {
    try {
        // CREATE
        final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet);
        // MOVE TO NEXT PHASE
        PlanPhase currentPhase = subscription.getCurrentPhase();
        testListener.pushExpectedEvent(NextEvent.PHASE);
        final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
        clock.addDeltaFromReality(it.toDurationMillis());
        final DateTime futureNow = clock.getUTCNow();
        final DateTime nextExpectedPhaseChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), currentPhase.getDuration());
        assertTrue(futureNow.isAfter(nextExpectedPhaseChange));
        assertListenerStatus();
        // CHANGE PLAN
        testListener.pushExpectedEvent(NextEvent.CHANGE);
        subscription.changePlan(new PlanSpecifier(toProd, toTerm, toPlanSet), null, callContext);
        assertListenerStatus();
        // CHECK CHANGE PLAN
        currentPhase = subscription.getCurrentPhase();
        checkChangePlan(subscription, toProd, ProductCategory.BASE, toTerm, PhaseType.EVERGREEN);
        assertListenerStatus();
    } catch (SubscriptionBaseApiException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : PlanPhase(org.killbill.billing.catalog.api.PlanPhase) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Example 7 with PlanSpecifier

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

the class TestStandaloneCatalogWithPriceOverride method testCreatePlanInvalidProduct.

@Test(groups = "slow")
public void testCreatePlanInvalidProduct() throws Exception {
    final StandaloneCatalog catalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class);
    final StaticCatalog standaloneCatalogWithPriceOverride = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalCallContext.getTenantRecordId(), internalCallContextFactory);
    try {
        final PlanSpecifier specWithNullProduct = new PlanSpecifier("INVALID", BillingPeriod.ANNUAL, "DEFAULT");
        standaloneCatalogWithPriceOverride.createOrFindCurrentPlan(specWithNullProduct, null);
        Assert.fail();
    } catch (final CatalogApiException e) {
        Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PRODUCT.getCode());
    }
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 8 with PlanSpecifier

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

the class DefaultPlanRules method planChange.

public PlanChangeResult planChange(final PlanPhaseSpecifier from, final PlanSpecifier to, final StaticCatalog catalog) throws CatalogApiException {
    final DefaultPriceList toPriceList = to.getPriceListName() != null ? (DefaultPriceList) catalog.findCurrentPricelist(to.getPriceListName()) : findPriceList(from, catalog);
    // If we use old scheme {product, billingPeriod, pricelist}, ensure pricelist is correct
    // (Pricelist may be null because if it is unspecified this is the principal use-case)
    final PlanSpecifier toWithPriceList = to.getPlanName() == null ? new PlanSpecifier(to.getProductName(), to.getBillingPeriod(), toPriceList.getName()) : to;
    final BillingActionPolicy policy = getPlanChangePolicy(from, toWithPriceList, catalog);
    if (policy == BillingActionPolicy.ILLEGAL) {
        throw new IllegalPlanChange(from, toWithPriceList);
    }
    final PlanAlignmentChange alignment = getPlanChangeAlignment(from, toWithPriceList, catalog);
    return new PlanChangeResult(toPriceList, policy, alignment);
}
Also used : BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) IllegalPlanChange(org.killbill.billing.catalog.api.IllegalPlanChange) PlanAlignmentChange(org.killbill.billing.catalog.api.PlanAlignmentChange) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) PlanChangeResult(org.killbill.billing.catalog.api.PlanChangeResult) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Example 9 with PlanSpecifier

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

the class TestDefaultEntitlement method testCancelWithEntitlementPolicyEOTNoCTDAndImmediateChange.

@Test(groups = "slow")
public void testCancelWithEntitlementPolicyEOTNoCTDAndImmediateChange() throws AccountApiException, EntitlementApiException, SubscriptionApiException, InterruptedException {
    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 Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Immediate change during trial
    testListener.pushExpectedEvent(NextEvent.CHANGE);
    entitlement.changePlan(new PlanSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Verify the change is immediate
    final Entitlement entitlement2 = entitlementApi.getEntitlementForId(entitlement.getId(), callContext);
    assertEquals(entitlement2.getLastActivePlan().getProduct().getName(), "Assault-Rifle");
    testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK);
    final Entitlement cancelledEntitlement = entitlement.cancelEntitlementWithPolicy(EntitlementActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    assertEquals(cancelledEntitlement.getState(), EntitlementState.CANCELLED);
    assertEquals(cancelledEntitlement.getEffectiveEndDate(), initialDate);
    // Entitlement started in trial on 2013-08-07, which is when we want the billing cancellation date to occur
    final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(entitlement.getBaseEntitlementId(), callContext);
    assertEquals(subscription.getBillingEndDate(), new LocalDate(2013, 8, 7));
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) LocalDate(org.joda.time.LocalDate) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 10 with PlanSpecifier

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

the class TestCase method testCaseOrder.

@Test
public void testCaseOrder() throws CatalogApiException {
    final MockCatalog cat = new MockCatalog();
    final DefaultProduct product = cat.getCurrentProduct(0);
    final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final DefaultCaseResult cr0 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, Result.FOO);
    final DefaultCaseResult cr1 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.MONTHLY, priceList, Result.BAR);
    final DefaultCaseResult cr2 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.ANNUAL, priceList, Result.DIPSY);
    final DefaultCaseResult cr3 = new DefaultCaseResult(product, ProductCategory.BASE, BillingPeriod.ANNUAL, priceList, Result.LALA);
    final Result r1 = DefaultCase.getResult(new DefaultCaseResult[] { cr0, cr1, cr2, cr3 }, new PlanSpecifier(product.getName(), BillingPeriod.MONTHLY, priceList.getName()), cat);
    Assert.assertEquals(r1, Result.FOO);
    final Result r2 = DefaultCase.getResult(new DefaultCaseResult[] { cr0, cr1, cr2 }, new PlanSpecifier(product.getName(), BillingPeriod.ANNUAL, priceList.getName()), cat);
    Assert.assertEquals(r2, Result.DIPSY);
}
Also used : MockCatalog(org.killbill.billing.catalog.MockCatalog) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Aggregations

PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)39 Test (org.testng.annotations.Test)28 DateTime (org.joda.time.DateTime)16 Interval (org.joda.time.Interval)11 LocalDate (org.joda.time.LocalDate)9 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)8 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)7 Duration (org.killbill.billing.catalog.api.Duration)7 Account (org.killbill.billing.account.api.Account)6 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)6 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)6 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)5 Plan (org.killbill.billing.catalog.api.Plan)5 ArrayList (java.util.ArrayList)4 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)4 PlanAlignmentCreate (org.killbill.billing.catalog.api.PlanAlignmentCreate)4 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)4 BigDecimal (java.math.BigDecimal)3 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)3