use of org.killbill.billing.jaxrs.json.PaymentMethodJson in project killbill by killbill.
the class PaymentMethodResource method searchPaymentMethods.
@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search payment methods", response = PaymentMethodJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchPaymentMethods(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_PAYMENT_METHOD_PLUGIN_NAME) final String pluginName, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException, AccountApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final TenantContext tenantContext = context.createContext(request);
// Search the plugin(s)
final Pagination<PaymentMethod> paymentMethods;
if (Strings.isNullOrEmpty(pluginName)) {
paymentMethods = paymentApi.searchPaymentMethods(searchKey, offset, limit, withPluginInfo, pluginProperties, tenantContext);
} else {
paymentMethods = paymentApi.searchPaymentMethods(searchKey, offset, limit, pluginName, withPluginInfo, pluginProperties, tenantContext);
}
final URI nextPageUri = uriBuilder.nextPage(PaymentMethodResource.class, "searchPaymentMethods", paymentMethods.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString()));
final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
final Map<UUID, Account> accounts = new HashMap<UUID, Account>();
return buildStreamingPaginationResponse(paymentMethods, new Function<PaymentMethod, PaymentMethodJson>() {
@Override
public PaymentMethodJson apply(final PaymentMethod paymentMethod) {
// Cache audit logs per account
if (accountsAuditLogs.get().get(paymentMethod.getAccountId()) == null) {
accountsAuditLogs.get().put(paymentMethod.getAccountId(), auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext));
}
// Lookup the associated account(s)
if (accounts.get(paymentMethod.getAccountId()) == null) {
final Account account;
try {
account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext);
accounts.put(paymentMethod.getAccountId(), account);
} catch (final AccountApiException e) {
log.warn("Error retrieving accountId='{}'", paymentMethod.getAccountId(), e);
return null;
}
}
return PaymentMethodJson.toPaymentMethodJson(accounts.get(paymentMethod.getAccountId()), paymentMethod, accountsAuditLogs.get().get(paymentMethod.getAccountId()));
}
}, nextPageUri);
}
use of org.killbill.billing.jaxrs.json.PaymentMethodJson in project killbill by killbill.
the class PaymentMethodResource method getPaymentMethod.
@TimedResource(name = "getPaymentMethod")
@GET
@Path("/{paymentMethodId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment method by id", response = PaymentMethodJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid paymentMethodId supplied"), @ApiResponse(code = 404, message = "Account or payment method not found") })
public Response getPaymentMethod(@PathParam("paymentMethodId") final String paymentMethodId, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final TenantContext tenantContext = context.createContext(request);
final PaymentMethod paymentMethod = paymentApi.getPaymentMethodById(UUID.fromString(paymentMethodId), false, withPluginInfo, pluginProperties, tenantContext);
final Account account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext);
final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext);
final PaymentMethodJson json = PaymentMethodJson.toPaymentMethodJson(account, paymentMethod, accountAuditLogs);
return Response.status(Status.OK).entity(json).build();
}
use of org.killbill.billing.jaxrs.json.PaymentMethodJson in project killbill by killbill.
the class AccountResource method getPaymentMethods.
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account payment methods", response = PaymentMethodJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getPaymentMethods(@PathParam("accountId") final String accountId, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @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 AccountApiException, PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final TenantContext tenantContext = context.createContext(request);
final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), tenantContext);
final List<PaymentMethod> methods = paymentApi.getAccountPaymentMethods(account.getId(), withPluginInfo, pluginProperties, tenantContext);
final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext);
final List<PaymentMethodJson> json = new ArrayList<PaymentMethodJson>(Collections2.transform(methods, new Function<PaymentMethod, PaymentMethodJson>() {
@Override
public PaymentMethodJson apply(final PaymentMethod input) {
return PaymentMethodJson.toPaymentMethodJson(account, input, accountAuditLogs);
}
}));
return Response.status(Status.OK).entity(json).build();
}
use of org.killbill.billing.jaxrs.json.PaymentMethodJson in project killbill by killbill.
the class PaymentMethodResource method getPaymentMethods.
@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List payment methods", response = PaymentMethodJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getPaymentMethods(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_PAYMENT_METHOD_PLUGIN_NAME) final String pluginName, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final TenantContext tenantContext = context.createContext(request);
final Pagination<PaymentMethod> paymentMethods;
if (Strings.isNullOrEmpty(pluginName)) {
paymentMethods = paymentApi.getPaymentMethods(offset, limit, withPluginInfo, pluginProperties, tenantContext);
} else {
paymentMethods = paymentApi.getPaymentMethods(offset, limit, pluginName, withPluginInfo, pluginProperties, tenantContext);
}
final URI nextPageUri = uriBuilder.nextPage(PaymentMethodResource.class, "getPaymentMethods", paymentMethods.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString()));
final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
final Map<UUID, Account> accounts = new HashMap<UUID, Account>();
return buildStreamingPaginationResponse(paymentMethods, new Function<PaymentMethod, PaymentMethodJson>() {
@Override
public PaymentMethodJson apply(final PaymentMethod paymentMethod) {
// Cache audit logs per account
if (accountsAuditLogs.get().get(paymentMethod.getAccountId()) == null) {
accountsAuditLogs.get().put(paymentMethod.getAccountId(), auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext));
}
// Lookup the associated account(s)
if (accounts.get(paymentMethod.getAccountId()) == null) {
final Account account;
try {
account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext);
accounts.put(paymentMethod.getAccountId(), account);
} catch (final AccountApiException e) {
log.warn("Error retrieving accountId='{}'", paymentMethod.getAccountId(), e);
return null;
}
}
return PaymentMethodJson.toPaymentMethodJson(accounts.get(paymentMethod.getAccountId()), paymentMethod, accountsAuditLogs.get().get(paymentMethod.getAccountId()));
}
}, nextPageUri);
}
use of org.killbill.billing.jaxrs.json.PaymentMethodJson in project killbill by killbill.
the class PaymentMethodResource method getPaymentMethodByKey.
@TimedResource(name = "getPaymentMethod")
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment method by external key", response = PaymentMethodJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Account or payment method not found") })
public Response getPaymentMethodByKey(@QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final TenantContext tenantContext = context.createContext(request);
final PaymentMethod paymentMethod = paymentApi.getPaymentMethodByExternalKey(externalKey, false, withPluginInfo, pluginProperties, tenantContext);
final Account account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext);
final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext);
final PaymentMethodJson json = PaymentMethodJson.toPaymentMethodJson(account, paymentMethod, accountAuditLogs);
return Response.status(Status.OK).entity(json).build();
}
Aggregations