Search in sources :

Example 1 with PlanAlignmentCreate

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

the class PlanAligner method getTimedPhaseOnCreate.

private List<TimedPhase> getTimedPhaseOnCreate(final DateTime subscriptionStartDate, final DateTime bundleStartDate, final Plan plan, @Nullable final PhaseType initialPhase, final SubscriptionCatalog catalog, final DateTime catalogEffectiveDate, final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException {
    final PlanSpecifier planSpecifier = new PlanSpecifier(plan.getName());
    final DateTime planStartDate;
    final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, catalogEffectiveDate, subscriptionStartDate);
    switch(alignment) {
        case START_OF_SUBSCRIPTION:
            planStartDate = subscriptionStartDate;
            break;
        case START_OF_BUNDLE:
            planStartDate = bundleStartDate;
            break;
        default:
            throw new SubscriptionBaseError(String.format("Unknown PlanAlignmentCreate %s", alignment));
    }
    return getPhaseAlignments(plan, initialPhase, planStartDate);
}
Also used : SubscriptionBaseError(org.killbill.billing.subscription.exceptions.SubscriptionBaseError) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Example 2 with PlanAlignmentCreate

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

the class TestUserApiAddOn method testAddonCreateWithSubscriptionAlign.

@Test(groups = "slow")
public void testAddonCreateWithSubscriptionAlign() throws SubscriptionBaseApiException, CatalogApiException {
    final String aoProduct = "Laser-Scope";
    final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
    final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // This is just to double check our test catalog gives us what we want before we start the test
    final PlanSpecifier planSpecifier = new PlanSpecifier(aoProduct, aoTerm, aoPriceList);
    final DateTime utcNow = clock.getUTCNow();
    final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, utcNow, utcNow);
    assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
    testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignment);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 3 with PlanAlignmentCreate

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

the class PlanAligner method getTimedPhaseOnCreate.

private List<TimedPhase> getTimedPhaseOnCreate(final DateTime subscriptionStartDate, final DateTime bundleStartDate, final Plan plan, @Nullable final PhaseType initialPhase, final DateTime effectiveDate, final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException {
    final Catalog catalog = catalogService.getFullCatalog(true, true, context);
    final PlanSpecifier planSpecifier = new PlanSpecifier(plan.getName());
    final DateTime planStartDate;
    final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, effectiveDate);
    switch(alignment) {
        case START_OF_SUBSCRIPTION:
            planStartDate = subscriptionStartDate;
            break;
        case START_OF_BUNDLE:
            planStartDate = bundleStartDate;
            break;
        default:
            throw new SubscriptionBaseError(String.format("Unknown PlanAlignmentCreate %s", alignment));
    }
    return getPhaseAlignments(plan, initialPhase, planStartDate);
}
Also used : SubscriptionBaseError(org.killbill.billing.subscription.exceptions.SubscriptionBaseError) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) Catalog(org.killbill.billing.catalog.api.Catalog) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier)

Example 4 with PlanAlignmentCreate

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

the class TestLoadRules method test.

@Test(groups = "fast")
public void test() throws Exception {
    final StandaloneCatalog catalog = getCatalog("WeaponsHireSmall.xml");
    Assert.assertNotNull(catalog);
    final DefaultPlanRules rules = (DefaultPlanRules) catalog.getPlanRules();
    final PlanSpecifier specifier = new PlanSpecifier("Laser-Scope", BillingPeriod.MONTHLY, "DEFAULT");
    final PlanAlignmentCreate alignment = rules.getPlanCreateAlignment(specifier);
    Assert.assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
    final PlanSpecifier specifier2 = new PlanSpecifier("Extra-Ammo", BillingPeriod.MONTHLY, "DEFAULT");
    final PlanAlignmentCreate alignment2 = rules.getPlanCreateAlignment(specifier2);
    Assert.assertEquals(alignment2, PlanAlignmentCreate.START_OF_BUNDLE);
}
Also used : StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 5 with PlanAlignmentCreate

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

the class TestUserApiAddOn method testAddonCreateWithBundleAlign.

@Test(groups = "slow")
public void testAddonCreateWithBundleAlign() throws CatalogApiException, SubscriptionBaseApiException {
    final String aoProduct = "Telescopic-Scope";
    final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
    final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // This is just to double check our test catalog gives us what we want before we start the test
    final PlanSpecifier planSpecifier = new PlanSpecifier(aoProduct, aoTerm, aoPriceList);
    final DateTime utcNow = clock.getUTCNow();
    final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, utcNow, utcNow);
    assertEquals(alignment, PlanAlignmentCreate.START_OF_BUNDLE);
    testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignment);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) PlanAlignmentCreate(org.killbill.billing.catalog.api.PlanAlignmentCreate) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Aggregations

PlanAlignmentCreate (org.killbill.billing.catalog.api.PlanAlignmentCreate)5 PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)5 DateTime (org.joda.time.DateTime)4 Test (org.testng.annotations.Test)3 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)2 SubscriptionBaseError (org.killbill.billing.subscription.exceptions.SubscriptionBaseError)2 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)1 Catalog (org.killbill.billing.catalog.api.Catalog)1