Compare commits
8 Commits
95c65836c5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98707fce2b | ||
|
|
b2ee0fe37f | ||
|
|
b16b9d4fb2 | ||
|
|
925002c572 | ||
|
|
e05f46a987 | ||
|
|
be5a097739 | ||
|
|
44cadbff92 | ||
|
|
4c3616ffbc |
33
bbpay.py
33
bbpay.py
@@ -15,6 +15,9 @@ from eth_utils import to_wei
|
|||||||
|
|
||||||
# Load environment variables from .env file
|
# Load environment variables from .env file
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
ENVIRONMENT = getenv('ENVIRONMENT', 'dev')
|
||||||
|
dotenv_path = f'.env.{ENVIRONMENT}'
|
||||||
|
load_dotenv(dotenv_path)
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app, origins=['https://p2pix.co'])
|
CORS(app, origins=['https://p2pix.co'])
|
||||||
@@ -31,7 +34,7 @@ class BBPay(Resource):
|
|||||||
self.token_url = getenv("ITP_TOKEN_URL")
|
self.token_url = getenv("ITP_TOKEN_URL")
|
||||||
|
|
||||||
self.params = {
|
self.params = {
|
||||||
'numeroConvenio': 701,
|
'numeroConvenio': getenv("BBPAY_CONVENIO"),
|
||||||
'gw-dev-app-key': getenv("DEV_APP_KEY")
|
'gw-dev-app-key': getenv("DEV_APP_KEY")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,9 +54,10 @@ class BBPay(Resource):
|
|||||||
|
|
||||||
class Register(BBPay):
|
class Register(BBPay):
|
||||||
def post(self):
|
def post(self):
|
||||||
data = request.get_json()
|
data = request.get_data(as_text=True)
|
||||||
|
app.logger.debug(data)
|
||||||
body = {
|
body = {
|
||||||
'numeroConvenio': 701,
|
'numeroConvenio': getenv("BBPAY_CONVENIO"),
|
||||||
'nomeParticipante': data['chainID'],
|
'nomeParticipante': data['chainID'],
|
||||||
'tipoDocumento': data['tipoDocumento'],
|
'tipoDocumento': data['tipoDocumento'],
|
||||||
'numeroDocumento': data['numeroDocumento'],
|
'numeroDocumento': data['numeroDocumento'],
|
||||||
@@ -62,6 +66,7 @@ class Register(BBPay):
|
|||||||
'tipoConta': data['tipoConta'],
|
'tipoConta': data['tipoConta'],
|
||||||
'codigoIspb': data['codigoIspb'] # Código identificador do Sistema de Pagamentos Brasileiro. Atualmente aceitamos apenas Banco do Brasil, codigoIspb igual a 0
|
'codigoIspb': data['codigoIspb'] # Código identificador do Sistema de Pagamentos Brasileiro. Atualmente aceitamos apenas Banco do Brasil, codigoIspb igual a 0
|
||||||
}
|
}
|
||||||
|
app.logger.debug(body)
|
||||||
response = self.oauth.post(
|
response = self.oauth.post(
|
||||||
self.baseUrl+"/participantes",
|
self.baseUrl+"/participantes",
|
||||||
params=self.params,
|
params=self.params,
|
||||||
@@ -69,19 +74,21 @@ class Register(BBPay):
|
|||||||
verify=self.verify_ssl,
|
verify=self.verify_ssl,
|
||||||
cert=self.cert)
|
cert=self.cert)
|
||||||
if response.status_code != 201:
|
if response.status_code != 201:
|
||||||
return 'Upstream error', response.status_code
|
app.logger.debug(response._content)
|
||||||
|
return response.reason, response.status_code
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
class Request(BBPay):
|
class Request(BBPay):
|
||||||
def post(self):
|
def post(self):
|
||||||
data = request.get_json()
|
data = request.get_data(as_text=True)
|
||||||
|
app.logger.debug(data)
|
||||||
body = {
|
body = {
|
||||||
"geral": {
|
"geral": {
|
||||||
"numeroConvenio": 701,
|
"numeroConvenio": getenv("BBPAY_CONVENIO"),
|
||||||
"pagamentoUnico": True,
|
"pagamentoUnico": True,
|
||||||
"descricaoSolicitacao": "P2Pix",
|
"descricaoSolicitacao": "P2Pix",
|
||||||
"valorSolicitacao": data['amount'],
|
"valorSolicitacao": data['amount'],
|
||||||
"codigoConciliacaoSolicitacao": data['lockid']
|
#"codigoConciliacaoSolicitacao": data['lockid']
|
||||||
},
|
},
|
||||||
# "devedor": {
|
# "devedor": {
|
||||||
# "tipoDocumento": 1,
|
# "tipoDocumento": 1,
|
||||||
@@ -96,25 +103,29 @@ class Request(BBPay):
|
|||||||
"valorRepasse": 100 }]
|
"valorRepasse": 100 }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
app.logger.debug(body)
|
||||||
response = self.oauth.post(
|
response = self.oauth.post(
|
||||||
self.baseUrl+"/solicitacoes",
|
self.baseUrl+"/solicitacoes",
|
||||||
params=self.params,
|
params=self.params,
|
||||||
json=body,
|
json=body,
|
||||||
verify=self.verify_ssl,
|
verify=self.verify_ssl,
|
||||||
cert=self.cert)
|
cert=self.cert)
|
||||||
|
app.logger.debug(response._content)
|
||||||
if response.status_code != 201:
|
if response.status_code != 201:
|
||||||
return 'Upstream error', response.status_code
|
return response.reason, response.status_code
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
class Release(BBPay):
|
class Release(BBPay):
|
||||||
def get(self, numeroSolicitacao):
|
def get(self, numeroSolicitacao):
|
||||||
|
app.logger.debug(request.get_data(as_text=True))
|
||||||
response = self.oauth.get(
|
response = self.oauth.get(
|
||||||
self.baseUrl+f"/solicitacoes/{numeroSolicitacao}",
|
self.baseUrl+f"/solicitacoes/{numeroSolicitacao}",
|
||||||
params=self.params,
|
params=self.params,
|
||||||
verify=self.verify_ssl,
|
verify=self.verify_ssl,
|
||||||
cert=self.cert)
|
cert=self.cert)
|
||||||
|
app.logger.debug(response._content)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return 'Upstream error', response.status_code
|
return response.reason, response.status_code
|
||||||
data = response.json()
|
data = response.json()
|
||||||
numeroParticipante = data['repasse']['recebedores'][0]['identificadorRecebedor']
|
numeroParticipante = data['repasse']['recebedores'][0]['identificadorRecebedor']
|
||||||
pixTimestamp = encode_packed(['bytes32'],[b85decode(data['informacoesPix']['txId'])])
|
pixTimestamp = encode_packed(['bytes32'],[b85decode(data['informacoesPix']['txId'])])
|
||||||
@@ -156,7 +167,7 @@ api.add_resource(Release, '/release/<int:numeroSolicitacao>')
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if getenv("DEBUG"):
|
if getenv("DEBUG"):
|
||||||
disable_warnings()
|
disable_warnings()
|
||||||
app.run(host='::',debug=True)
|
app.run(host='::1', debug=True, port=getenv("PORT",5000))
|
||||||
else:
|
else:
|
||||||
from waitress import serve
|
from waitress import serve
|
||||||
serve(app, host=getenv("HOST","::"), port=getenv("PORT",5000))
|
serve(app, host=getenv("HOST","::1"), port=getenv("PORT",5000))
|
||||||
|
|||||||
Reference in New Issue
Block a user