Search in sources :

Example 1 with PhaseJson

use of org.killbill.billing.jaxrs.json.CatalogJson.PhaseJson in project killbill by killbill.

the class CatalogResource method getPhaseForSubscriptionAndDate.

@TimedResource
@GET
@Path("/phase")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve phase for a given subscription and date", response = PhaseJson.class)
@ApiResponses(value = {})
public Response getPhaseForSubscriptionAndDate(@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 PlanPhase phase = lastEventBeforeRequestedDate.getNextPhase();
    if (phase == 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 PhaseJson phaseJson = new PhaseJson(phase);
    return Response.status(Status.OK).entity(phaseJson).build();
}
Also used : SubscriptionEvent(org.killbill.billing.entitlement.api.SubscriptionEvent) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) PhaseJson(org.killbill.billing.jaxrs.json.CatalogJson.PhaseJson) 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

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)1 SubscriptionEvent (org.killbill.billing.entitlement.api.SubscriptionEvent)1 PhaseJson (org.killbill.billing.jaxrs.json.CatalogJson.PhaseJson)1 TimedResource (org.killbill.commons.metrics.TimedResource)1