Compare commits

...

4 Commits

Author SHA1 Message Date
hueso
60a22e1b0b dynamic deploy environments 2025-10-31 14:28:35 -03:00
hueso
68f33a3249 improve error handling 2025-10-31 14:07:07 -03:00
hueso
2729be8d2c added .gitignore for sensitive files 2025-07-11 14:16:08 -03:00
hueso
65db1edc06 0x prefixed and padded return values 2025-07-04 21:15:06 -03:00
3 changed files with 43 additions and 29 deletions

16
.env.example Normal file
View File

@@ -0,0 +1,16 @@
PRIVATE_KEY=0x....
CLIENT_ID=
CLIENT_SECRET=
DEV_APP_KEY=
DEBUG=false
ITP_TOKEN_URL = https://oauth.hm.bb.com.br/oauth/token
# Url de produção com autenticação mTLS.
#ITP_API_URL="https://api-bbpay.bb.com.br/checkout/v2"
# Url de homologação com autenticação mTLS.
ITP_API_URL = "https://api-bbpay.hm.bb.com.br/checkout/v2"
# Url de homologação sem autenticação mTLS.
#ITP_API_URL = "https://api.extranet.hm.bb.com.br/checkout/v2"
# 05/08/2025
#ITP_API_URL=https://checkout.mtls.api.bb.com.br
#ITP_API_URL=https://checkout.mtls.api.hm.bb.com.br

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.env
*.pem
venv

View File

@@ -27,15 +27,8 @@ class BBPay(Resource):
self.cert = 'key.pem'
self.verify_ssl = 'bb.pem'
# Url de homologação com autenticação mTLS.
self.baseUrl = "https://api-bbpay.hm.bb.com.br/checkout/v2"
# Url de homologação sem autenticação mTLS.
#self.baseUrl = "https://api.extranet.hm.bb.com.br/checkout/v2"
# Url de produção com autenticação mTLS.
#self.baseUrl = "https://api-bbpay.bb.com.br/checkout/v2"
self.baseUrl = getenv("ITP_API_URL")
self.token_url = getenv("ITP_TOKEN_URL")
self.params = {
'numeroConvenio': 701,
@@ -48,7 +41,7 @@ class BBPay(Resource):
'checkout.participantes-info']
self.oauth.fetch_token(
token_url='https://oauth.hm.bb.com.br/oauth/token',
token_url=self.token_url,
client_id=getenv("CLIENT_ID"),
client_secret=getenv("CLIENT_SECRET"), scope=self.scope)
@@ -75,6 +68,8 @@ class Register(BBPay):
json=body,
verify=self.verify_ssl,
cert=self.cert)
if response.status_code != 201:
return 'Upstream error', response.status_code
return response.json()
class Request(BBPay):
@@ -85,7 +80,8 @@ class Request(BBPay):
"numeroConvenio": 701,
"pagamentoUnico": True,
"descricaoSolicitacao": "P2Pix",
"valorSolicitacao": data['amount']
"valorSolicitacao": data['amount'],
"codigoConciliacaoSolicitacao": data['lockid']
},
# "devedor": {
# "tipoDocumento": 1,
@@ -106,6 +102,8 @@ class Request(BBPay):
json=body,
verify=self.verify_ssl,
cert=self.cert)
if response.status_code != 201:
return 'Upstream error', response.status_code
return response.json()
class Release(BBPay):
@@ -119,7 +117,7 @@ class Release(BBPay):
return 'Upstream error', response.status_code
data = response.json()
numeroParticipante = data['repasse']['recebedores'][0]['identificadorRecebedor']
pixTimestamp = b85decode(data['informacoesPix']['txId'])
pixTimestamp = encode_packed(['bytes32'],[b85decode(data['informacoesPix']['txId'])])
valorSolicitacao = to_wei(data['valorSolicitacao'], 'ether')
codigoEstadoSolicitacao = data['codigoEstadoSolicitacao']
if codigoEstadoSolicitacao != 1:
@@ -139,9 +137,9 @@ class Release(BBPay):
return {
'pixTarget': f"{chainID}-{numeroParticipante}",
'amount': str(valorSolicitacao),
'pixTimestamp': pixTimestamp.hex(),
'signature': signature }
'pixTimestamp': f"0x{pixTimestamp.hex()}",
'signature': f"0x{signature}"
}
# (CPF, nome, conta) -> participantID
# should be called before deposit
@@ -155,7 +153,6 @@ api.add_resource(Request, '/request')
# should be called before release
api.add_resource(Release, '/release/<int:numeroSolicitacao>')
if __name__ == '__main__':
if getenv("DEBUG"):
disable_warnings()
@@ -163,5 +160,3 @@ if __name__ == '__main__':
else:
from waitress import serve
serve(app, host=getenv("HOST","0.0.0.0"), port=getenv("PORT",5000))