Search in sources :

Example 96 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class AccountResource method processPayment.

@TimedResource(name = "processPayment")
@POST
@Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENTS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Trigger a payment (authorization, purchase or credit)")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Payment transaction created successfully"), @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found"), @ApiResponse(code = 402, message = "Transaction declined by gateway"), @ApiResponse(code = 422, message = "Payment is aborted by a control plugin"), @ApiResponse(code = 502, message = "Failed to submit payment transaction"), @ApiResponse(code = 503, message = "Payment in unknown status, failed to receive gateway response"), @ApiResponse(code = 504, message = "Payment operation timeout") })
public Response processPayment(@MetricTag(tag = "type", property = "transactionType") final PaymentTransactionJson json, @PathParam(QUERY_ACCOUNT_ID) final String accountIdStr, @QueryParam(QUERY_PAYMENT_METHOD_ID) final String paymentMethodIdStr, @QueryParam(QUERY_PAYMENT_CONTROL_PLUGIN_NAME) final List<String> paymentControlPluginNames, @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 PaymentApiException, AccountApiException {
    final UUID accountId = UUID.fromString(accountIdStr);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final Account account = accountUserApi.getAccountById(accountId, callContext);
    return processPayment(json, account, paymentMethodIdStr, paymentControlPluginNames, pluginPropertiesString, uriInfo, callContext, request);
}
Also used : Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 97 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class AccountResource method getBlockingStates.

/*
     * *************************      BLOCKING STATE     *****************************
     */
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + BLOCK)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve blocking states for account", response = BlockingStateJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied") })
public Response getBlockingStates(@PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_BLOCKING_STATE_TYPES) final List<BlockingStateType> typeFilter, @QueryParam(QUERY_BLOCKING_STATE_SVCS) final List<String> svcsFilter, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException {
    final TenantContext tenantContext = this.context.createContext(request);
    final UUID accountId = UUID.fromString(id);
    final Iterable<BlockingState> blockingStates = subscriptionApi.getBlockingStates(accountId, typeFilter, svcsFilter, OrderingType.ASCENDING, SubscriptionApi.ALL_EVENTS, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext);
    final List<BlockingStateJson> result = ImmutableList.copyOf(Iterables.transform(blockingStates, new Function<BlockingState, BlockingStateJson>() {

        @Override
        public BlockingStateJson apply(final BlockingState input) {
            return new BlockingStateJson(input, accountAuditLogs);
        }
    }));
    return Response.status(Status.OK).entity(result).build();
}
Also used : Function(com.google.common.base.Function) TenantContext(org.killbill.billing.util.callcontext.TenantContext) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) BlockingStateJson(org.killbill.billing.jaxrs.json.BlockingStateJson) 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 98 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class AccountResource method transferChildCreditToParent.

@TimedResource
@POST
@Path("/{childAccountId:" + UUID_PATTERN + "}/" + TRANSFER_CREDIT)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Move a given child credit to the parent level")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Account does not have credit"), @ApiResponse(code = 404, message = "Account not found") })
public Response transferChildCreditToParent(@PathParam("childAccountId") final String childAccountIdString, @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, @javax.ws.rs.core.Context final UriInfo uriInfo) throws InvoiceApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID childAccountId = UUID.fromString(childAccountIdString);
    invoiceApi.transferChildCreditToParent(childAccountId, callContext);
    return Response.status(Response.Status.OK).build();
}
Also used : UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 99 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class AccountResource method processPaymentByExternalKey.

@TimedResource(name = "processPayment")
@POST
@Path("/" + PAYMENTS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Trigger a payment using the account external key (authorization, purchase or credit)")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Payment transaction created successfully"), @ApiResponse(code = 400, message = "Invalid account external key supplied"), @ApiResponse(code = 404, message = "Account not found"), @ApiResponse(code = 402, message = "Transaction declined by gateway"), @ApiResponse(code = 422, message = "Payment is aborted by a control plugin"), @ApiResponse(code = 502, message = "Failed to submit payment transaction"), @ApiResponse(code = 503, message = "Payment in unknown status, failed to receive gateway response"), @ApiResponse(code = 504, message = "Payment operation timeout") })
public Response processPaymentByExternalKey(@MetricTag(tag = "type", property = "transactionType") final PaymentTransactionJson json, @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_PAYMENT_METHOD_ID) final String paymentMethodIdStr, @QueryParam(QUERY_PAYMENT_CONTROL_PLUGIN_NAME) final List<String> paymentControlPluginNames, @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 PaymentApiException, AccountApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final Account account = accountUserApi.getAccountByKey(externalKey, callContext);
    return processPayment(json, account, paymentMethodIdStr, paymentControlPluginNames, pluginPropertiesString, uriInfo, callContext, request);
}
Also used : Account(org.killbill.billing.account.api.Account) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 100 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class AccountResource method addEmail.

@TimedResource
@POST
@Path("/{accountId:" + UUID_PATTERN + "}/" + EMAILS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add account email")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response addEmail(final AccountEmailJson json, @PathParam(ID_PARAM_NAME) final String id, @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, @javax.ws.rs.core.Context final UriInfo uriInfo) throws AccountApiException {
    verifyNonNullOrEmpty(json, "AccountEmailJson body should be specified");
    verifyNonNullOrEmpty(json.getEmail(), "AccountEmailJson email needs to be set");
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID accountId = UUID.fromString(id);
    // Make sure the account exist or we will confuse the history and auditing code
    accountUserApi.getAccountById(accountId, callContext);
    // Make sure the email doesn't exist
    final AccountEmail existingEmail = Iterables.<AccountEmail>tryFind(accountUserApi.getEmails(accountId, callContext), new Predicate<AccountEmail>() {

        @Override
        public boolean apply(final AccountEmail input) {
            return input.getEmail().equals(json.getEmail());
        }
    }).orNull();
    if (existingEmail == null) {
        accountUserApi.addEmail(accountId, json.toAccountEmail(UUIDs.randomUUID()), callContext);
    }
    return uriBuilder.buildResponse(uriInfo, AccountResource.class, "getEmails", json.getAccountId(), request);
}
Also used : AccountEmail(org.killbill.billing.account.api.AccountEmail) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) Predicate(com.google.common.base.Predicate) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)112 TimedResource (org.killbill.commons.metrics.TimedResource)112 ApiResponses (io.swagger.annotations.ApiResponses)111 Produces (javax.ws.rs.Produces)109 Path (javax.ws.rs.Path)95 UUID (java.util.UUID)59 GET (javax.ws.rs.GET)58 TenantContext (org.killbill.billing.util.callcontext.TenantContext)54 Consumes (javax.ws.rs.Consumes)48 CallContext (org.killbill.billing.util.callcontext.CallContext)48 Account (org.killbill.billing.account.api.Account)47 POST (javax.ws.rs.POST)36 PluginProperty (org.killbill.billing.payment.api.PluginProperty)35 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)31 Payment (org.killbill.billing.payment.api.Payment)19 LocalDate (org.joda.time.LocalDate)16 URI (java.net.URI)15 Invoice (org.killbill.billing.invoice.api.Invoice)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)11