/* * ************************** REFUNDS ******************************** */ @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + REFUNDS) @Produces(APPLICATION_JSON) public Response getRefunds( @PathParam("accountId") final String accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException { final TenantContext tenantContext = context.createContext(request); final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), tenantContext); final List<Refund> refunds = paymentApi.getAccountRefunds(account, tenantContext); final List<RefundJson> result = new ArrayList<RefundJson>( Collections2.transform( refunds, new Function<Refund, RefundJson>() { @Override public RefundJson apply(Refund input) { // TODO Return adjusted items and audits return new RefundJson(input, null, null); } })); return Response.status(Status.OK).entity(result).build(); }
@GET @Path("/{accountId:" + UUID_PATTERN + "}/" + TIMELINE) @Produces(APPLICATION_JSON) public Response getAccountTimeline( @PathParam("accountId") final String accountIdString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException, SubscriptionApiException { final TenantContext tenantContext = context.createContext(request); final UUID accountId = UUID.fromString(accountIdString); final Account account = accountUserApi.getAccountById(accountId, tenantContext); // Get the invoices final List<Invoice> invoices = invoiceApi.getInvoicesByAccount(account.getId(), tenantContext); final AuditLogsForInvoices invoicesAuditLogs = auditUserApi.getAuditLogsForInvoices(invoices, auditMode.getLevel(), tenantContext); // Get the payments final List<Payment> payments = paymentApi.getAccountPayments(accountId, tenantContext); final AuditLogsForPayments paymentsAuditLogs = auditUserApi.getAuditLogsForPayments(payments, auditMode.getLevel(), tenantContext); // Get the refunds final List<Refund> refunds = paymentApi.getAccountRefunds(account, tenantContext); final AuditLogsForRefunds refundsAuditLogs = auditUserApi.getAuditLogsForRefunds(refunds, auditMode.getLevel(), tenantContext); final Multimap<UUID, Refund> refundsByPayment = ArrayListMultimap.<UUID, Refund>create(); for (final Refund refund : refunds) { refundsByPayment.put(refund.getPaymentId(), refund); } // Get the chargebacks final List<InvoicePayment> chargebacks = invoicePaymentApi.getChargebacksByAccountId(accountId, tenantContext); final AuditLogsForInvoicePayments chargebacksAuditLogs = auditUserApi.getAuditLogsForInvoicePayments( chargebacks, auditMode.getLevel(), tenantContext); final Multimap<UUID, InvoicePayment> chargebacksByPayment = ArrayListMultimap.<UUID, InvoicePayment>create(); for (final InvoicePayment chargeback : chargebacks) { chargebacksByPayment.put(chargeback.getPaymentId(), chargeback); } // Get the bundles final List<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundlesForAccountId(account.getId(), tenantContext); final AuditLogsForBundles bundlesAuditLogs = auditUserApi.getAuditLogsForBundles(bundles, auditMode.getLevel(), tenantContext); final AccountTimelineJson json = new AccountTimelineJson( account, invoices, payments, bundles, refundsByPayment, chargebacksByPayment, invoicesAuditLogs, paymentsAuditLogs, refundsAuditLogs, chargebacksAuditLogs, bundlesAuditLogs); return Response.status(Status.OK).entity(json).build(); }