@Test public void shouldCreditCardRegister() throws IOException, ParseException { HttpResponse response = new HttpResponse(200, responseAsString); when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenReturn(response); CreditCard creditCard = getCreditCard(); TransactionDetail transactionDetail = directPaymentRegisterResource.withCreditCard(creditCard); assertTransaction(transactionDetail); }
public TransactionDetail withCreditCard(CreditCard creditCard) { LOGGER.info("Iniciando pagamento direto com cartao de credito"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.CREDIT_CARD.getName()); map.putMap(CREDIT_CARD_MC.convert(creditCard)); 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 cartao de credito"); 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 cartao de credito finalizado"); return transaction; }
DirectPaymentRegisterResource { public TransactionDetail withCreditCard(CreditCard creditCard) { LOGGER.info("Iniciando pagamento direto com cartao de credito"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.CREDIT_CARD.getName()); map.putMap(CREDIT_CARD_MC.convert(creditCard)); 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 cartao de credito"); 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 cartao de credito finalizado"); return transaction; } }
DirectPaymentRegisterResource { public TransactionDetail withCreditCard(CreditCard creditCard) { LOGGER.info("Iniciando pagamento direto com cartao de credito"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.CREDIT_CARD.getName()); map.putMap(CREDIT_CARD_MC.convert(creditCard)); 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 cartao de credito"); 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 cartao de credito finalizado"); return transaction; } DirectPaymentRegisterResource(PagSeguro pagSeguro,
                                       HttpClient httpClient,
                                       DirectPaymentRegistration directPaymentRegistration); }
DirectPaymentRegisterResource { public TransactionDetail withCreditCard(CreditCard creditCard) { LOGGER.info("Iniciando pagamento direto com cartao de credito"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.CREDIT_CARD.getName()); map.putMap(CREDIT_CARD_MC.convert(creditCard)); 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 cartao de credito"); 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 cartao de credito 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 withCreditCard(CreditCard creditCard) { LOGGER.info("Iniciando pagamento direto com cartao de credito"); LOGGER.info("Convertendo valores"); final RequestMap map = DIRECT_PAYMENT_REGISTRATION_MC.convert(directPaymentRegistration); map.putString("paymentMethod", TransactionMethod.PaymentMethod.CREDIT_CARD.getName()); map.putMap(CREDIT_CARD_MC.convert(creditCard)); 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 cartao de credito"); 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 cartao de credito 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);  }