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());
}
}
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"));
}
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);
}
}
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;
}
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;
}
Aggregations