@Test public void shouldSearch() throws Exception { String responseAsString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<transaction>\n" + " <reference>reference</reference>\n" + " <date>2016-11-09T00:00:00.000-02:00</date>\n" + " <items>\n" + " <item>\n" + " <id>0001</id>\n" + " <description>description</description>\n" + " <quantity>1</quantity>\n" + " <amount>9.99</amount>\n" + " </item>\n" + " </items>\n" + " <status>INITIATED</status>\n" + " <type>CHECKOUT</type>\n" + " <code>code2</code>\n" + " <itemCount>1</itemCount>\n" + " <installmentCount>1</installmentCount>\n" + " <sender>\n" + " <name>sender name</name>\n" + " <email>email</email>\n" + " <phone>\n" + " <areaCode>99</areaCode>\n" + " <number>123456789</number>\n" + " </phone>\n" + " </sender>\n" + " <shipping>\n" + " <address>\n" + " <street>street</street>\n" + " <number>9</number>\n" + " <complement>complement</complement>\n" + " <district>district</district>\n" + " <city>city</city>\n" + " <state>SP</state>\n" + " <country>country</country>\n" + " <postalCode>12345678</postalCode>\n" + " </address>\n" + " <type>1</type>\n" + " <cost>9.99</cost>\n" + " </shipping>\n" + " <lastEventDate>2016-11-09T23:59:59.000-02:00</lastEventDate>\n" + " <paymentMethod>\n" + " <type>1</type>\n" + " <code>101</code>\n" + " </paymentMethod>\n" + " <grossAmount>9.99</grossAmount>\n" + " <discountAmount>9.99</discountAmount>\n" + " <feeAmount>9.99</feeAmount>\n" + " <netAmount>9.99</netAmount>\n" + " <extraAmount>9.99</extraAmount>\n" + " <escrowEndDate>2016-11-09T01:01:01.000-02:00</escrowEndDate>\n" + "</transaction>"; HttpResponse response = new HttpResponse(200, responseAsString); when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenReturn(response); TransactionDetail transactionDetail = transactionSearchByNotification.execute(pagSeguro, httpClient); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); assertEquals("reference", transactionDetail.getReference()); assertEquals(dateFormat.parse("2016-11-09 00:00:00"), transactionDetail.getDate()); PaymentItem item = transactionDetail.getItems().iterator().next(); assertEquals("0001", item.getId()); assertEquals("description", item.getDescription()); assertEquals(new Integer(1), item.getQuantity()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), item.getAmount()); assertEquals(TransactionStatus.Status.UNRECOGNIZED, transactionDetail.getStatus().getStatus()); assertEquals(TransactionType.Type.UNRECOGNIZED, transactionDetail.getType().getType()); assertEquals("code2", transactionDetail.getCode()); assertEquals("sender name", transactionDetail.getSender().getName()); assertEquals("email", transactionDetail.getSender().getEmail()); assertEquals("99", transactionDetail.getSender().getPhone().getAreaCode()); assertEquals("123456789", transactionDetail.getSender().getPhone().getNumber()); assertEquals("street", transactionDetail.getShipping().getAddress().getStreet()); assertEquals("9", transactionDetail.getShipping().getAddress().getNumber()); assertEquals("complement", transactionDetail.getShipping().getAddress().getComplement()); assertEquals("district", transactionDetail.getShipping().getAddress().getDistrict()); assertEquals("city", transactionDetail.getShipping().getAddress().getCity()); assertEquals("SP", transactionDetail.getShipping().getAddress().getState()); assertEquals("country", transactionDetail.getShipping().getAddress().getCountry()); assertEquals("12345678", transactionDetail.getShipping().getAddress().getPostalCode()); assertEquals(ShippingType.Type.PAC, transactionDetail.getShipping().getShippingType().getType()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), transactionDetail.getShipping().getCost()); assertEquals(dateFormat.parse("2016-11-09 23:59:59"), transactionDetail.getLastEvent()); assertEquals(TransactionPaymentMethod.Type.CREDIT_CARD, transactionDetail.getPaymentMethod().getType()); assertEquals(TransactionPaymentMethod.Code.VISA, transactionDetail.getPaymentMethod().getCode()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), transactionDetail.getGrossAmount()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), transactionDetail.getDiscountAmount()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), transactionDetail.getFeeAmount()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), transactionDetail.getNetAmount()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), transactionDetail.getExtraAmount()); assertEquals(dateFormat.parse("2016-11-09 01:01:01"), transactionDetail.getEscrowEndDate()); }
@Override public TransactionDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagseguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por codigo de notificacao finalizada"); return transaction; }
TransactionSearchByNotification implements PagSeguroCommand<TransactionDetail> { @Override public TransactionDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagseguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por codigo de notificacao finalizada"); return transaction; } }
TransactionSearchByNotification implements PagSeguroCommand<TransactionDetail> { @Override public TransactionDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagseguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por codigo de notificacao finalizada"); return transaction; } TransactionSearchByNotification(String notificationCode); }
TransactionSearchByNotification implements PagSeguroCommand<TransactionDetail> { @Override public TransactionDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagseguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por codigo de notificacao finalizada"); return transaction; } TransactionSearchByNotification(String notificationCode); @Override TransactionDetail execute(PagSeguro pagseguro, HttpClient httpClient); }
TransactionSearchByNotification implements PagSeguroCommand<TransactionDetail> { @Override public TransactionDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); TransactionDetail transaction = response.parseXMLContent(pagseguro, TransactionDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por codigo de notificacao finalizada"); return transaction; } TransactionSearchByNotification(String notificationCode); @Override TransactionDetail execute(PagSeguro pagseguro, HttpClient httpClient);  }