Source:
public Response submitRefund(@ApiParam(value = "accountId", hidden = true) @Auth String accountId, @ApiParam(value = "paymentId", required = true) @PathParam(PATH_PAYMENT_KEY) String paymentId, @ApiParam(value = "requestPayload", required = true) CreatePaymentRefundRequest requestPayload) { logger.info("Create a refund for payment request - paymentId={}", paymentId); Integer refundAmountAvailable = requestPayload.getRefundAmountAvailable(); if (refundAmountAvailable == null) { Response getChargeResponse = client .target(getConnectorUrl(format(CONNECTOR_CHARGE_RESOURCE, accountId, paymentId))) .request() .get(); ChargeFromResponse chargeFromResponse = getChargeResponse.readEntity(ChargeFromResponse.class); refundAmountAvailable = Long.valueOf(chargeFromResponse.getRefundSummary().getAmountAvailable()).intValue(); } ImmutableMap<String, Object> payloadMap = ImmutableMap.of("amount", requestPayload.getAmount(), "refund_amount_available", refundAmountAvailable); String connectorPayload = new GsonBuilder().create().toJson( payloadMap); Response connectorResponse = client .target(getConnectorUrl(format(CONNECTOR_CHARGE_REFUNDS_RESOURCE, accountId, paymentId))) .request() .post(json(connectorPayload)); if (connectorResponse.getStatus() == ACCEPTED.getStatusCode()) { RefundFromConnector refundFromConnector = connectorResponse.readEntity(RefundFromConnector.class); logger.debug("created refund returned - [ ]", refundFromConnector); RefundResponse refundResponse = RefundResponse.valueOf(refundFromConnector, paymentId, baseUrl); return Response.accepted(refundResponse.serialize()).build(); } throw new CreateRefundException(connectorResponse); }

Target:
public Response submitRefund(@ApiParam(value = "accountId", hidden = true) @Auth String accountId, @ApiParam(value = "paymentId", required = true) @PathParam(PATH_PAYMENT_KEY) String paymentId, @ApiParam(value = "requestPayload", required = true) CreatePaymentRefundRequest requestPayload) { logger.info("Create a refund for payment request - paymentId={}", paymentId); Integer refundAmountAvailable = requestPayload.getRefundAmountAvailable() .orElseGet(() -> { Response getChargeResponse = client .target(getConnectorUrl(format(CONNECTOR_CHARGE_RESOURCE, accountId, paymentId))) .request() .get(); ChargeFromResponse chargeFromResponse = getChargeResponse.readEntity(ChargeFromResponse.class); return Long.valueOf(chargeFromResponse.getRefundSummary().getAmountAvailable()).intValue(); }); ImmutableMap<String, Object> payloadMap = ImmutableMap.of("amount", requestPayload.getAmount(), "refund_amount_available", refundAmountAvailable); String connectorPayload = new GsonBuilder().create().toJson( payloadMap); Response connectorResponse = client .target(getConnectorUrl(format(CONNECTOR_CHARGE_REFUNDS_RESOURCE, accountId, paymentId))) .request() .post(json(connectorPayload)); if (connectorResponse.getStatus() == ACCEPTED.getStatusCode()) { RefundFromConnector refundFromConnector = connectorResponse.readEntity(RefundFromConnector.class); logger.debug("created refund returned - [ ]", refundFromConnector); RefundResponse refundResponse = RefundResponse.valueOf(refundFromConnector, paymentId, baseUrl); return Response.accepted(refundResponse.serialize()).build(); } throw new CreateRefundException(connectorResponse); }