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);
}
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();
}
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();
}
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);
}
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);
}
Aggregations