Search in sources :

Example 41 with CallContext

use of org.killbill.billing.util.callcontext.CallContext 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);
}
Also used : CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) 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 42 with CallContext

use of org.killbill.billing.util.callcontext.CallContext 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);
}
Also used : Account(org.killbill.billing.account.api.Account) Payment(org.killbill.billing.payment.api.Payment) 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 43 with CallContext

use of org.killbill.billing.util.callcontext.CallContext 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();
}
Also used : UnitUsageRecordJson(org.killbill.billing.jaxrs.json.SubscriptionUsageRecordJson.UnitUsageRecordJson) UnitUsageRecordJson(org.killbill.billing.jaxrs.json.SubscriptionUsageRecordJson.UnitUsageRecordJson) UsageRecordJson(org.killbill.billing.jaxrs.json.SubscriptionUsageRecordJson.UsageRecordJson) SubscriptionUsageRecordJson(org.killbill.billing.jaxrs.json.SubscriptionUsageRecordJson) Entitlement(org.killbill.billing.entitlement.api.Entitlement) SubscriptionUsageRecord(org.killbill.billing.usage.api.SubscriptionUsageRecord) CallContext(org.killbill.billing.util.callcontext.CallContext) 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 44 with CallContext

use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.

the class Context method createContext.

public CallContext createContext(final String createdBy, final String reason, final String comment, final ServletRequest request) throws IllegalArgumentException {
    try {
        Preconditions.checkNotNull(createdBy, String.format("Header %s needs to be set", JaxrsResource.HDR_CREATED_BY));
        final Tenant tenant = getTenantFromRequest(request);
        final CallContext callContext = contextFactory.createCallContext(tenant == null ? null : tenant.getId(), createdBy, origin, userType, reason, comment, getOrCreateUserToken());
        populateMDCContext(callContext);
        return callContext;
    } catch (final NullPointerException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : Tenant(org.killbill.billing.tenant.api.Tenant) CallContext(org.killbill.billing.util.callcontext.CallContext)

Example 45 with CallContext

use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.

the class DefaultEntitlementService method initialize.

@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE)
public void initialize() {
    try {
        final NotificationQueueHandler queueHandler = new NotificationQueueHandler() {

            @Override
            public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) {
                final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "EntitlementQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken);
                if (inputKey instanceof EntitlementNotificationKey) {
                    final CallContext callContext = internalCallContextFactory.createCallContext(internalCallContext);
                    processEntitlementNotification((EntitlementNotificationKey) inputKey, internalCallContext, callContext);
                } else if (inputKey instanceof BlockingTransitionNotificationKey) {
                    processBlockingNotification((BlockingTransitionNotificationKey) inputKey, internalCallContext);
                } else if (inputKey != null) {
                    log.error("Entitlement service received an unexpected event className='{}", inputKey.getClass());
                } else {
                    log.error("Entitlement service received an unexpected null event");
                }
            }
        };
        entitlementEventQueue = notificationQueueService.createNotificationQueue(ENTITLEMENT_SERVICE_NAME, NOTIFICATION_QUEUE_NAME, queueHandler);
    } catch (final NotificationQueueAlreadyExists e) {
        throw new RuntimeException(e);
    }
}
Also used : EntitlementNotificationKey(org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey) BlockingTransitionNotificationKey(org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) NotificationQueueAlreadyExists(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) DateTime(org.joda.time.DateTime) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Aggregations

CallContext (org.killbill.billing.util.callcontext.CallContext)82 ApiOperation (io.swagger.annotations.ApiOperation)51 ApiResponses (io.swagger.annotations.ApiResponses)51 Produces (javax.ws.rs.Produces)48 TimedResource (org.killbill.commons.metrics.TimedResource)48 Consumes (javax.ws.rs.Consumes)47 Path (javax.ws.rs.Path)43 UUID (java.util.UUID)40 Account (org.killbill.billing.account.api.Account)38 POST (javax.ws.rs.POST)35 PluginProperty (org.killbill.billing.payment.api.PluginProperty)29 LocalDate (org.joda.time.LocalDate)16 Payment (org.killbill.billing.payment.api.Payment)15 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)14 DefaultCallContext (org.killbill.billing.callcontext.DefaultCallContext)11 Invoice (org.killbill.billing.invoice.api.Invoice)10 PaymentOptions (org.killbill.billing.payment.api.PaymentOptions)10 PUT (javax.ws.rs.PUT)9 Entitlement (org.killbill.billing.entitlement.api.Entitlement)9 DELETE (javax.ws.rs.DELETE)7