improve error handling
This commit is contained in:
parent
2729be8d2c
commit
68f33a3249
23
bbpay.py
23
bbpay.py
@ -70,11 +70,13 @@ class Register(BBPay):
|
|||||||
'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
|
||||||
}
|
}
|
||||||
response = self.oauth.post(
|
response = self.oauth.post(
|
||||||
self.baseUrl+"/participantes",
|
self.baseUrl+"/participantes",
|
||||||
params=self.params,
|
params=self.params,
|
||||||
json=body,
|
json=body,
|
||||||
verify=self.verify_ssl,
|
verify=self.verify_ssl,
|
||||||
cert=self.cert)
|
cert=self.cert)
|
||||||
|
if response.status_code != 201:
|
||||||
|
return 'Upstream error', response.status_code
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
class Request(BBPay):
|
class Request(BBPay):
|
||||||
@ -85,7 +87,8 @@ class Request(BBPay):
|
|||||||
"numeroConvenio": 701,
|
"numeroConvenio": 701,
|
||||||
"pagamentoUnico": True,
|
"pagamentoUnico": True,
|
||||||
"descricaoSolicitacao": "P2Pix",
|
"descricaoSolicitacao": "P2Pix",
|
||||||
"valorSolicitacao": data['amount']
|
"valorSolicitacao": data['amount'],
|
||||||
|
"codigoConciliacaoSolicitacao": data['lockid']
|
||||||
},
|
},
|
||||||
# "devedor": {
|
# "devedor": {
|
||||||
# "tipoDocumento": 1,
|
# "tipoDocumento": 1,
|
||||||
@ -94,7 +97,7 @@ class Request(BBPay):
|
|||||||
"formasPagamento": [{ "codigoTipoPagamento": "PIX", "quantidadeParcelas": 1}],
|
"formasPagamento": [{ "codigoTipoPagamento": "PIX", "quantidadeParcelas": 1}],
|
||||||
"repasse": {
|
"repasse": {
|
||||||
"tipoValorRepasse": "Percentual",
|
"tipoValorRepasse": "Percentual",
|
||||||
"recebedores": [{
|
"recebedores": [{
|
||||||
"identificadorRecebedor": data['pixTarget'],
|
"identificadorRecebedor": data['pixTarget'],
|
||||||
"tipoRecebedor": "Participante",
|
"tipoRecebedor": "Participante",
|
||||||
"valorRepasse": 100 }]
|
"valorRepasse": 100 }]
|
||||||
@ -106,6 +109,8 @@ class Request(BBPay):
|
|||||||
json=body,
|
json=body,
|
||||||
verify=self.verify_ssl,
|
verify=self.verify_ssl,
|
||||||
cert=self.cert)
|
cert=self.cert)
|
||||||
|
if response.status_code != 201:
|
||||||
|
return 'Upstream error', response.status_code
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
class Release(BBPay):
|
class Release(BBPay):
|
||||||
@ -132,7 +137,7 @@ class Release(BBPay):
|
|||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return 'Upstream error', response.status_code
|
return 'Upstream error', response.status_code
|
||||||
chainID = response.json()['nomeParticipante']
|
chainID = response.json()['nomeParticipante']
|
||||||
packed = encode_packed(['bytes32','uint80','bytes32'],
|
packed = encode_packed(['bytes32','uint80','bytes32'],
|
||||||
(f"{chainID}-{numeroParticipante}".encode(), int(valorSolicitacao), pixTimestamp) )
|
(f"{chainID}-{numeroParticipante}".encode(), int(valorSolicitacao), pixTimestamp) )
|
||||||
signable = eth_account.messages.encode_defunct(keccak(packed))
|
signable = eth_account.messages.encode_defunct(keccak(packed))
|
||||||
signature = eth_account.account.Account.sign_message(signable, private_key=getenv('PRIVATE_KEY')).signature.hex()
|
signature = eth_account.account.Account.sign_message(signable, private_key=getenv('PRIVATE_KEY')).signature.hex()
|
||||||
@ -143,26 +148,22 @@ class Release(BBPay):
|
|||||||
'signature': f"0x{signature}"
|
'signature': f"0x{signature}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# (CPF, nome, conta) -> participantID
|
# (CPF, nome, conta) -> participantID
|
||||||
# should be called before deposit
|
# should be called before deposit
|
||||||
api.add_resource(Register, '/register')
|
api.add_resource(Register, '/register')
|
||||||
|
|
||||||
# (amount,pixtarget) -> requestID, QRcodeText
|
# (amount,pixtarget) -> requestID, QRcodeText
|
||||||
# should be called after lock
|
# should be called after lock
|
||||||
api.add_resource(Request, '/request')
|
api.add_resource(Request, '/request')
|
||||||
|
|
||||||
# (requestID) -> sig(pixTarget, amount, pixTimestamp)
|
# (requestID) -> sig(pixTarget, amount, pixTimestamp)
|
||||||
# should be called before release
|
# should be called before release
|
||||||
api.add_resource(Release, '/release/<int:numeroSolicitacao>')
|
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(debug=True)
|
app.run(debug=True)
|
||||||
else:
|
else:
|
||||||
from waitress import serve
|
from waitress import serve
|
||||||
serve(app, host=getenv("HOST","0.0.0.0"), port=getenv("PORT",5000))
|
serve(app, host=getenv("HOST","0.0.0.0"), port=getenv("PORT",5000))
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user