Search in sources :

Example 1 with StaticCatalog

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());
    }
}
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 2 with StaticCatalog

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);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) Invoice(org.killbill.billing.invoice.api.Invoice) ArrayList(java.util.ArrayList) Plan(org.killbill.billing.catalog.api.Plan) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) BigDecimal(java.math.BigDecimal) Entitlement(org.killbill.billing.entitlement.api.Entitlement) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) Test(org.testng.annotations.Test)

Example 3 with StaticCatalog

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();
}
Also used : PlanDetailJson(org.killbill.billing.jaxrs.json.PlanDetailJson) Listing(org.killbill.billing.catalog.api.Listing) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with StaticCatalog

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();
}
Also used : PlanDetailJson(org.killbill.billing.jaxrs.json.PlanDetailJson) Listing(org.killbill.billing.catalog.api.Listing) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with StaticCatalog

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;
}
Also used : ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) HashSet(java.util.HashSet)

Aggregations

StaticCatalog (org.killbill.billing.catalog.api.StaticCatalog)14 Test (org.testng.annotations.Test)9 SimplePlanDescriptor (org.killbill.billing.catalog.api.SimplePlanDescriptor)7 DefaultSimplePlanDescriptor (org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor)7 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)5 Entitlement (org.killbill.billing.entitlement.api.Entitlement)5 ArrayList (java.util.ArrayList)4 LocalDate (org.joda.time.LocalDate)4 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)4 BigDecimal (java.math.BigDecimal)3 PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)2 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2 Listing (org.killbill.billing.catalog.api.Listing)2 Subscription (org.killbill.billing.entitlement.api.Subscription)2