Repository: andreroggeri/pynubank

Issue:
Texto "Comentário" da Transação PIX
O texto comentário que pode ser escrito pelo pagador durante uma transação pix não é retornado no método `nu.get_account_feed()`. Seria possível incluir?

Discussion:
roarena: @andreroggeri acho que a classe Nubank ficou muito grande com essa mudança, talvez seja a hora de um refactor, ou jogar os métodos helpers para uma classe "utils" o que acha?
O codeclimate está reclamando do número de linhas ![sad](https://media.giphy.com/media/7SF5scGB2AFrgsXP63/giphy.gif)

Patch:
diff --git a/pynubank/nubank.py b/pynubank/nubank.py
index 23dd07f..7ef07e8 100644
--- a/pynubank/nubank.py
+++ b/pynubank/nubank.py
@@ -286,19 +286,61 @@ class Nubank:
 
     @requires_auth_mode(AuthMode.APP)
     def get_pix_identifier(self, transaction_id: str):
-        def find_pix_identifier(table_item: dict):
-            return table_item.get('label') == 'Identificador'
-
         response = self._make_graphql_request('pix_receipt_screen', {'type': 'TRANSFER_IN', 'id': transaction_id})
+
         if 'errors' in response.keys():
             return
 
         screen_pieces = response['data']['viewer']['savingsAccount']['getGenericReceiptScreen']['screenPieces']
+
+        return self._get_pix_id(screen_pieces)
+
+    def _get_pix_value(self, screen_pieces: dict):
+        def find_pix_value(table_item: dict):
+            return table_item.get('label') == 'Valor'
+
         table_items = list(itertools.chain(*[table_item.get('tableItems', []) for table_item in screen_pieces]))
+        value_data = next(filter(find_pix_value, table_items), None)
+
+        if value_data is None:
+            return
+
+        return value_data['value']
 
-        identifier_data = next(filter(find_pix_identifier, table_items), None)
+    def _get_pix_id(self, screen_pieces: dict):
+        def find_pix_id(table_item: dict):
+            return table_item.get('label') == 'Identificador'
+
+        table_items = list(itertools.chain(*[table_item.get('tableItems', []) for table_item in screen_pieces]))
+        identifier_data = next(filter(find_pix_id, table_items), None)
 
         if identifier_data is None:
             return
 
         return identifier_data['value']
+
+    def _get_pix_message(self, screen_pieces: dict):
+        message_content = list(itertools.chain(*[table_item.get('messageContent', []) for table_item in screen_pieces]))
+
+        return ''.join(message_content)
+
+    def _get_pix_date(self, screen_pieces: dict):
+        transaction_date = list(itertools.chain(*[table_item.get('headerSubtitle', []) for table_item in screen_pieces]))
+
+        return ''.join(transaction_date)
+
+    @requires_auth_mode(AuthMode.APP)
+    def get_pix_details(self, transaction_id: str):
+        response = self._make_graphql_request('pix_receipt_screen', {'type': 'TRANSFER_IN', 'id': transaction_id})
+
+        if 'errors' in response.keys():
+            return
+
+        screen_pieces = response['data']['viewer']['savingsAccount']['getGenericReceiptScreen']['screenPieces']
+
+        return {
+            "id": self._get_pix_id(screen_pieces),
+            "value": self._get_pix_value(screen_pieces),
+            "message": self._get_pix_message(screen_pieces),
+            "date": self._get_pix_date(screen_pieces),
+        }
diff --git a/pynubank/utils/mocked_responses/pix_receipt_screen.json b/pynubank/utils/mocked_responses/pix_receipt_screen.json
index d49843a..1de1558 100644
--- a/pynubank/utils/mocked_responses/pix_receipt_screen.json
+++ b/pynubank/utils/mocked_responses/pix_receipt_screen.json
@@ -27,6 +27,12 @@
                 }
               ]
             },
+            {
+              "__typename": "ReceiptMessagePiece",
+              "fallbackMessage": "Atualize seu app para ver todas as informações!",
+              "messageTitle": "Descrição",
+              "messageContent": "Mensagem enviada via PIX"
+            },
             {
               "__typename": "ReceiptTablePiece",
               "fallbackMessage": "Atualize seu app para ver todas as informações!",
diff --git a/setup.py b/setup.py
index 3b4837d..6c89a08 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@ def read(fname):
 
 setup(
     name='pynubank',
-    version='2.18.0',
+    version='2.18.1',
     url='https://github.com/andreroggeri/pynubank',
     author='André Roggeri Campos',
     author_email='a.roggeri.c@gmail.com',


Test patch:
diff --git a/tests/test_nubank_client.py b/tests/test_nubank_client.py
index bdba9ed..dac0920 100644
--- a/tests/test_nubank_client.py
+++ b/tests/test_nubank_client.py
@@ -522,3 +522,16 @@ def test_creditcard_methods_should_allow_web_authentication(method_name, method_
 
 def test_creditcard_methods_should_allow_app_authentication():
     pass
+
+
+def test_get_pix_details():
+    nubank_client = Nubank(client=MockHttpClient())
+    nubank_client.authenticate_with_cert('1234', 'hunter12', 'some-file.p12')
+
+    pix_details = nubank_client.get_pix_details('IdentificadorPixAqui')
+
+    assert pix_details is not None
+    assert pix_details['message'] == 'Mensagem enviada via PIX'
+    assert pix_details['id'] == 'IdentificadorPixAqui'
+    assert pix_details['value'] == 'R$ 2,00'
+    assert pix_details['date'] == '09 AGO 2021 - 17:05:08'