Search in sources :

Example 76 with CallContext

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

the class TenantResource method deleteTenantKey.

private Response deleteTenantKey(final TenantKey key, @Nullable final String keyPostfix, final String createdBy, final String reason, final String comment, final HttpServletRequest request) throws TenantApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final String tenantKey = keyPostfix != null ? key.toString() + keyPostfix : key.toString();
    tenantApi.deleteTenantKey(tenantKey, callContext);
    return Response.status(Status.OK).build();
}
Also used : CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext)

Example 77 with CallContext

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

the class TenantResource method createTenant.

@TimedResource
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Create a tenant")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Tenant already exists") })
public Response createTenant(final TenantJson json, @QueryParam(QUERY_TENANT_USE_GLOBAL_DEFAULT) @DefaultValue("true") final Boolean useGlobalDefault, @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, CatalogApiException {
    verifyNonNullOrEmpty(json, "TenantJson body should be specified");
    verifyNonNullOrEmpty(json.getApiKey(), "TenantJson apiKey needs to be set", json.getApiSecret(), "TenantJson apiSecret needs to be set");
    final TenantData data = json.toTenantData();
    final Tenant tenant = tenantApi.createTenant(data, context.createContext(createdBy, reason, comment, request));
    if (!useGlobalDefault) {
        final CallContext callContext = new DefaultCallContext(tenant.getId(), createdBy, CallOrigin.EXTERNAL, UserType.CUSTOMER, Context.getOrCreateUserToken(), clock);
        catalogUserApi.createDefaultEmptyCatalog(clock.getUTCNow(), callContext);
    }
    return uriBuilder.buildResponse(uriInfo, TenantResource.class, "getTenant", tenant.getId(), request);
}
Also used : Tenant(org.killbill.billing.tenant.api.Tenant) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) TenantData(org.killbill.billing.tenant.api.TenantData) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) 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 78 with CallContext

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

the class TenantResource method deleteUserKeyValue.

@TimedResource
@DELETE
@Path("/" + USER_KEY_VALUE + "/{keyName:" + ANYTHING_PATTERN + "}")
@ApiOperation(value = "Delete  a per tenant user key/value")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tenantId supplied") })
public Response deleteUserKeyValue(@PathParam("keyName") final String key, @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 TenantApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    tenantApi.deleteTenantKey(key, callContext);
    return Response.status(Status.OK).build();
}
Also used : CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) TimedResource(org.killbill.commons.metrics.TimedResource) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 79 with CallContext

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

the class AccountResource method createPaymentMethod.

@TimedResource
@POST
@Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a payment method")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response createPaymentMethod(final PaymentMethodJson json, @PathParam("accountId") final String accountId, @QueryParam(QUERY_PAYMENT_METHOD_IS_DEFAULT) @DefaultValue("false") final Boolean isDefault, @QueryParam(QUERY_PAY_ALL_UNPAID_INVOICES) @DefaultValue("false") final Boolean payAllUnpaidInvoices, @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 AccountApiException, PaymentApiException {
    verifyNonNullOrEmpty(json, "PaymentMethodJson body should be specified");
    verifyNonNullOrEmpty(json.getPluginName(), "PaymentMethodJson pluginName should be specified");
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final PaymentMethod data = json.toPaymentMethod(accountId);
    final Account account = accountUserApi.getAccountById(data.getAccountId(), callContext);
    final boolean hasDefaultPaymentMethod = account.getPaymentMethodId() != null || isDefault;
    final Collection<Invoice> unpaidInvoices = payAllUnpaidInvoices ? invoiceApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext) : Collections.<Invoice>emptyList();
    if (payAllUnpaidInvoices && unpaidInvoices.size() > 0 && !hasDefaultPaymentMethod) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    final UUID paymentMethodId = paymentApi.addPaymentMethod(account, data.getExternalKey(), data.getPluginName(), isDefault, data.getPluginDetail(), pluginProperties, callContext);
    if (payAllUnpaidInvoices && unpaidInvoices.size() > 0) {
        for (final Invoice invoice : unpaidInvoices) {
            createPurchaseForInvoice(account, invoice.getId(), invoice.getBalance(), paymentMethodId, false, null, null, pluginProperties, callContext);
        }
    }
    return uriBuilder.buildResponse(uriInfo, PaymentMethodResource.class, "getPaymentMethod", paymentMethodId, request);
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) 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 80 with CallContext

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

the class CatalogResource method uploadCatalogXml.

@TimedResource
@POST
@Consumes(APPLICATION_XML)
@ApiOperation(value = "Upload the full catalog as XML")
@ApiResponses(value = {})
public Response uploadCatalogXml(final String catalogXML, @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 Exception {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    catalogUserApi.uploadCatalog(catalogXML, callContext);
    return uriBuilder.buildResponse(uriInfo, CatalogResource.class, null, null, request);
}
Also used : CallContext(org.killbill.billing.util.callcontext.CallContext) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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