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