Search in sources :

Example 6 with SubscriptionEvent

use of org.killbill.billing.entitlement.api.SubscriptionEvent in project killbill by killbill.

the class CatalogResource method getPlanForSubscriptionAndDate.

@TimedResource
@GET
@Path("/plan")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve plan for a given subscription and date", response = PlanJson.class)
@ApiResponses(value = {})
public Response getPlanForSubscriptionAndDate(@QueryParam("subscriptionId") final UUID subscriptionId, @QueryParam("requestedDate") final String requestedDateString, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, CurrencyValueNull {
    verifyNonNullOrEmpty(subscriptionId, "Subscription id needs to be specified");
    final SubscriptionEvent lastEventBeforeRequestedDate = getLastEventBeforeDate(subscriptionId, requestedDateString, request);
    if (lastEventBeforeRequestedDate == null) {
        return Response.status(Status.BAD_REQUEST).entity(String.format("%s is before the subscription start date", requestedDateString)).type("text/plain").build();
    }
    final Plan plan = lastEventBeforeRequestedDate.getNextPlan();
    if (plan == null) {
        // Subscription was cancelled at that point
        return Response.status(Status.BAD_REQUEST).entity(String.format("%s is after the subscription cancel date", requestedDateString)).type("text/plain").build();
    }
    final PlanJson planJson = new PlanJson(plan);
    return Response.status(Status.OK).entity(planJson).build();
}
Also used : SubscriptionEvent(org.killbill.billing.entitlement.api.SubscriptionEvent) PlanJson(org.killbill.billing.jaxrs.json.CatalogJson.PlanJson) SimplePlanJson(org.killbill.billing.jaxrs.json.SimplePlanJson) Plan(org.killbill.billing.catalog.api.Plan) 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 7 with SubscriptionEvent

use of org.killbill.billing.entitlement.api.SubscriptionEvent in project killbill by killbill.

the class CatalogResource method getPriceListForSubscriptionAndDate.

@TimedResource
@GET
@Path("/priceList")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve priceList for a given subscription and date", response = PriceListJson.class)
@ApiResponses(value = {})
public Response getPriceListForSubscriptionAndDate(@QueryParam("subscriptionId") final UUID subscriptionId, @QueryParam("requestedDate") final String requestedDateString, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException {
    verifyNonNullOrEmpty(subscriptionId, "Subscription id needs to be specified");
    final SubscriptionEvent lastEventBeforeRequestedDate = getLastEventBeforeDate(subscriptionId, requestedDateString, request);
    if (lastEventBeforeRequestedDate == null) {
        return Response.status(Status.BAD_REQUEST).entity(String.format("%s is before the subscription start date", requestedDateString)).type("text/plain").build();
    }
    final PriceList priceList = lastEventBeforeRequestedDate.getNextPriceList();
    if (priceList == null) {
        // Subscription was cancelled at that point
        return Response.status(Status.BAD_REQUEST).entity(String.format("%s is after the subscription cancel date", requestedDateString)).type("text/plain").build();
    }
    final PriceListJson priceListJson = new PriceListJson(priceList);
    return Response.status(Status.OK).entity(priceListJson).build();
}
Also used : SubscriptionEvent(org.killbill.billing.entitlement.api.SubscriptionEvent) PriceListJson(org.killbill.billing.jaxrs.json.CatalogJson.PriceListJson) PriceList(org.killbill.billing.catalog.api.PriceList) 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)

Aggregations

SubscriptionEvent (org.killbill.billing.entitlement.api.SubscriptionEvent)7 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 TimedResource (org.killbill.commons.metrics.TimedResource)4 LocalDate (org.joda.time.LocalDate)3 Subscription (org.killbill.billing.entitlement.api.Subscription)3 BigDecimal (java.math.BigDecimal)2 UUID (java.util.UUID)2 Account (org.killbill.billing.account.api.Account)2 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)2 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)2 VersionedCatalog (org.killbill.billing.catalog.api.VersionedCatalog)2 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)2 Invoice (org.killbill.billing.invoice.api.Invoice)2 Test (org.testng.annotations.Test)2 DateTime (org.joda.time.DateTime)1 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)1