@GET @Path("/{paymentId:" + UUID_PATTERN + "}/" + REFUNDS) @Produces(APPLICATION_JSON) public Response getRefunds(@PathParam("paymentId") final String paymentId, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final List<Refund> refunds = paymentApi.getPaymentRefunds(UUID.fromString(paymentId), context.createContext(request)); final List<RefundJson> result = new ArrayList<RefundJson>(Collections2.transform(refunds, new Function<Refund, RefundJson>() { @Override public RefundJson apply(final Refund input) { // TODO Return adjusted items and audits return new RefundJson(input, null, null); } })); return Response.status(Status.OK).entity(result).build(); }
@GET @Path("/{paymentId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) public Response getPayment(@PathParam(ID_PARAM_NAME) final String paymentIdString, @QueryParam(QUERY_PAYMENT_WITH_REFUNDS_AND_CHARGEBACKS) @DefaultValue("false") final Boolean withRefundsAndChargebacks, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final TenantContext tenantContext = context.createContext(request); final UUID paymentId = UUID.fromString(paymentIdString); final Payment payment = paymentApi.getPayment(paymentId, false, tenantContext); final PaymentJson paymentJson; if (withRefundsAndChargebacks) { final List<RefundJson> refunds = new ArrayList<RefundJson>(); for (final Refund refund : paymentApi.getPaymentRefunds(paymentId, tenantContext)) { refunds.add(new RefundJson(refund)); } final List<ChargebackJson> chargebacks = new ArrayList<ChargebackJson>(); for (final InvoicePayment chargeback : invoicePaymentApi.getChargebacksByPaymentId(paymentId, tenantContext)) { chargebacks.add(new ChargebackJson(payment.getAccountId(), chargeback)); } paymentJson = new PaymentJson(payment, null, // TODO - the keys are really only used for the timeline refunds, chargebacks); } else { paymentJson = new PaymentJson(payment, null); } return Response.status(Status.OK).entity(paymentJson).build(); }