@Test public void shouldThrowsBadRequestOnRefund() { try { String responseAsString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<errors>" + "<error>" + "<code>00001</code>" + "<message>Transaction code is required.</message>" + "</error>" + "</errors>"; HttpResponse response = new HttpResponse(400, responseAsString); when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenReturn(response); transactionsResource.refund(transactionIdentify, new BigDecimal(99.99)); } catch (PagSeguroBadRequestException e) { ServerErrors errors = e.getErrors(); ServerError error = errors.getErrors().iterator().next(); assertEquals(new Integer(00001), error.getCode()); assertEquals("Transaction code is required.", error.getMessage()); } catch (Exception e) { } }
public void refund(TransactionIdentify transactionIdentify, BigDecimal amount) { LOGGER.info("Iniciando estorno de transacao"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_IDENTIFY_MC.convert(transactionIdentify); map.putCurrency("refundValue", amount); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.TRANSACTION_REFUND, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar estorno de transacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); response.parseXMLContent(pagSeguro, RefundResponseXMLTransaction.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Estorno de transacao finalizado"); }
TransactionsResource { public void refund(TransactionIdentify transactionIdentify, BigDecimal amount) { LOGGER.info("Iniciando estorno de transacao"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_IDENTIFY_MC.convert(transactionIdentify); map.putCurrency("refundValue", amount); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.TRANSACTION_REFUND, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar estorno de transacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); response.parseXMLContent(pagSeguro, RefundResponseXMLTransaction.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Estorno de transacao finalizado"); } }
TransactionsResource { public void refund(TransactionIdentify transactionIdentify, BigDecimal amount) { LOGGER.info("Iniciando estorno de transacao"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_IDENTIFY_MC.convert(transactionIdentify); map.putCurrency("refundValue", amount); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.TRANSACTION_REFUND, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar estorno de transacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); response.parseXMLContent(pagSeguro, RefundResponseXMLTransaction.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Estorno de transacao finalizado"); } TransactionsResource(PagSeguro pagSeguro, HttpClient httpClient); }
TransactionsResource { public void refund(TransactionIdentify transactionIdentify, BigDecimal amount) { LOGGER.info("Iniciando estorno de transacao"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_IDENTIFY_MC.convert(transactionIdentify); map.putCurrency("refundValue", amount); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.TRANSACTION_REFUND, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar estorno de transacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); response.parseXMLContent(pagSeguro, RefundResponseXMLTransaction.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Estorno de transacao finalizado"); } TransactionsResource(PagSeguro pagSeguro, HttpClient httpClient); TransactionSearchResource search(); void cancel(TransactionIdentify transaction); void cancel(Builder<TransactionIdentify> transactionBuilder); void cancelByCode(String code); void refund(TransactionIdentify transactionIdentify, BigDecimal amount); void refund(TransactionIdentify transactionIdentify); void refund(Builder<TransactionIdentify> transactionIdentifyBuilder, BigDecimal amount); void refund(Builder<TransactionIdentify> transactionIdentifyBuilder); void refundByCode(String code); void refundByCode(String code, BigDecimal amount); DirectPaymentRegisterResource register(
      DirectPaymentRegistrationBuilder directPaymentRegistrationBuilder); DirectPaymentRegisterResource register(
      DirectPaymentRegistration directPaymentRegistration); }
TransactionsResource { public void refund(TransactionIdentify transactionIdentify, BigDecimal amount) { LOGGER.info("Iniciando estorno de transacao"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_IDENTIFY_MC.convert(transactionIdentify); map.putCurrency("refundValue", amount); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.TRANSACTION_REFUND, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar estorno de transacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); response.parseXMLContent(pagSeguro, RefundResponseXMLTransaction.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Estorno de transacao finalizado"); } TransactionsResource(PagSeguro pagSeguro, HttpClient httpClient); TransactionSearchResource search(); void cancel(TransactionIdentify transaction); void cancel(Builder<TransactionIdentify> transactionBuilder); void cancelByCode(String code); void refund(TransactionIdentify transactionIdentify, BigDecimal amount); void refund(TransactionIdentify transactionIdentify); void refund(Builder<TransactionIdentify> transactionIdentifyBuilder, BigDecimal amount); void refund(Builder<TransactionIdentify> transactionIdentifyBuilder); void refundByCode(String code); void refundByCode(String code, BigDecimal amount); DirectPaymentRegisterResource register(
      DirectPaymentRegistrationBuilder directPaymentRegistrationBuilder); DirectPaymentRegisterResource register(
      DirectPaymentRegistration directPaymentRegistration);  }