use of org.killbill.billing.catalog.api.CatalogApiException in project killbill by killbill.
the class DefaultSubscriptionBaseApiService method createPlan.
@Override
public DefaultSubscriptionBase createPlan(final SubscriptionBuilder builder, final Plan plan, final PhaseType initialPhase, final String realPriceList, final DateTime effectiveDate, final DateTime processedDate, final CallContext context) throws SubscriptionBaseApiException {
final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(builder, this, clock);
final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context);
try {
final List<SubscriptionBaseEvent> events = getEventsOnCreation(subscription.getBundleId(), subscription.getId(), subscription.getAlignStartDate(), subscription.getBundleStartDate(), plan, initialPhase, realPriceList, effectiveDate, processedDate, internalCallContext);
dao.createSubscription(subscription, events, internalCallContext);
subscription.rebuildTransitions(dao.getEventsForSubscription(subscription.getId(), internalCallContext), catalogService.getFullCatalog(true, true, internalCallContext));
return subscription;
} catch (final CatalogApiException e) {
throw new SubscriptionBaseApiException(e);
}
}
use of org.killbill.billing.catalog.api.CatalogApiException in project killbill by killbill.
the class DefaultSubscriptionBaseApiService method changePlan.
@Override
public DateTime changePlan(final DefaultSubscriptionBase subscription, final PlanSpecifier spec, final List<PlanPhasePriceOverride> overrides, final CallContext context) throws SubscriptionBaseApiException {
final DateTime now = clock.getUTCNow();
validateEntitlementState(subscription);
final PlanChangeResult planChangeResult = getPlanChangeResult(subscription, spec, now, context);
final DateTime effectiveDate = dryRunChangePlan(subscription, spec, null, planChangeResult.getPolicy(), context);
validateEffectiveDate(subscription, effectiveDate);
try {
doChangePlan(subscription, spec, overrides, effectiveDate, context);
} catch (final CatalogApiException e) {
throw new SubscriptionBaseApiException(e);
}
return effectiveDate;
}
use of org.killbill.billing.catalog.api.CatalogApiException in project killbill by killbill.
the class DefaultSubscriptionDao method rebuildSubscriptionAndNotifyBusOfEffectiveImmediateChange.
// Sends bus notification for event on effective date -- only used for operation that happen immediately
private void rebuildSubscriptionAndNotifyBusOfEffectiveImmediateChange(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) {
try {
final DefaultSubscriptionBase upToDateSubscription = createSubscriptionWithNewEvent(subscription, immediateEvent, context);
notifyBusOfEffectiveImmediateChange(entitySqlDaoWrapperFactory, upToDateSubscription, immediateEvent, seqId, context);
} catch (final CatalogApiException e) {
log.warn("Failed to post effective event for subscriptionId='{}'", subscription.getId(), e);
}
}
use of org.killbill.billing.catalog.api.CatalogApiException in project killbill by killbill.
the class TestStandaloneCatalogWithPriceOverride method testCreateAmbiguousPlan.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/842")
public void testCreateAmbiguousPlan() throws Exception {
final StandaloneCatalog catalog = getCatalog("SpyCarAdvanced.xml");
final StaticCatalog standaloneCatalogWithPriceOverride = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalCallContext.getTenantRecordId(), internalCallContextFactory);
// Create ambiguous plan name
final PlanSpecifier spec = new PlanSpecifier("standard-monthly-67890");
final PlanPhasePriceOverridesWithCallContext overrides = Mockito.mock(PlanPhasePriceOverridesWithCallContext.class);
Mockito.when(overrides.getCallContext()).thenReturn(callContext);
final PlanPhasePriceOverride override = new DefaultPlanPhasePriceOverride("standard-monthly-evergreen", Currency.USD, null, BigDecimal.ONE, ImmutableList.<UsagePriceOverride>of());
Mockito.when(overrides.getOverrides()).thenReturn(ImmutableList.of(override));
final Plan plan = standaloneCatalogWithPriceOverride.createOrFindPlan(spec, overrides);
Assert.assertTrue(plan.getName().startsWith("standard-monthly-67890-"));
Assert.assertTrue(priceOverridePattern.isOverriddenPlan(plan.getName()));
// From the catalog
Assert.assertNotNull(catalog.findPlan("standard-monthly"));
Assert.assertNotNull(standaloneCatalogWithPriceOverride.findPlan("standard-monthly"));
// Created on the fly
try {
catalog.findPlan(plan.getName());
Assert.fail();
} catch (final CatalogApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PLAN.getCode());
}
Assert.assertNotNull(standaloneCatalogWithPriceOverride.findPlan("standard-monthly-1"));
// From the catalog
Assert.assertNotNull(catalog.findPlan("standard-monthly-12345"));
Assert.assertNotNull(standaloneCatalogWithPriceOverride.findPlan("standard-monthly-12345"));
}
use of org.killbill.billing.catalog.api.CatalogApiException in project killbill by killbill.
the class TestStandaloneCatalogWithPriceOverride method testCreatePlanNoProduct.
@Test(groups = "slow")
public void testCreatePlanNoProduct() throws Exception {
final StandaloneCatalog catalog = getCatalog("SpyCarAdvanced.xml");
final StaticCatalog standaloneCatalogWithPriceOverride = new StandaloneCatalogWithPriceOverride(catalog, priceOverride, internalCallContext.getTenantRecordId(), internalCallContextFactory);
try {
final PlanSpecifier specWithNullProduct = new PlanSpecifier(null, BillingPeriod.ANNUAL, "DEFAULT");
standaloneCatalogWithPriceOverride.createOrFindPlan(specWithNullProduct, null);
Assert.fail();
} catch (final CatalogApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.CAT_NULL_PRODUCT_NAME.getCode());
}
}
Aggregations