Search in sources :

Example 21 with PUT

use of javax.ws.rs.PUT in project killbill by killbill.

the class AdminResource method updatePaymentTransactionState.

@PUT
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("/payments/{paymentId:" + UUID_PATTERN + "}/transactions/{paymentTransactionId:" + UUID_PATTERN + "}")
@ApiOperation(value = "Update existing paymentTransaction and associated payment state")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account data supplied") })
public Response updatePaymentTransactionState(final AdminPaymentJson json, @PathParam("paymentId") final String paymentIdStr, @PathParam("paymentTransactionId") final String paymentTransactionIdStr, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final Payment payment = paymentApi.getPayment(UUID.fromString(paymentIdStr), false, false, ImmutableList.<PluginProperty>of(), callContext);
    final UUID paymentTransactionId = UUID.fromString(paymentTransactionIdStr);
    final PaymentTransaction paymentTransaction = Iterables.tryFind(payment.getTransactions(), new Predicate<PaymentTransaction>() {

        @Override
        public boolean apply(final PaymentTransaction input) {
            return input.getId().equals(paymentTransactionId);
        }
    }).orNull();
    adminPaymentApi.fixPaymentTransactionState(payment, paymentTransaction, TransactionStatus.valueOf(json.getTransactionStatus()), json.getLastSuccessPaymentState(), json.getCurrentPaymentStateName(), ImmutableList.<PluginProperty>of(), callContext);
    return Response.status(Status.OK).build();
}
Also used : PaymentTransaction(org.killbill.billing.payment.api.PaymentTransaction) Payment(org.killbill.billing.payment.api.Payment) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) Predicate(com.google.common.base.Predicate) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 22 with PUT

use of javax.ws.rs.PUT in project killbill by killbill.

the class BundleResource method transferBundle.

@TimedResource
@PUT
@Path("/{bundleId:" + UUID_PATTERN + "}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Transfer a bundle to another account")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid bundle id, requested date or policy supplied"), @ApiResponse(code = 404, message = "Bundle not found") })
public Response transferBundle(final BundleJson json, @PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_BILLING_POLICY) @DefaultValue("END_OF_TERM") final String policyString, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final UriInfo uriInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException, SubscriptionApiException, AccountApiException {
    verifyNonNullOrEmpty(json, "BundleJson body should be specified");
    verifyNonNullOrEmpty(json.getAccountId(), "BundleJson accountId needs to be set");
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final BillingActionPolicy policy = BillingActionPolicy.valueOf(policyString.toUpperCase());
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID bundleId = UUID.fromString(id);
    final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, callContext);
    final LocalDate inputLocalDate = toLocalDate(requestedDate);
    final UUID newBundleId = entitlementApi.transferEntitlementsOverrideBillingPolicy(bundle.getAccountId(), UUID.fromString(json.getAccountId()), bundle.getExternalKey(), inputLocalDate, policy, pluginProperties, callContext);
    return uriBuilder.buildResponse(uriInfo, BundleResource.class, "getBundle", newBundleId, request);
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) SubscriptionBundle(org.killbill.billing.entitlement.api.SubscriptionBundle) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) LocalDate(org.joda.time.LocalDate) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 23 with PUT

use of javax.ws.rs.PUT in project killbill by killbill.

the class BundleResource method pauseBundle.

@TimedResource
@PUT
@Path("/{bundleId:" + UUID_PATTERN + "}/" + PAUSE)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Pause a bundle")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid bundle id supplied"), @ApiResponse(code = 404, message = "Bundle not found") })
public Response pauseBundle(@PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, EntitlementApiException, AccountApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID bundleId = UUID.fromString(id);
    final LocalDate inputLocalDate = toLocalDate(requestedDate);
    entitlementApi.pause(bundleId, inputLocalDate, pluginProperties, callContext);
    return Response.status(Status.OK).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) LocalDate(org.joda.time.LocalDate) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 24 with PUT

use of javax.ws.rs.PUT in project killbill by killbill.

the class SubscriptionResource method updateSubscriptionBCD.

@TimedResource
@PUT
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/{subscriptionId:" + UUID_PATTERN + "}/" + BCD)
@ApiOperation(value = "Update the BCD associated to a subscription")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid entitlement supplied") })
public Response updateSubscriptionBCD(final SubscriptionJson json, @PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_ENTITLEMENT_EFFECTIVE_FROM_DT) final String effectiveFromDateStr, @QueryParam(QUERY_FORCE_NEW_BCD_WITH_PAST_EFFECTIVE_DATE) @DefaultValue("false") final Boolean forceNewBcdWithPastEffectiveDate, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final UriInfo uriInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, EntitlementApiException, AccountApiException {
    verifyNonNullOrEmpty(json, "SubscriptionJson body should be specified");
    verifyNonNullOrEmpty(json.getBillCycleDayLocal(), "SubscriptionJson new BCD should be specified");
    LocalDate effectiveFromDate = toLocalDate(effectiveFromDateStr);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID subscriptionId = UUID.fromString(id);
    final Entitlement entitlement = entitlementApi.getEntitlementForId(subscriptionId, callContext);
    if (effectiveFromDateStr != null) {
        final Account account = accountUserApi.getAccountById(entitlement.getAccountId(), callContext);
        final LocalDate accountToday = new LocalDate(clock.getUTCNow(), account.getTimeZone());
        int comp = effectiveFromDate.compareTo(accountToday);
        switch(comp) {
            case -1:
                if (!forceNewBcdWithPastEffectiveDate) {
                    throw new IllegalArgumentException("Changing a subscription BCD in the past may have consequences on previous invoice generated. Use flag forceNewBcdWithPastEffectiveDate to force this behavior");
                }
                break;
            case 0:
                // Ensure system will use curremt time for the event so it happens immediately
                effectiveFromDate = null;
                break;
            case 1:
                // Future date, normal case where such effectiveFromDateStr is being passed
                break;
        }
    }
    entitlement.updateBCD(json.getBillCycleDayLocal(), effectiveFromDate, callContext);
    return Response.status(Status.OK).build();
}
Also used : Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 25 with PUT

use of javax.ws.rs.PUT in project killbill by killbill.

the class SubscriptionResource method changeEntitlementPlan.

@TimedResource
@PUT
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/{subscriptionId:" + UUID_PATTERN + "}")
@ApiOperation(value = "Change entitlement plan")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Entitlement not found") })
public Response changeEntitlementPlan(final SubscriptionJson entitlement, @PathParam("subscriptionId") final String subscriptionId, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_CALL_COMPLETION) @DefaultValue("false") final Boolean callCompletion, @QueryParam(QUERY_CALL_TIMEOUT) @DefaultValue("3") final long timeoutSec, @QueryParam(QUERY_BILLING_POLICY) final String policyString, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException, AccountApiException, SubscriptionApiException {
    verifyNonNullOrEmpty(entitlement, "SubscriptionJson body should be specified");
    if (entitlement.getPlanName() == null) {
        verifyNonNullOrEmpty(entitlement.getProductName(), "SubscriptionJson productName needs to be set", entitlement.getBillingPeriod(), "SubscriptionJson billingPeriod needs to be set", entitlement.getPriceList(), "SubscriptionJson priceList needs to be set");
    }
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final EntitlementCallCompletionCallback<Response> callback = new EntitlementCallCompletionCallback<Response>() {

        private boolean isImmediateOp = true;

        @Override
        public Response doOperation(final CallContext ctx) throws EntitlementApiException, InterruptedException, TimeoutException, AccountApiException {
            final UUID uuid = UUID.fromString(subscriptionId);
            final Entitlement current = entitlementApi.getEntitlementForId(uuid, callContext);
            final LocalDate inputLocalDate = toLocalDate(requestedDate);
            final Entitlement newEntitlement;
            final Account account = accountUserApi.getAccountById(current.getAccountId(), callContext);
            final PlanSpecifier planSpec = entitlement.getPlanName() != null ? new PlanSpecifier(entitlement.getPlanName()) : new PlanSpecifier(entitlement.getProductName(), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList());
            final List<PlanPhasePriceOverride> overrides = PhasePriceOverrideJson.toPlanPhasePriceOverrides(entitlement.getPriceOverrides(), planSpec, account.getCurrency());
            if (requestedDate == null && policyString == null) {
                newEntitlement = current.changePlan(planSpec, overrides, pluginProperties, ctx);
            } else if (policyString == null) {
                newEntitlement = current.changePlanWithDate(planSpec, overrides, inputLocalDate, pluginProperties, ctx);
            } else {
                final BillingActionPolicy policy = BillingActionPolicy.valueOf(policyString.toUpperCase());
                newEntitlement = current.changePlanOverrideBillingPolicy(planSpec, overrides, inputLocalDate, policy, pluginProperties, ctx);
            }
            isImmediateOp = newEntitlement.getLastActiveProduct().getName().equals(entitlement.getProductName()) && newEntitlement.getLastActivePlan().getRecurringBillingPeriod() == BillingPeriod.valueOf(entitlement.getBillingPeriod()) && newEntitlement.getLastActivePriceList().getName().equals(entitlement.getPriceList());
            return Response.status(Status.OK).build();
        }

        @Override
        public boolean isImmOperation() {
            return isImmediateOp;
        }

        @Override
        public Response doResponseOk(final Response operationResponse) throws SubscriptionApiException, AccountApiException, CatalogApiException {
            if (operationResponse.getStatus() != Status.OK.getStatusCode()) {
                return operationResponse;
            }
            return getEntitlement(subscriptionId, new AuditMode(AuditLevel.NONE.toString()), request);
        }
    };
    final EntitlementCallCompletion<Response> callCompletionCreation = new EntitlementCallCompletion<Response>();
    return callCompletionCreation.withSynchronization(callback, timeoutSec, callCompletion, callContext);
}
Also used : Account(org.killbill.billing.account.api.Account) BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) CallContext(org.killbill.billing.util.callcontext.CallContext) LocalDate(org.joda.time.LocalDate) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) PluginProperty(org.killbill.billing.payment.api.PluginProperty) UUID(java.util.UUID) Entitlement(org.killbill.billing.entitlement.api.Entitlement) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11