@Test(expected = PagSeguroLibException.class) public void shouldThrowsErrorLibOnRegister() throws Exception { when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenThrow(new IOException()); directPaymentRegisterResource.withBankSlip(); }
public TransactionDetail withBankSlip() { LOGGER.info("Iniciando pagamento direto com boleto"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.BANK_SLIP.getName()); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.DIRECT_PAYMENT, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar pagamento direto com boleto"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagSeguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Pagamento direto com boleto finalizado"); return transaction; }
DirectPaymentRegisterResource { public TransactionDetail withBankSlip() { LOGGER.info("Iniciando pagamento direto com boleto"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.BANK_SLIP.getName()); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.DIRECT_PAYMENT, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar pagamento direto com boleto"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagSeguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Pagamento direto com boleto finalizado"); return transaction; } }
DirectPaymentRegisterResource { public TransactionDetail withBankSlip() { LOGGER.info("Iniciando pagamento direto com boleto"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.BANK_SLIP.getName()); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.DIRECT_PAYMENT, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar pagamento direto com boleto"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagSeguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Pagamento direto com boleto finalizado"); return transaction; } DirectPaymentRegisterResource(PagSeguro pagSeguro,
                                       HttpClient httpClient,
                                       DirectPaymentRegistration directPaymentRegistration); }
DirectPaymentRegisterResource { public TransactionDetail withBankSlip() { LOGGER.info("Iniciando pagamento direto com boleto"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.BANK_SLIP.getName()); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.DIRECT_PAYMENT, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar pagamento direto com boleto"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagSeguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Pagamento direto com boleto finalizado"); return transaction; } DirectPaymentRegisterResource(PagSeguro pagSeguro,
                                       HttpClient httpClient,
                                       DirectPaymentRegistration directPaymentRegistration); TransactionDetail withBankSlip(); TransactionDetail withCreditCard(CreditCard creditCard); TransactionDetail withCreditCard(Builder<CreditCard> creditCardBuilder); TransactionDetail withOnlineDebit(Builder<Bank> bankBuilder); TransactionDetail withOnlineDebit(Bank bank); }
DirectPaymentRegisterResource { public TransactionDetail withBankSlip() { LOGGER.info("Iniciando pagamento direto com boleto"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.BANK_SLIP.getName()); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.POST, String.format(Endpoints.DIRECT_PAYMENT, pagSeguro.getHost()), null, map.toHttpRequestBody(CharSet.ENCODING_ISO)); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar pagamento direto com boleto"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagSeguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Pagamento direto com boleto finalizado"); return transaction; } DirectPaymentRegisterResource(PagSeguro pagSeguro,
                                       HttpClient httpClient,
                                       DirectPaymentRegistration directPaymentRegistration); TransactionDetail withBankSlip(); TransactionDetail withCreditCard(CreditCard creditCard); TransactionDetail withCreditCard(Builder<CreditCard> creditCardBuilder); TransactionDetail withOnlineDebit(Builder<Bank> bankBuilder); TransactionDetail withOnlineDebit(Bank bank);  }