Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criação de transferência em lotes pelo PIX #54

Open
wants to merge 142 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
9fbd40b
criar transferencia pix
peidrao Apr 20, 2023
2306997
testes de transferencias pix
peidrao Apr 20, 2023
e1c6b24
exemplo de transferencia pix
peidrao Apr 20, 2023
5121f2d
formatacao e remocao de pdb
peidrao Apr 20, 2023
cbcc864
Update tests/wrapper/test_pagamentos.py
peidrao Apr 20, 2023
dca8256
Update tests/wrapper/test_pagamentos.py
peidrao Apr 20, 2023
33b6c34
Update tests/wrapper/test_pagamentos.py
peidrao Apr 20, 2023
216dd29
fmt
peidrao Apr 20, 2023
cec80e5
adicao de novos escopo de autorizacao do pix
peidrao Apr 20, 2023
dbf4d76
fix testes
peidrao Apr 20, 2023
558871d
fmt
peidrao Apr 20, 2023
e9d83cc
Update tests/wrapper/test_pagamentos.py
peidrao Apr 20, 2023
f088f9e
adicao de exemplo de trasnferencia usando cpf
peidrao Apr 20, 2023
7168239
adicao de wrapper para consulta de pix
peidrao Apr 20, 2023
08b50a6
testes no service de pix
peidrao Apr 20, 2023
18a7e8b
testes na funcao para criar body da transferencia pix
peidrao Apr 22, 2023
8ab341d
atualizacao de modelo e service transferencia pix
peidrao Apr 22, 2023
3a7e9de
refatorando servico de transferencia pix em lote
peidrao Apr 22, 2023
191b492
refatorando examplo de transferencia pix usando cpf
peidrao Apr 22, 2023
7d8f3d7
servico para verificar se email eh valido
peidrao Apr 23, 2023
5b97b46
testes em DocumentService
peidrao Apr 24, 2023
dede79a
fmt em DocumentService
peidrao Apr 24, 2023
01a6dab
Update bb_wrapper/services/pix.py
peidrao Apr 24, 2023
4f0166c
Update bb_wrapper/services/pix.py
peidrao Apr 24, 2023
e14abe7
ajustes em testes
peidrao Apr 24, 2023
4c43560
correcoes em teste
peidrao Apr 25, 2023
a6e746b
mock em test_retry_request
peidrao Apr 26, 2023
2846d7b
fmt
peidrao Apr 26, 2023
f9cff49
atualizacao da versao do py-bdd-context
peidrao Apr 26, 2023
298faf0
adicao de novos testes
peidrao Apr 26, 2023
4f77340
update lock file
peidrao Apr 26, 2023
14e2564
fmt
peidrao Apr 26, 2023
e54c317
Update tests/wrapper/test_pagamentos.py
peidrao Apr 27, 2023
857f9a3
refatoracao de testes
peidrao Apr 27, 2023
8947873
fmt
peidrao Apr 27, 2023
19c63e0
Update tests/utils.py
peidrao Apr 28, 2023
585508b
Update examples/lotes_pagamento/consultar_transferencia_pix.py
peidrao Apr 28, 2023
b3aa363
Update tests/wrapper/test_request.py
peidrao Apr 28, 2023
fdc0250
BDD em PixServiceTesteCase
peidrao Apr 28, 2023
8408423
fmt
peidrao Apr 28, 2023
993dda4
espaco branco no final do arquivo json
peidrao Apr 28, 2023
b130142
adicionando bdd em testes
peidrao May 2, 2023
6a86e7c
Update tests/services/test_documento.py
peidrao May 2, 2023
1afda49
Update tests/services/test_documento.py
peidrao May 2, 2023
4b02e21
Update tests/services/test_identify_key_type.py
peidrao May 2, 2023
4355f03
Update tests/services/test_identify_key_type.py
peidrao May 2, 2023
7b5a905
Update tests/wrapper/test_request.py
peidrao May 2, 2023
b0575e6
Update tests/services/test_identify_key_type.py
peidrao May 2, 2023
100bb9e
ajustes na descricao dos testes
peidrao May 2, 2023
dbc034f
Update tests/services/test_identify_key_type.py
peidrao May 3, 2023
7a13a25
Update tests/wrapper/test_request.py
peidrao May 3, 2023
12f174b
Update tests/utils.py
peidrao May 3, 2023
0d40ce7
ajustes em test
peidrao May 3, 2023
f16bd69
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
471d83d
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
5ebe8ce
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
f18f7da
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
146b1ec
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
83c5f1e
Update tests/services/test_documento.py
peidrao May 4, 2023
d50dfa3
Update tests/services/test_documento.py
peidrao May 4, 2023
014bff8
Update tests/services/test_documento.py
peidrao May 4, 2023
32a309d
Update bb_wrapper/models/pagamentos.py
peidrao May 4, 2023
e331ce3
ajuste em espaco de teste
peidrao May 4, 2023
ae5e6d9
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
17faf03
Update tests/services/test_documento.py
peidrao May 4, 2023
55103b0
Update tests/services/test_documento.py
peidrao May 4, 2023
18f6ad6
Update tests/services/test_documento.py
peidrao May 4, 2023
5964dd3
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
59228f8
Update tests/services/test_documento.py
peidrao May 4, 2023
545d9a4
Update tests/services/test_documento.py
peidrao May 4, 2023
33f4c66
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
3b1c761
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
398adc9
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
a7f99e6
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
f7a03da
Update tests/services/test_documento.py
peidrao May 4, 2023
14bdb29
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
3e2fc28
Update tests/services/test_identify_key_type.py
peidrao May 4, 2023
5f13d75
Update bb_wrapper/models/pagamentos.py
peidrao May 4, 2023
f7c8c76
Melhorar comentários em testes e remoção de método para buscar transf…
peidrao May 5, 2023
002c065
Atualizacao de requests
peidrao May 5, 2023
605729e
Atualizacao de poetry.lock
peidrao May 5, 2023
30bb589
update requests
peidrao May 5, 2023
07ee192
atualizacao do poetry.lock
peidrao May 5, 2023
03aac77
utilizando requests 2.29.0
peidrao May 5, 2023
9f15f13
ajuste no actions
peidrao May 5, 2023
c1b1472
Debugando CI, ls -al
PedroRegisPOAR May 5, 2023
24d7128
Debugando CI, ls -al
PedroRegisPOAR May 5, 2023
d5316a6
Debugando CI, remove .native -> .venv
PedroRegisPOAR May 5, 2023
f0f7e3a
Debugando CI, poetry show --tree
PedroRegisPOAR May 5, 2023
1d2f8f9
Debugando CI, poetry show --tree
PedroRegisPOAR May 5, 2023
f9f5bed
Update .github/workflows/pypi.yml
PedroRegisPOAR May 7, 2023
86da7f5
Update .github/workflows/tests.yml
PedroRegisPOAR May 7, 2023
88d6b8e
Update .github/workflows/tests.yml
PedroRegisPOAR May 7, 2023
a05ddce
Update .github/workflows/tests.yml
PedroRegisPOAR May 7, 2023
c9295fb
Fixa requests = "2.30.0"
PedroRegisPOAR May 7, 2023
a2f84be
Fixa urllib3 = "1.26.15"
PedroRegisPOAR May 7, 2023
d6243ca
Atualiza poetry da Action
PedroRegisPOAR May 7, 2023
c5f9ed9
fmt
PedroRegisPOAR May 7, 2023
304d4ab
Atualiza poetry usado localmente para 1.4.2
PedroRegisPOAR May 7, 2023
d5c37ce
Update tests/wrapper/test_pagamentos.py
peidrao May 8, 2023
b3fd154
atualizacao de nomes cpf e cnpj
peidrao May 8, 2023
5174020
alterando nomeacao de pix para PIX em comentarios
peidrao May 8, 2023
756df5f
Remove result-bin
PedroRegisPOAR May 8, 2023
e183604
consultar pix
peidrao May 8, 2023
07b044e
teste de consulta de pix
peidrao May 8, 2023
a158a01
fmt
peidrao May 8, 2023
3c23d45
fmt
peidrao May 8, 2023
0df0a6f
consultar pix exemplo
peidrao May 8, 2023
28796a4
refatoracao de testes usando o bdd
peidrao May 9, 2023
bc13ca3
alteracao do readme, com novos recursos
peidrao May 10, 2023
3767851
Merge branch 'imopix' of github.com:imobanco/bb-wrapper into imopix
peidrao May 10, 2023
9a30c81
ajustando comentarios nos testes do BaseBBWrapper
peidrao May 10, 2023
2cce1ec
Merge branch 'imopix' of github.com:imobanco/bb-wrapper into imopix
peidrao May 10, 2023
e3c5b70
adicionando campo de documento para enviar cpf/cnpj
peidrao May 10, 2023
b2a6a2d
adicionando classmethod em verifica_documento
peidrao May 10, 2023
720d3e6
criacao de pasta certs com nix
peidrao May 11, 2023
c38445b
Update bb_wrapper/wrapper/pagamento_lote.py
peidrao May 12, 2023
6691f0c
Update bb_wrapper/models/pagamentos.py
peidrao May 12, 2023
7af9f63
ajustes na interface do transferencia pix
peidrao May 12, 2023
f48d900
Update bb_wrapper/models/pagamentos.py
peidrao May 15, 2023
eedcbe5
ajustes em testes e ajustes na documentacao
peidrao May 15, 2023
2e8895b
merge com main
peidrao Jan 25, 2024
9925265
adiciona pequenas mudanças em nomes de métodos e classes
peidrao Jan 29, 2024
6e4c515
remover tipo de chave pix da docsstring TipoChavePIX
peidrao Jan 29, 2024
9db1079
adiciona verificador de documento no serviço destinado ao pix
peidrao Jan 30, 2024
219ae20
adiciona modelo para transferencia pix via dados bancários
peidrao Jan 30, 2024
e58dd32
adiciona serviço de transferencia pix via dados bancários no bb-wrapper
peidrao Jan 30, 2024
012dccc
adiciona testes unitários
peidrao Jan 30, 2024
31cc8ae
adiciona example de chamada de requisição
peidrao Jan 30, 2024
c2ff8f4
adiciona numero ISPB
peidrao Jan 30, 2024
f59ddc5
adiciona valores bancários como opcionais
peidrao Jan 30, 2024
8934d56
cria exemplo de transferencia pix via dados bancários apenas pela con…
peidrao Jan 30, 2024
310a6e8
Apply suggestions from code review
peidrao Jan 30, 2024
a81a5b3
ajustes
peidrao Jan 30, 2024
446e6df
ajustar modelos
peidrao Jan 31, 2024
e462efa
ajustar testes em wrapper
peidrao Jan 31, 2024
3ef005e
ajustar testes
peidrao Jan 31, 2024
ded5afb
adiciona logging no exemplo!
rodrigondec Feb 1, 2024
d1ea125
ajustes
peidrao Feb 1, 2024
9f62125
removendo valores nulos
peidrao Feb 2, 2024
45f0277
adiciona tratamento do COMPE e cpf/cnpj dos dados.
rodrigondec Feb 6, 2024
28f6829
ajustes
rodrigondec May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 117 additions & 1 deletion bb_wrapper/wrapper/pagamento_lote.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PagamentoLoteBBWrapper(BaseBBWrapper):
Wrapper da API Pagamentos em Lote
"""

SCOPE = "pagamentos-lote.lotes-requisicao pagamentos-lote.transferencias-info pagamentos-lote.transferencias-requisicao pagamentos-lote.cancelar-requisicao pagamentos-lote.devolvidos-info pagamentos-lote.lotes-info pagamentos-lote.pagamentos-guias-sem-codigo-barras-info pagamentos-lote.pagamentos-info pagamentos-lote.pagamentos-guias-sem-codigo-barras-requisicao pagamentos-lote.pagamentos-codigo-barras-info pagamentos-lote.boletos-requisicao pagamentos-lote.guias-codigo-barras-info pagamentos-lote.guias-codigo-barras-requisicao pagamentos-lote.transferencias-pix-info pagamentos-lote.transferencias-pix-requisicao pagamentos-lote.pix-info pagamentos-lote.boletos-info" # noqa
brenomfviana marked this conversation as resolved.
Show resolved Hide resolved
SCOPE = "pagamentos-lote.lotes-requisicao pagamentos-lote.transferencias-info pagamentos-lote.transferencias-requisicao pagamentos-lote.cancelar-requisicao pagamentos-lote.devolvidos-info pagamentos-lote.lotes-info pagamentos-lote.pagamentos-guias-sem-codigo-barras-info pagamentos-lote.pagamentos-info pagamentos-lote.pagamentos-guias-sem-codigo-barras-requisicao pagamentos-lote.pagamentos-codigo-barras-info pagamentos-lote.boletos-requisicao pagamentos-lote.guias-codigo-barras-info pagamentos-lote.guias-codigo-barras-requisicao pagamentos-lote.transferencias-pix-requisicao" # noqa
BASE_PROD_ADDITION = "-ip"
BASE_DOMAIN = ".bb.com.br/pagamentos-lote/v1"

Expand Down Expand Up @@ -481,3 +481,119 @@ def consultar_pagamento_tributo(self, _id):
response = self._get(url)

return response

################
# PIX #
################

def _criar_dados_transferencia_pix(
self,
n_requisicao,
agencia,
conta,
dv_conta,
data_transferencia,
valor_transferencia,
forma_id,
ddd,
telefone,
email,
cpf,
cnpj,
chave_aleatoria,
rodrigondec marked this conversation as resolved.
Show resolved Hide resolved
descricao,
tipo_pagamento,
):
lote_data = {
"numeroRequisicao": n_requisicao,
"agenciaDebito": agencia,
"contaCorrenteDebito": conta,
"digitoVerificadorContaCorrente": dv_conta,
"tipoPagamento": tipo_pagamento,
}

transferencia_data = {
"data": data_transferencia,
"valor": valor_transferencia,
"formaIdentificacao": forma_id,
"descricaoPagamento": descricao,
}

if forma_id == 1:
transferencia_data["dddTelefone"] = ddd
transferencia_data["telefone"] = telefone
elif forma_id == 2:
transferencia_data["email"] = email
elif forma_id == 3:
transferencia_data["cpf"] = cpf
transferencia_data["cnpj"] = cnpj
elif forma_id == 4:
transferencia_data["identificacaoAleatoria"] = chave_aleatoria
rodrigondec marked this conversation as resolved.
Show resolved Hide resolved

return {**lote_data, "listaTransferencias": [{**transferencia_data}]}

def criar_transferencia_pix(
self,
n_requisicao,
agencia,
conta,
dv_conta,
data_transferencia,
valor_transferencia,
forma_id,
ddd=None,
telefone=None,
email=None,
cpf=None,
cnpj=None,
chave_aleatoria=None,
descricao="",
tipo_pagamento=128,
):
"""
Efetua pagamentos em lote via tranferência PIX

Args:
n_requisicao: Nº da requisição a ser utilizado. Deve ser único
agencia: Agência da conta de origem do pagamento
conta: Nº da conta de origem do pagamento
dv_conta: DV da conta de origem do pagamento
tipo_pagamento: Tipo de pagamento a ser feito (126, 127 ou 128)
data_transferencia: Data do pagamento. No formato "ddmmyyyy"
valor_transferencia: Valor do pagamento
forma_id: Tipo de chave utilizada
1. Telefone
2. E-mail
3. CPF/CNPJ
4. Chave Aleatória
ddd: DDD com dígitos. Obrigatório caso forma_id seja igual 1
telefone: Telefone do recebedor. Obrigatório caso forma_id seja igual 1
email: Email do recebedor. Obrigatório caso forma_id seja igual 2
cpf: CPF do recebedor.
Opcional caso forma_id seja igual a 1 ou 2 e caso o campo cnpj não seja informado
Obrigatório caso forma_id seja igual a 3 ou 5 e caso o campo cnpj não seja informado
cnpj: CNPJ do recebedor: Tem os mesmos casos de Obrigatório e opcional do cpf
chave_aleatoria: Chave aleatória gerada pelo recebedor. Obrigatório caso forma_id seja igual 4
descricao: Campo de uso livre pelo cliente
brenomfviana marked this conversation as resolved.
Show resolved Hide resolved
"""
data = self._criar_dados_transferencia_pix(
n_requisicao,
agencia,
conta,
dv_conta,
data_transferencia,
valor_transferencia,
forma_id,
ddd,
telefone,
email,
cpf,
cnpj,
chave_aleatoria,
descricao,
PedroRegisPOAR marked this conversation as resolved.
Show resolved Hide resolved
tipo_pagamento,
)
url = self._construct_url("lotes-transferencias-pix")
response = self._post(url, data)

return response
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"numeroRequisicao": 921347,
"estadoRequisicao": 1,
"quantidadeTransferencias": 1,
"valorTransferencias": 15.5,
"quantidadeTransferenciasValidas": 1,
"valorTransferenciasValidas": 15.5,
"listaTransferencias": [
{
"identificadorPagamento": 90921347731030000,
"data": 19042023,
"valor": 15.5,
"documentoDebito": 0,
"documentoCredito": 0,
"descricaoPagamento": "nova transferencia",
"descricaoPagamentoInstantaneo": "",
"formaIdentificacao": 4,
"dddTelefone": 0,
"telefone": 0,
"email": "",
"cpf": 0,
"cnpj": 0,
"identificacaoAleatoria": "d14d32de-b3b9-4c31-9f89-8df2cec92c50",
"numeroCOMPE": 0,
"numeroISPB": 0,
"tipoConta": 0,
"agencia": 0,
"conta": 0,
"digitoVerificadorConta": "",
"contaPagamento": "",
"indicadorMovimentoAceito": "S",
"erros": []
}
]
}
brenomfviana marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions examples/lotes_pagamento/transferencia_pix_chave_aleatoria.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
from datetime import date

from examples.utils import dump_response

from bb_wrapper.wrapper import PagamentoLoteBBWrapper

c = PagamentoLoteBBWrapper(cert=("./certs/cert.pem", "./certs/key.pem"))


today = date.today()
bb_fmt = "%d%m%Y"


lote_data = {
"n_requisicao": 921347,
"agencia": 1607,
"conta": 99738672,
"dv_conta": "X",
PedroRegisPOAR marked this conversation as resolved.
Show resolved Hide resolved
}

transferencia_data = {
"descricao": "nova transferencia",
"data_transferencia": today.strftime(bb_fmt),
"valor_transferencia": 15.50,
"forma_id": 4,
"chave_aleatoria": "d14d32de-b3b9-4c31-9f89-8df2cec92c50",
}

response = c.criar_transferencia_pix(**lote_data, **transferencia_data)
dump_response(response, os.path.realpath(__file__))
163 changes: 163 additions & 0 deletions tests/wrapper/test_pagamentos.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,166 @@ def test_consultar_pagamento_tributo_1(self):

self.assertEqual(2, self.total_requests())
self.mock_responses.assert_call_count(request_url, 1)

def test_criar_transferencia_pix_chave_aleatoria(self):
"""
Teste para verificar a URL da requisição e dados
peidrao marked this conversation as resolved.
Show resolved Hide resolved
"""

request_url = PagamentoLoteBBWrapper()._construct_url(
"lotes-transferencias-pix"
)
expected_json = {
"numeroRequisicao": "123",
"agenciaDebito": "345",
"contaCorrenteDebito": "678",
"digitoVerificadorContaCorrente": "X",
"tipoPagamento": 128,
"listaTransferencias": [
{
"data": "19042023",
"valor": "11",
"descricaoPagamento": "Pagamento",
"formaIdentificacao": 4,
"identificacaoAleatoria": "d14d32de-b3b9-4c31-9f89-8df2cec92c50",
}
],
}
self.mock_responses.add(
brenomfviana marked this conversation as resolved.
Show resolved Hide resolved
responses.POST,
request_url,
headers=self._build_authorization_header(1),
json=expected_json,
)

response = PagamentoLoteBBWrapper().criar_transferencia_pix(
"123",
"345",
"678",
"X",
"19042023",
"11",
4,
None,
None,
None,
None,
None,
"d14d32de-b3b9-4c31-9f89-8df2cec92c50",
"Pagamento",
)

self.assertEqual(request_url, response.url)
self.assertEqual(self._get_headers(), response.headers)
self.assertEqual(expected_json, response.json())
self.assertEqual(2, self.total_requests())
self.mock_responses.assert_call_count(request_url, 1)

def test_criar_transferencia_pix_email(self):
"""
Teste para verificar a URL da requisição e dados
peidrao marked this conversation as resolved.
Show resolved Hide resolved
"""

request_url = PagamentoLoteBBWrapper()._construct_url(
"lotes-transferencias-pix"
)
expected_json = {
"numeroRequisicao": "123",
"agenciaDebito": "345",
"contaCorrenteDebito": "678",
"digitoVerificadorContaCorrente": "X",
"tipoPagamento": 128,
"listaTransferencias": [
{
"data": "19042023",
"valor": "12",
"descricaoPagamento": "Teste transfer",
"formaIdentificacao": 2,
"email": "[email protected]",
}
],
}
self.mock_responses.add(
responses.POST,
request_url,
headers=self._build_authorization_header(1),
json=expected_json,
)

response = PagamentoLoteBBWrapper().criar_transferencia_pix(
"123",
"345",
"678",
"X",
"19042023",
"11",
2,
None,
None,
"[email protected]",
None,
None,
None,
"Teste transfer",
)

self.assertEqual(request_url, response.url)
self.assertEqual(self._get_headers(), response.headers)
self.assertEqual(expected_json, response.json())
self.assertEqual(2, self.total_requests())
self.mock_responses.assert_call_count(request_url, 1)

def test_criar_transferencia_pix_telefone(self):
"""
Teste para verificar a URL da requisição e dados
peidrao marked this conversation as resolved.
Show resolved Hide resolved
"""

request_url = PagamentoLoteBBWrapper()._construct_url(
"lotes-transferencias-pix"
)
expected_json = {
"numeroRequisicao": "123",
"agenciaDebito": "345",
"contaCorrenteDebito": "678",
"digitoVerificadorContaCorrente": "X",
"tipoPagamento": 128,
"listaTransferencias": [
{
"data": "19042023",
"ddd": "11",
"telefone": "985732102",
"valor": "12",
"descricaoPagamento": "Teste telefone",
"formaIdentificacao": 1,
}
],
}
self.mock_responses.add(
responses.POST,
request_url,
headers=self._build_authorization_header(1),
json=expected_json,
)

response = PagamentoLoteBBWrapper().criar_transferencia_pix(
"123",
"345",
"678",
"X",
"19042023",
"11",
1,
"11",
"985732102",
None,
None,
None,
None,
"Teste telefone",
)

self.assertEqual(request_url, response.url)
self.assertEqual(self._get_headers(), response.headers)
self.assertEqual(expected_json, response.json())
self.assertEqual(2, self.total_requests())
self.mock_responses.assert_call_count(request_url, 1)