@Test(expectedExceptions = IllegalArgumentException.class) public void testRefundChargeInvalidChargeId() throws BaseException { Charge expectedCharge = new Charge.Builder() .amount(new BigDecimal(1234)) .context(new PaymentContext.Builder().mobile("false").isEcommerce("true").build()) .build(); RequestContext requestContext = new RequestContext(); requestContext.setBaseUrl("SomeBaseUrl"); ChargeService chargeService = new ChargeService(requestContext); Capture captureChargeRequest = new Capture.Builder() .amount(expectedCharge.getAmount()) .context(expectedCharge.getContext()) .build(); Refund actualRefund = chargeService.refund(null, null); }
public Refund refund(String chargeId, Refund refund) throws BaseException { logger.debug("Enter ChargeService::refund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(refund) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Refund refundResponse = (Refund) response.getResponseObject(); prepareResponse(request, response, refundResponse); return refundResponse; }
ChargeService extends ServiceBase { public Refund refund(String chargeId, Refund refund) throws BaseException { logger.debug("Enter ChargeService::refund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(refund) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Refund refundResponse = (Refund) response.getResponseObject(); prepareResponse(request, response, refundResponse); return refundResponse; } }
ChargeService extends ServiceBase { public Refund refund(String chargeId, Refund refund) throws BaseException { logger.debug("Enter ChargeService::refund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(refund) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Refund refundResponse = (Refund) response.getResponseObject(); prepareResponse(request, response, refundResponse); return refundResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); }
ChargeService extends ServiceBase { public Refund refund(String chargeId, Refund refund) throws BaseException { logger.debug("Enter ChargeService::refund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(refund) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Refund refundResponse = (Refund) response.getResponseObject(); prepareResponse(request, response, refundResponse); return refundResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); Charge create(Charge charge); Charge retrieve(String chargeId); Charge capture(String chargeId, Capture capture); Refund refund(String chargeId, Refund refund); Refund getRefund(String chargeId, String refundId); Refund voidTransaction(String chargeRequestId); }
ChargeService extends ServiceBase { public Refund refund(String chargeId, Refund refund) throws BaseException { logger.debug("Enter ChargeService::refund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(refund) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Refund refundResponse = (Refund) response.getResponseObject(); prepareResponse(request, response, refundResponse); return refundResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); Charge create(Charge charge); Charge retrieve(String chargeId); Charge capture(String chargeId, Capture capture); Refund refund(String chargeId, Refund refund); Refund getRefund(String chargeId, String refundId); Refund voidTransaction(String chargeRequestId);  }