@GET @Path("/{accountId:" + UUID_PATTERN + "}/" + CHARGEBACKS) @Produces(APPLICATION_JSON) public Response getChargebacksForAccount(@PathParam("accountId") final String accountIdStr, @javax.ws.rs.core.Context final HttpServletRequest request) { final UUID accountId = UUID.fromString(accountIdStr); final List<InvoicePayment> chargebacks = invoicePaymentApi.getChargebacksByAccountId(accountId, context.createContext(request)); final List<ChargebackJson> chargebacksJson = new ArrayList<ChargebackJson>(); for (final InvoicePayment chargeback : chargebacks) { chargebacksJson.add(new ChargebackJson(accountId, chargeback)); } return Response.status(Response.Status.OK).entity(chargebacksJson).build(); }
@POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) public Response createChargeback(final ChargebackJson json, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws InvoiceApiException { final CallContext callContext = context.createContext(createdBy, reason, comment, request); final InvoicePayment invoicePayment = invoicePaymentApi.getInvoicePaymentForAttempt(UUID.fromString(json.getPaymentId()), callContext); if (invoicePayment == null) { throw new InvoiceApiException(ErrorCode.INVOICE_PAYMENT_NOT_FOUND, json.getPaymentId()); } final InvoicePayment chargeBack = invoicePaymentApi.createChargeback(invoicePayment.getId(), json.getAmount(), callContext); return uriBuilder.buildResponse(uriInfo, ChargebackResource.class, "getChargeback", chargeBack.getId()); }
@Test(groups = "fast") public void testJson() throws Exception { final DateTime requestedDate = new DateTime(DateTimeZone.UTC); final DateTime effectiveDate = new DateTime(DateTimeZone.UTC); final BigDecimal chargebackAmount = BigDecimal.TEN; final String chargebackId = UUID.randomUUID().toString(); final String accountId = UUID.randomUUID().toString(); final String paymentId = UUID.randomUUID().toString(); final String currency = "USD"; final List<AuditLogJson> auditLogs = createAuditLogsJson(clock.getUTCNow()); final ChargebackJson chargebackJson = new ChargebackJson(chargebackId, accountId, requestedDate, effectiveDate, chargebackAmount, paymentId, currency, auditLogs); Assert.assertEquals(chargebackJson.getChargebackId(), chargebackId); Assert.assertEquals(chargebackJson.getRequestedDate(), requestedDate); Assert.assertEquals(chargebackJson.getEffectiveDate(), effectiveDate); Assert.assertEquals(chargebackJson.getAmount(), chargebackAmount); Assert.assertEquals(chargebackJson.getPaymentId(), paymentId); Assert.assertEquals(chargebackJson.getAuditLogs(), auditLogs); final String asJson = mapper.writeValueAsString(chargebackJson); final ChargebackJson fromJson = mapper.readValue(asJson, ChargebackJson.class); Assert.assertEquals(fromJson, chargebackJson); } }
public ChargebackJson(final UUID accountId, final InvoicePayment chargeback, @Nullable final List<AuditLog> auditLogs) { this(chargeback.getId().toString(), accountId.toString(), chargeback.getPaymentDate(), chargeback.getPaymentDate(), chargeback.getAmount().negate(), chargeback.getPaymentId().toString(), chargeback.getCurrency().toString(), toAuditLogJson(auditLogs)); }
@GET @Path("/{chargebackId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) public Response getChargeback(@PathParam("chargebackId") final String chargebackId, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException { final TenantContext tenantContext = context.createContext(request); final InvoicePayment chargeback = invoicePaymentApi.getChargebackById(UUID.fromString(chargebackId), tenantContext); final UUID accountId = invoicePaymentApi.getAccountIdFromInvoicePaymentId(chargeback.getId(), tenantContext); final ChargebackJson chargebackJson = new ChargebackJson(accountId, chargeback); return Response.status(Response.Status.OK).entity(chargebackJson).build(); }
@GET @Path("/{paymentId:" + UUID_PATTERN + "}/" + CHARGEBACKS) @Produces(APPLICATION_JSON) public Response getChargebacksForPayment(@PathParam("paymentId") final String paymentId, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException { final TenantContext tenantContext = context.createContext(request); final List<InvoicePayment> chargebacks = invoicePaymentApi.getChargebacksByPaymentId(UUID.fromString(paymentId), tenantContext); if (chargebacks.size() == 0) { return Response.status(Response.Status.NO_CONTENT).build(); } final UUID invoicePaymentId = chargebacks.get(0).getId(); final UUID accountId = invoicePaymentApi.getAccountIdFromInvoicePaymentId(invoicePaymentId, tenantContext); final List<ChargebackJson> chargebacksJson = new ArrayList<ChargebackJson>(); for (final InvoicePayment chargeback : chargebacks) { chargebacksJson.add(new ChargebackJson(accountId, chargeback)); } return Response.status(Response.Status.OK).entity(chargebacksJson).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(); }
for (final InvoicePayment chargeback : chargebacksByPayment.get(payment.getId())) { final List<AuditLog> auditLogs = accountAuditLogs.getAuditLogsForChargeback(chargeback.getId()); chargebacks.add(new ChargebackJson(payment.getAccountId(), chargeback, auditLogs));