@Test public void testGetRefund() throws BaseException { Refund expectedRefund = new Refund.Builder() .amount(new BigDecimal(1234)) .description("SomeDescription") .context( new PaymentContext.Builder() .tax(new BigDecimal(5678)) .recurring(true) .deviceInfo( new DeviceInfo.Builder() .macAddress("SomeMacAddress") .ipAddress("SomeIpAddress") .longitude("SomeLongitude") .latitude("SomeLatitude") .phoneNumber("1800-FAKE-FAKE") .type("mobile") .build()) .build()) .id("ThisIsAGeneratedRefundId") .created(new Date(System.currentTimeMillis())) .build(); final String serializedResponseString = JsonUtil.serialize(expectedRefund); final Response mockedResponse = new Response(200, serializedResponseString, "some_intuit_tid"); mockedResponse.setResponseObject(expectedRefund); new Expectations() {{ serviceBase.sendRequest((Request) any); result = mockedResponse; }}; RequestContext requestContext = new RequestContext(); requestContext.setBaseUrl("SomeBaseUrl"); ChargeService chargeService = new ChargeService(requestContext); Refund actualRefund = chargeService.getRefund("SomeChargeId", "SomeRefundId"); Assert.assertEquals(expectedRefund.getId(), actualRefund.getId()); Assert.assertEquals(expectedRefund.getAmount(), actualRefund.getAmount()); Assert.assertEquals(expectedRefund.getDescription(), actualRefund.getDescription()); Assert.assertEquals(expectedRefund.getContext().getTax(), actualRefund.getContext().getTax()); Assert.assertEquals(expectedRefund.getContext().getRecurring(), actualRefund.getContext().getRecurring()); Assert.assertEquals(expectedRefund.getCreated(), actualRefund.getCreated()); }
public Refund getRefund(String chargeId, String refundId) throws BaseException { logger.debug("Enter ChargeService::getRefund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } if (StringUtils.isBlank(refundId)) { logger.error("IllegalArgumentException {}", refundId); throw new IllegalArgumentException("refundId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds/{refund_id}" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId.toString()) .replaceAll("\\{" + "refund_id" + "\\}", refundId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).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 getRefund(String chargeId, String refundId) throws BaseException { logger.debug("Enter ChargeService::getRefund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } if (StringUtils.isBlank(refundId)) { logger.error("IllegalArgumentException {}", refundId); throw new IllegalArgumentException("refundId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds/{refund_id}" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId.toString()) .replaceAll("\\{" + "refund_id" + "\\}", refundId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).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 getRefund(String chargeId, String refundId) throws BaseException { logger.debug("Enter ChargeService::getRefund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } if (StringUtils.isBlank(refundId)) { logger.error("IllegalArgumentException {}", refundId); throw new IllegalArgumentException("refundId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds/{refund_id}" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId.toString()) .replaceAll("\\{" + "refund_id" + "\\}", refundId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).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 getRefund(String chargeId, String refundId) throws BaseException { logger.debug("Enter ChargeService::getRefund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } if (StringUtils.isBlank(refundId)) { logger.error("IllegalArgumentException {}", refundId); throw new IllegalArgumentException("refundId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds/{refund_id}" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId.toString()) .replaceAll("\\{" + "refund_id" + "\\}", refundId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).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 getRefund(String chargeId, String refundId) throws BaseException { logger.debug("Enter ChargeService::getRefund"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } if (StringUtils.isBlank(refundId)) { logger.error("IllegalArgumentException {}", refundId); throw new IllegalArgumentException("refundId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}/refunds/{refund_id}" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", chargeId.toString()) .replaceAll("\\{" + "refund_id" + "\\}", refundId); logger.info("apiUrl - " + apiUrl); TypeReference<Refund> typeReference = new TypeReference<Refund>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).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);  }