use of org.killbill.billing.jaxrs.json.InvoicePaymentJson in project killbill by killbill.
the class InvoiceResource method getPayments.
@TimedResource
@GET
@Path("/{invoiceId:" + UUID_PATTERN + "}/" + PAYMENTS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve payments associated with an invoice", response = InvoicePaymentJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid invoice id supplied"), @ApiResponse(code = 404, message = "Invoice not found") })
public Response getPayments(@PathParam("invoiceId") final String invoiceId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException, InvoiceApiException {
final TenantContext tenantContext = context.createContext(request);
final Invoice invoice = invoiceApi.getInvoice(UUID.fromString(invoiceId), tenantContext);
// Extract unique set of paymentId for this invoice
final Set<UUID> invoicePaymentIds = ImmutableSet.copyOf(Iterables.transform(invoice.getPayments(), new Function<InvoicePayment, UUID>() {
@Override
public UUID apply(final InvoicePayment input) {
return input.getPaymentId();
}
}));
if (invoicePaymentIds.isEmpty()) {
return Response.status(Status.OK).entity(ImmutableList.<InvoicePaymentJson>of()).build();
}
final List<Payment> payments = new ArrayList<Payment>();
for (final UUID paymentId : invoicePaymentIds) {
final Payment payment = paymentApi.getPayment(paymentId, withPluginInfo, withAttempts, ImmutableList.<PluginProperty>of(), tenantContext);
payments.add(payment);
}
final Iterable<InvoicePaymentJson> result = INVOICE_PAYMENT_ORDERING.sortedCopy(Iterables.transform(payments, new Function<Payment, InvoicePaymentJson>() {
@Override
public InvoicePaymentJson apply(final Payment input) {
return new InvoicePaymentJson(input, invoice.getId(), null);
}
}));
return Response.status(Status.OK).entity(result).build();
}
Aggregations