use of org.killbill.billing.catalog.api.StaticCatalog 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.StaticCatalog in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method testWithPriceOverride.
@Test(groups = "slow")
public void testWithPriceOverride() throws Exception {
// Create a per-tenant catalog with one plan
final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("bar-monthly", "Bar", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
catalogUserApi.addSimplePlan(desc1, init, testCallContext);
StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
assertEquals(catalog.getCurrentPlans().size(), 1);
final Plan plan = catalog.getCurrentPlans().iterator().next();
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("bar-monthly", null);
final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
overrides.add(new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), account.getCurrency(), null, BigDecimal.ONE));
final Entitlement baseEntitlement = createEntitlement(spec, overrides, true);
List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, testCallContext);
assertEquals(invoices.size(), 1);
assertEquals(invoices.get(0).getChargedAmount().compareTo(BigDecimal.ONE), 0);
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addMonths(1);
assertListenerStatus();
invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, testCallContext);
assertEquals(invoices.size(), 2);
assertEquals(invoices.get(1).getChargedAmount().compareTo(BigDecimal.ONE), 0);
// Change plan to original (non overridden plan)
busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
baseEntitlement.changePlan(spec, null, ImmutableList.<PluginProperty>of(), testCallContext);
assertListenerStatus();
invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, testCallContext);
assertEquals(invoices.size(), 3);
// 10 (recurring) - 1 (repair)
assertEquals(invoices.get(2).getChargedAmount().compareTo(new BigDecimal("9.00")), 0);
}
use of org.killbill.billing.catalog.api.StaticCatalog in project killbill by killbill.
the class CatalogResource method getAvailableAddons.
// Need to figure out dependency on StandaloneCatalog
// @GET
// @Path("/xsd")
// @Produces(APPLICATION_XML)
// public String getCatalogXsd() throws Exception
// {
// InputStream stream = XMLSchemaGenerator.xmlSchema(StandaloneCatalog.class);
// StringWriter writer = new StringWriter();
// IOUtils.copy(stream, writer);
// String result = writer.toString();
//
// return result;
// }
@TimedResource
@GET
@Path("/availableAddons")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve available add-ons for a given product", response = PlanDetailJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getAvailableAddons(@QueryParam("baseProductName") final String baseProductName, @Nullable @QueryParam("priceListName") final String priceListName, @javax.ws.rs.core.Context final HttpServletRequest request) throws CatalogApiException {
final TenantContext tenantContext = context.createContext(request);
final StaticCatalog catalog = catalogUserApi.getCurrentCatalog(catalogName, tenantContext);
final List<Listing> listings = catalog.getAvailableAddOnListings(baseProductName, priceListName);
final List<PlanDetailJson> details = new ArrayList<PlanDetailJson>();
for (final Listing listing : listings) {
details.add(new PlanDetailJson(listing));
}
return Response.status(Status.OK).entity(details).build();
}
use of org.killbill.billing.catalog.api.StaticCatalog in project killbill by killbill.
the class CatalogResource method getAvailableBasePlans.
@TimedResource
@GET
@Path("/availableBasePlans")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve available base plans", response = PlanDetailJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getAvailableBasePlans(@javax.ws.rs.core.Context final HttpServletRequest request) throws CatalogApiException {
final TenantContext tenantContext = context.createContext(request);
final StaticCatalog catalog = catalogUserApi.getCurrentCatalog(catalogName, tenantContext);
final List<Listing> listings = catalog.getAvailableBasePlanListings();
final List<PlanDetailJson> details = new ArrayList<PlanDetailJson>();
for (final Listing listing : listings) {
details.add(new PlanDetailJson(listing));
}
return Response.status(Status.OK).entity(details).build();
}
use of org.killbill.billing.catalog.api.StaticCatalog in project killbill by killbill.
the class DefaultInternalBillingApi method getBillingEventsForAccountAndUpdateAccountBCD.
@Override
public BillingEventSet getBillingEventsForAccountAndUpdateAccountBCD(final UUID accountId, final DryRunArguments dryRunArguments, final InternalCallContext context) throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
final StaticCatalog currentCatalog = catalogService.getCurrentCatalog(true, true, context);
// Check to see if billing is off for the account
final List<Tag> accountTags = tagApi.getTags(accountId, ObjectType.ACCOUNT, context);
final boolean found_AUTO_INVOICING_OFF = is_AUTO_INVOICING_OFF(accountTags);
final Set<UUID> skippedSubscriptions = new HashSet<UUID>();
final DefaultBillingEventSet result;
if (found_AUTO_INVOICING_OFF) {
// billing is off, we are done
result = new DefaultBillingEventSet(true, currentCatalog.getRecurringBillingMode());
} else {
final List<SubscriptionBaseBundle> bundles = subscriptionApi.getBundlesForAccount(accountId, context);
final ImmutableAccountData account = accountApi.getImmutableAccountDataById(accountId, context);
result = new DefaultBillingEventSet(false, currentCatalog.getRecurringBillingMode());
addBillingEventsForBundles(bundles, account, dryRunArguments, context, result, skippedSubscriptions);
}
if (result.isEmpty()) {
log.info("No billing event for accountId='{}'", accountId);
return result;
}
// Pretty-print the events, before and after the blocking calculator does its magic
final StringBuilder logStringBuilder = new StringBuilder("Computed billing events for accountId='").append(accountId).append("'");
eventsToString(logStringBuilder, result);
if (blockCalculator.insertBlockingEvents(result, skippedSubscriptions, context)) {
logStringBuilder.append("\nBilling Events After Blocking");
eventsToString(logStringBuilder, result);
}
log.info(logStringBuilder.toString());
return result;
}
Aggregations