Search in sources :

Example 66 with CallContext

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

the class AccountResource method refreshPaymentMethods.

@TimedResource
@POST
@Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS + "/refresh")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Refresh account payment methods")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response refreshPaymentMethods(@PathParam("accountId") final String accountId, @QueryParam(QUERY_PAYMENT_PLUGIN_NAME) final String pluginName, @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 HttpServletRequest request) throws AccountApiException, PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), callContext);
    if (pluginName != null && !pluginName.isEmpty()) {
        paymentApi.refreshPaymentMethods(account, pluginName, pluginProperties, callContext);
    } else {
        paymentApi.refreshPaymentMethods(account, pluginProperties, callContext);
    }
    return Response.status(Status.OK).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) 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) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 67 with CallContext

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

the class AccountResource method setDefaultPaymentMethod.

@TimedResource
@PUT
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS + "/{paymentMethodId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS_DEFAULT_PATH_POSTFIX)
@ApiOperation(value = "Set the default payment method")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id or payment method id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response setDefaultPaymentMethod(@PathParam("accountId") final String accountId, @PathParam("paymentMethodId") final String paymentMethodId, @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 HttpServletRequest request) throws AccountApiException, PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), callContext);
    final UUID newPaymentMethodId = UUID.fromString(paymentMethodId);
    paymentApi.setDefaultPaymentMethod(account, newPaymentMethodId, pluginProperties, callContext);
    if (payAllUnpaidInvoices) {
        final Collection<Invoice> unpaidInvoices = invoiceApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext);
        for (final Invoice invoice : unpaidInvoices) {
            createPurchaseForInvoice(account, invoice.getId(), invoice.getBalance(), newPaymentMethodId, false, null, null, pluginProperties, callContext);
        }
    }
    return Response.status(Status.OK).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 68 with CallContext

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

the class AccountResource method rebalanceExistingCBAOnAccount.

/*
     * ************************** INVOICE CBA REBALANCING ********************************
     */
@TimedResource
@POST
@Path("/{accountId:" + UUID_PATTERN + "}/" + CBA_REBALANCING)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Rebalance account CBA")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied") })
public Response rebalanceExistingCBAOnAccount(@PathParam("accountId") final String accountIdString, @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 AccountApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID accountId = UUID.fromString(accountIdString);
    invoiceApi.consumeExstingCBAOnAccountWithUnpaidInvoices(accountId, callContext);
    return Response.status(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 69 with CallContext

use of org.killbill.billing.util.callcontext.CallContext 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 70 with CallContext

use of org.killbill.billing.util.callcontext.CallContext 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)

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