Search in sources :

Example 11 with CatalogApiException

use of org.killbill.billing.catalog.api.CatalogApiException 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 12 with CatalogApiException

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

the class TestVersionedCatalog method testFindPlanWithDates.

@Test(groups = "fast")
public void testFindPlanWithDates() throws Exception {
    final DateTime dt0 = new DateTime("2010-01-01T00:00:00+00:00");
    final DateTime dt1 = new DateTime("2011-01-01T00:01:00+00:00");
    final DateTime dt2 = new DateTime("2011-02-02T00:01:00+00:00");
    final DateTime dt214 = new DateTime("2011-02-14T00:01:00+00:00");
    final DateTime dt3 = new DateTime("2011-03-03T00:01:00+00:00");
    // New subscription
    try {
        vc.findPlan("pistol-monthly", dt0, dt0);
        Assert.fail("Exception should have been thrown there are no plans for this date");
    } catch (CatalogApiException e) {
        // Expected behaviour
        log.error("Expected exception", e);
    }
    final Plan newSubPlan1 = vc.findPlan("pistol-monthly", dt1, dt1);
    final Plan newSubPlan2 = vc.findPlan("pistol-monthly", dt2, dt2);
    final Plan newSubPlan214 = vc.findPlan("pistol-monthly", dt214, dt214);
    final Plan newSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt3);
    Assert.assertEquals(newSubPlan1.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
    Assert.assertEquals(newSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
    Assert.assertEquals(newSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
    Assert.assertEquals(newSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("49.95"));
    // Existing subscription
    final Plan exSubPlan2 = vc.findPlan("pistol-monthly", dt2, dt1);
    final Plan exSubPlan214 = vc.findPlan("pistol-monthly", dt214, dt1);
    final Plan exSubPlan3 = vc.findPlan("pistol-monthly", dt3, dt1);
    Assert.assertEquals(exSubPlan2.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("29.95"));
    Assert.assertEquals(exSubPlan214.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
    Assert.assertEquals(exSubPlan3.getAllPhases()[1].getRecurring().getRecurringPrice().getPrice(Currency.USD), new BigDecimal("39.95"));
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 13 with CatalogApiException

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

the class DefaultCatalogUserApi method createDefaultEmptyCatalog.

@Override
public void createDefaultEmptyCatalog(final DateTime effectiveDate, final CallContext callContext) throws CatalogApiException {
    try {
        final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(callContext);
        final StandaloneCatalog currentCatalog = getCurrentStandaloneCatalogForTenant(internalTenantContext);
        final CatalogUpdater catalogUpdater = (currentCatalog != null) ? new CatalogUpdater(currentCatalog) : new CatalogUpdater(BillingMode.IN_ADVANCE, effectiveDate, null);
        catalogCache.clearCatalog(internalTenantContext);
        tenantApi.updateTenantKeyValue(TenantKey.CATALOG.toString(), catalogUpdater.getCatalogXML(), callContext);
    } catch (TenantApiException e) {
        throw new CatalogApiException(e);
    }
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantApiException(org.killbill.billing.tenant.api.TenantApiException) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) CatalogUpdater(org.killbill.billing.catalog.CatalogUpdater)

Example 14 with CatalogApiException

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

the class EhCacheOverriddenPlanCache method loadOverriddenPlan.

private DefaultPlan loadOverriddenPlan(final String planName, final StaticCatalog catalog, final InternalTenantContext context) throws CatalogApiException {
    final Matcher m = DefaultPriceOverride.CUSTOM_PLAN_NAME_PATTERN.matcher(planName);
    if (!m.matches()) {
        throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PLAN, planName);
    }
    final String parentPlanName = m.group(1);
    final Long planDefRecordId = Long.parseLong(m.group(2));
    final List<CatalogOverridePhaseDefinitionModelDao> phaseDefs = overrideDao.getOverriddenPlanPhases(planDefRecordId, context);
    final DefaultPlan defaultPlan = (DefaultPlan) catalog.findCurrentPlan(parentPlanName);
    final PlanPhasePriceOverride[] overrides = createOverrides(defaultPlan, phaseDefs);
    final DefaultPlan result = new DefaultPlan(planName, defaultPlan, overrides);
    result.initialize((StandaloneCatalog) catalog, ((StandaloneCatalog) catalog).getCatalogURI());
    return result;
}
Also used : Matcher(java.util.regex.Matcher) CatalogOverridePhaseDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao) DefaultPlan(org.killbill.billing.catalog.DefaultPlan) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)

Example 15 with CatalogApiException

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

the class DefaultPlan method dateOfFirstRecurringNonZeroCharge.

@Override
public DateTime dateOfFirstRecurringNonZeroCharge(final DateTime subscriptionStartDate, final PhaseType initialPhaseType) {
    DateTime result = subscriptionStartDate;
    boolean skipPhase = initialPhaseType != null;
    for (final PlanPhase phase : getAllPhases()) {
        if (skipPhase) {
            if (phase.getPhaseType() != initialPhaseType) {
                continue;
            } else {
                skipPhase = false;
            }
        }
        final Recurring recurring = phase.getRecurring();
        if (phase.getDuration().getUnit() != TimeUnit.UNLIMITED && (recurring == null || recurring.getRecurringPrice() == null || recurring.getRecurringPrice().isZero())) {
            try {
                result = phase.getDuration().addToDateTime(result);
            } catch (final CatalogApiException ignored) {
            }
        } else {
            break;
        }
    }
    return result;
}
Also used : Recurring(org.killbill.billing.catalog.api.Recurring) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) DateTime(org.joda.time.DateTime) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Aggregations

CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)61 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)22 DateTime (org.joda.time.DateTime)20 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)14 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)12 Plan (org.killbill.billing.catalog.api.Plan)12 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)11 ArrayList (java.util.ArrayList)9 UUID (java.util.UUID)9 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)8 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)8 LinkedList (java.util.LinkedList)7 Catalog (org.killbill.billing.catalog.api.Catalog)7 Test (org.testng.annotations.Test)7 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)6 PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)6 URI (java.net.URI)5 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)5 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)5