Compare commits
4 Commits
a59717a8db
...
4da1d1233c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4da1d1233c | ||
|
|
3edac0ecc9 | ||
|
|
3a4d65ff5d | ||
|
|
22449e7ce1 |
23
README.md
23
README.md
@@ -71,8 +71,29 @@ curl http://localhost:5000/release/123
|
|||||||
- `pixTimestamp`
|
- `pixTimestamp`
|
||||||
- `signature`: assinatura ethereum compatível
|
- `signature`: assinatura ethereum compatível
|
||||||
|
|
||||||
|
# mTLS
|
||||||
|
|
||||||
|
##### `key.pem`: chave privada e certificado da empresa
|
||||||
|
Descriptografar o e-CNPJ em formato PKCS#12 e converter em formato PEM (☢️ contém chave privada):
|
||||||
|
```
|
||||||
|
umask 077; # tirar permissão de leitura global
|
||||||
|
openssl pkcs12 -in <arquivo>.p12 -legacy -clcerts -noenc -out key.pem
|
||||||
|
```
|
||||||
|
|
||||||
|
##### `bb.pem`: certificado do BB
|
||||||
|
Descarregar o certificado de https://apoio.developers.bb.com.br/referency/post/646799afa2e2b90012c5ede8 e converter em formato PEM:
|
||||||
|
```
|
||||||
|
openssl x509 -in raiz_v3.der -inform DER -outform PEM -out bb.pem
|
||||||
|
```
|
||||||
|
|
||||||
|
### Envio de certificado
|
||||||
|
Para criar a cadeia de certificados pra enviar pro BB usar:
|
||||||
|
```
|
||||||
|
openssl pkcs12 -in <arquivo>.p12 -nokeys -legacy -out cert.pem
|
||||||
|
```
|
||||||
|
enviar o `cert.pem` no formulário do portal developers como "cadeia completa".
|
||||||
|
|
||||||
# Observações
|
# Observações
|
||||||
- O ambiente de produção requer autenticação mTLS
|
|
||||||
- Para ambiente de desenvolvimento use `DEBUG=true`
|
- Para ambiente de desenvolvimento use `DEBUG=true`
|
||||||
- Em produção, o servidor usa Waitress como servidor WSGI
|
- Em produção, o servidor usa Waitress como servidor WSGI
|
||||||
- Para mais informações, consulte a documentação oficial: https://developers.bb.com.br/
|
- Para mais informações, consulte a documentação oficial: https://developers.bb.com.br/
|
||||||
49
bbpay.py
49
bbpay.py
@@ -21,24 +21,12 @@ CORS(app)
|
|||||||
api = Api(app)
|
api = Api(app)
|
||||||
|
|
||||||
class BBPay(Resource):
|
class BBPay(Resource):
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.setup_oauth()
|
|
||||||
|
|
||||||
def setup_oauth(self):
|
def setup_oauth(self):
|
||||||
client = BackendApplicationClient(client_id=getenv("CLIENT_ID"))
|
client = BackendApplicationClient(client_id=getenv("CLIENT_ID"))
|
||||||
self.oauth = OAuth2Session(client=client)
|
self.oauth = OAuth2Session(client=client)
|
||||||
|
|
||||||
scope = ['checkout.solicitacoes-requisicao',
|
self.cert = 'key.pem'
|
||||||
'checkout.participantes-requisicao',
|
self.verify_ssl = 'bb.pem'
|
||||||
'checkout.solicitacoes-info',
|
|
||||||
'checkout.participantes-info']
|
|
||||||
|
|
||||||
self.oauth.fetch_token(
|
|
||||||
token_url='https://oauth.hm.bb.com.br/oauth/token',
|
|
||||||
client_id=getenv("CLIENT_ID"),
|
|
||||||
client_secret=getenv("CLIENT_SECRET"), scope=scope,
|
|
||||||
cert='cert.pem')
|
|
||||||
|
|
||||||
# Url de homologação com autenticação mTLS.
|
# Url de homologação com autenticação mTLS.
|
||||||
self.baseUrl = "https://api-bbpay.hm.bb.com.br/checkout/v2"
|
self.baseUrl = "https://api-bbpay.hm.bb.com.br/checkout/v2"
|
||||||
@@ -49,13 +37,25 @@ class BBPay(Resource):
|
|||||||
# Url de produção com autenticação mTLS.
|
# Url de produção com autenticação mTLS.
|
||||||
#self.baseUrl = "https://api-bbpay.bb.com.br/checkout/v2"
|
#self.baseUrl = "https://api-bbpay.bb.com.br/checkout/v2"
|
||||||
|
|
||||||
self.verify_ssl = False
|
|
||||||
|
|
||||||
self.params = {
|
self.params = {
|
||||||
'numeroConvenio': 701,
|
'numeroConvenio': 701,
|
||||||
'gw-dev-app-key': getenv("DEV_APP_KEY")
|
'gw-dev-app-key': getenv("DEV_APP_KEY")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.scope = ['checkout.solicitacoes-requisicao',
|
||||||
|
'checkout.participantes-requisicao',
|
||||||
|
'checkout.solicitacoes-info',
|
||||||
|
'checkout.participantes-info']
|
||||||
|
|
||||||
|
self.oauth.fetch_token(
|
||||||
|
token_url='https://oauth.hm.bb.com.br/oauth/token',
|
||||||
|
client_id=getenv("CLIENT_ID"),
|
||||||
|
client_secret=getenv("CLIENT_SECRET"), scope=self.scope)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setup_oauth()
|
||||||
|
|
||||||
class Register(BBPay):
|
class Register(BBPay):
|
||||||
def post(self):
|
def post(self):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
@@ -74,7 +74,7 @@ class Register(BBPay):
|
|||||||
params=self.params,
|
params=self.params,
|
||||||
json=body,
|
json=body,
|
||||||
verify=self.verify_ssl,
|
verify=self.verify_ssl,
|
||||||
cert='cert.pem')
|
cert=self.cert)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
class Request(BBPay):
|
class Request(BBPay):
|
||||||
@@ -104,7 +104,8 @@ class Request(BBPay):
|
|||||||
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)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
class Release(BBPay):
|
class Release(BBPay):
|
||||||
@@ -112,10 +113,13 @@ class Release(BBPay):
|
|||||||
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)
|
||||||
|
if response.status_code != 200:
|
||||||
|
return 'Upstream error', response.status_code
|
||||||
data = response.json()
|
data = response.json()
|
||||||
numeroParticipante = data['repasse']['recebedores'][0]['identificadorRecebedor']
|
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')
|
valorSolicitacao = to_wei(data['valorSolicitacao'], 'ether')
|
||||||
codigoEstadoSolicitacao = data['codigoEstadoSolicitacao']
|
codigoEstadoSolicitacao = data['codigoEstadoSolicitacao']
|
||||||
if codigoEstadoSolicitacao != 1:
|
if codigoEstadoSolicitacao != 1:
|
||||||
@@ -123,7 +127,10 @@ class Release(BBPay):
|
|||||||
response = self.oauth.get(
|
response = self.oauth.get(
|
||||||
self.baseUrl+f"/participantes/{numeroParticipante}",
|
self.baseUrl+f"/participantes/{numeroParticipante}",
|
||||||
params=self.params,
|
params=self.params,
|
||||||
verify=self.verify_ssl)
|
verify=self.verify_ssl,
|
||||||
|
cert=self.cert)
|
||||||
|
if response.status_code != 200:
|
||||||
|
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) )
|
||||||
|
|||||||
Reference in New Issue
Block a user