Source:
<code>public Response submitRefund(@Parameter(hidden = true) @ApiParam(value = "accountId", hidden = true) @Auth Account account, @ApiParam(value = "paymentId", required = true) @PathParam(PATH_PAYMENT_KEY) String paymentId, @Parameter(required = true, description = "requestPayload") @ApiParam(value = "requestPayload", required = true) CreatePaymentRefundRequest requestPayload) { logger.info("Create a refund for payment request - paymentId={}", paymentId); Integer refundAmountAvailable = requestPayload.getRefundAmountAvailable() .orElseGet(() -> { Charge charge = connectorService.getCharge(account, paymentId); <START> return Long.valueOf(charge.getRefundSummary().getAmountAvailable()).intValue(); <END> }); 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, account.getAccountId(), 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).build(); } throw new CreateRefundException(connectorResponse); }</code><technical_language>Charge appears getRefundSummary() return null end NPE. want add some protection charge received Connector a refund_summary</technical_language>

Target:
public Response submitRefund(@Parameter(hidden = true) @ApiParam(value = "accountId", hidden = true) @Auth Account account, @ApiParam(value = "paymentId", required = true) @PathParam(PATH_PAYMENT_KEY) String paymentId, @Parameter(required = true, description = "requestPayload") @ApiParam(value = "requestPayload", required = true) CreatePaymentRefundRequest requestPayload) { logger.info("Create a refund for payment request - paymentId={}", paymentId); Integer refundAmountAvailable = requestPayload.getRefundAmountAvailable() .orElseGet(() -> Optional.ofNullable(connectorService.getCharge(account, paymentId)) .map(Charge::getRefundSummary) .map(RefundSummary::getAmountAvailable) .map(Long::intValue) .orElse(0)); 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, account.getAccountId(), 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).build(); } throw new CreateRefundException(connectorResponse); }