Search in sources :

Example 6 with InvoicePaymentJson

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();
}
Also used : Function(com.google.common.base.Function) InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) Payment(org.killbill.billing.payment.api.Payment) Invoice(org.killbill.billing.invoice.api.Invoice) InvoicePaymentJson(org.killbill.billing.jaxrs.json.InvoicePaymentJson) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) UUID(java.util.UUID) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 UUID (java.util.UUID)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 InvoicePayment (org.killbill.billing.invoice.api.InvoicePayment)6 InvoicePaymentJson (org.killbill.billing.jaxrs.json.InvoicePaymentJson)6 Payment (org.killbill.billing.payment.api.Payment)6 TenantContext (org.killbill.billing.util.callcontext.TenantContext)6 TimedResource (org.killbill.commons.metrics.TimedResource)6 ArrayList (java.util.ArrayList)4 PluginProperty (org.killbill.billing.payment.api.PluginProperty)4 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)4 Function (com.google.common.base.Function)2 Predicate (com.google.common.base.Predicate)2 Account (org.killbill.billing.account.api.Account)2 Invoice (org.killbill.billing.invoice.api.Invoice)2 HashSet (java.util.HashSet)1