use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class TenantResource method insertUserKeyValue.
@TimedResource
@POST
@Path("/" + USER_KEY_VALUE + "/{keyName:" + ANYTHING_PATTERN + "}")
@Consumes(TEXT_PLAIN)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a per tenant user key/value")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tenantId supplied") })
public Response insertUserKeyValue(@PathParam("keyName") final String key, final String value, @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 TenantApiException {
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
tenantApi.addTenantKeyValue(key, value, callContext);
return uriBuilder.buildResponse(uriInfo, TenantResource.class, "getUserKeyValue", key, request);
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class TransactionResource method notifyStateChanged.
@TimedResource
@POST
@Path("/{transactionId:" + UUID_PATTERN + "}/")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Mark a pending payment transaction as succeeded or failed")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid paymentId supplied"), @ApiResponse(code = 404, message = "Account or Payment not found") })
public Response notifyStateChanged(final PaymentTransactionJson json, @PathParam("transactionId") final String transactionIdStr, @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 {
verifyNonNullOrEmpty(json, "PaymentTransactionJson body should be specified");
verifyNonNullOrEmpty(json.getPaymentId(), "PaymentTransactionJson paymentId needs to be set", json.getStatus(), "PaymentTransactionJson status needs to be set");
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final UUID paymentId = UUID.fromString(json.getPaymentId());
final Payment payment = paymentApi.getPayment(paymentId, false, false, ImmutableList.<PluginProperty>of(), callContext);
final Account account = accountUserApi.getAccountById(payment.getAccountId(), callContext);
final boolean success = TransactionStatus.SUCCESS.name().equals(json.getStatus());
final Payment result = paymentApi.notifyPendingTransactionOfStateChanged(account, UUID.fromString(transactionIdStr), success, callContext);
return uriBuilder.buildResponse(uriInfo, PaymentResource.class, "getPayment", result.getId(), request);
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class TransactionResource method getPaymentByTransactionId.
@TimedResource(name = "getPaymentByTransactionId")
@GET
@Path("/{transactionId:" + UUID_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment by transaction id", response = PaymentJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Payment not found") })
public Response getPaymentByTransactionId(@PathParam("transactionId") final String transactionIdStr, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final UUID transactionIdId = UUID.fromString(transactionIdStr);
final TenantContext tenantContext = context.createContext(request);
final Payment payment = paymentApi.getPaymentByTransactionId(transactionIdId, withPluginInfo, withAttempts, pluginProperties, tenantContext);
final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext);
final PaymentJson result = new PaymentJson(payment, accountAuditLogs);
return Response.status(Response.Status.OK).entity(result).build();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class UsageResource method recordUsage.
@TimedResource
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Record usage for a subscription")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid subscription (e.g. inactive)") })
public Response recordUsage(final SubscriptionUsageRecordJson json, @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 EntitlementApiException, AccountApiException, UsageApiException {
verifyNonNullOrEmpty(json, "SubscriptionUsageRecordJson body should be specified");
verifyNonNullOrEmpty(json.getSubscriptionId(), "SubscriptionUsageRecordJson subscriptionId needs to be set", json.getUnitUsageRecords(), "SubscriptionUsageRecordJson unitUsageRecords needs to be set");
Preconditions.checkArgument(!json.getUnitUsageRecords().isEmpty());
for (final UnitUsageRecordJson unitUsageRecordJson : json.getUnitUsageRecords()) {
verifyNonNullOrEmpty(unitUsageRecordJson.getUnitType(), "UnitUsageRecordJson unitType need to be set");
Preconditions.checkArgument(Iterables.size(unitUsageRecordJson.getUsageRecords()) > 0, "UnitUsageRecordJson usageRecords must have at least one element.");
for (final UsageRecordJson usageRecordJson : unitUsageRecordJson.getUsageRecords()) {
verifyNonNull(usageRecordJson.getAmount(), "UsageRecordJson amount needs to be set");
verifyNonNull(usageRecordJson.getRecordDate(), "UsageRecordJson recordDate needs to be set");
}
}
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
// Verify subscription exists..
final Entitlement entitlement = entitlementApi.getEntitlementForId(UUID.fromString(json.getSubscriptionId()), callContext);
if (entitlement.getState() != EntitlementState.ACTIVE) {
return Response.status(Status.BAD_REQUEST).build();
}
final SubscriptionUsageRecord record = json.toSubscriptionUsageRecord();
usageUserApi.recordRolledUpUsage(record, callContext);
return Response.status(Status.CREATED).build();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class InvoicePaymentResource method createChargeback.
@TimedResource
@POST
@Path("/{paymentId:" + UUID_PATTERN + "}/" + CHARGEBACKS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Record a chargeback")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid payment id supplied"), @ApiResponse(code = 404, message = "Account or payment not found") })
public Response createChargeback(final InvoicePaymentTransactionJson json, @PathParam("paymentId") final String paymentId, @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 {
verifyNonNullOrEmpty(json, "InvoicePaymentTransactionJson body should be specified");
verifyNonNullOrEmpty(json.getAmount(), "InvoicePaymentTransactionJson amount needs to be set");
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final UUID paymentUuid = UUID.fromString(paymentId);
final Payment payment = paymentApi.getPayment(paymentUuid, false, false, ImmutableList.<PluginProperty>of(), callContext);
final Account account = accountUserApi.getAccountById(payment.getAccountId(), callContext);
final String transactionExternalKey = json.getTransactionExternalKey() != null ? json.getTransactionExternalKey() : UUIDs.randomUUID().toString();
final Payment result = paymentApi.createChargebackWithPaymentControl(account, payment.getId(), json.getAmount(), account.getCurrency(), transactionExternalKey, createInvoicePaymentControlPluginApiPaymentOptions(false), callContext);
return uriBuilder.buildResponse(uriInfo, InvoicePaymentResource.class, "getInvoicePayment", result.getId(), request);
}
Aggregations