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`
|
||||
- `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
|
||||
- O ambiente de produção requer autenticação mTLS
|
||||
- Para ambiente de desenvolvimento use `DEBUG=true`
|
||||
- Em produção, o servidor usa Waitress como servidor WSGI
|
||||
- Para mais informações, consulte a documentação oficial: https://developers.bb.com.br/
|
||||
51
bbpay.py
51
bbpay.py
@ -20,25 +20,13 @@ app = Flask(__name__)
|
||||
CORS(app)
|
||||
api = Api(app)
|
||||
|
||||
class BBPay(Resource):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setup_oauth()
|
||||
|
||||
class BBPay(Resource):
|
||||
def setup_oauth(self):
|
||||
client = BackendApplicationClient(client_id=getenv("CLIENT_ID"))
|
||||
self.oauth = OAuth2Session(client=client)
|
||||
|
||||
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=scope,
|
||||
cert='cert.pem')
|
||||
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"
|
||||
@ -49,13 +37,25 @@ class BBPay(Resource):
|
||||
# Url de produção com autenticação mTLS.
|
||||
#self.baseUrl = "https://api-bbpay.bb.com.br/checkout/v2"
|
||||
|
||||
self.verify_ssl = False
|
||||
|
||||
self.params = {
|
||||
'numeroConvenio': 701,
|
||||
'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):
|
||||
def post(self):
|
||||
data = request.get_json()
|
||||
@ -74,7 +74,7 @@ class Register(BBPay):
|
||||
params=self.params,
|
||||
json=body,
|
||||
verify=self.verify_ssl,
|
||||
cert='cert.pem')
|
||||
cert=self.cert)
|
||||
return response.json()
|
||||
|
||||
class Request(BBPay):
|
||||
@ -104,7 +104,8 @@ class Request(BBPay):
|
||||
self.baseUrl+"/solicitacoes",
|
||||
params=self.params,
|
||||
json=body,
|
||||
verify=self.verify_ssl)
|
||||
verify=self.verify_ssl,
|
||||
cert=self.cert)
|
||||
return response.json()
|
||||
|
||||
class Release(BBPay):
|
||||
@ -112,10 +113,13 @@ class Release(BBPay):
|
||||
response = self.oauth.get(
|
||||
self.baseUrl+f"/solicitacoes/{numeroSolicitacao}",
|
||||
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()
|
||||
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:
|
||||
@ -123,7 +127,10 @@ class Release(BBPay):
|
||||
response = self.oauth.get(
|
||||
self.baseUrl+f"/participantes/{numeroParticipante}",
|
||||
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']
|
||||
packed = encode_packed(['bytes32','uint80','bytes32'],
|
||||
(f"{chainID}-{numeroParticipante}".encode(), int(valorSolicitacao), pixTimestamp) )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user