PHP code example of dbseller / sdk-api-pix-bb

1. Go to this page and download the library: Download dbseller/sdk-api-pix-bb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dbseller / sdk-api-pix-bb example snippets


    


/*******************************************************************************************************
 * Definindo as configurações para o consumo da API Arrecadação Integrada ao PIX do BB.
 * Aqui definimos a URL para autenticação oauth2, a URL de chamada para a API ( temos teste, hmg e prd)
 * e as credenciais da aplicação, que são obtidas em app.developers.bb.com.br
 * *****************************************************************************************************/
 
$config = Swagger\Client\Configuration::getDefaultConfiguration();
$config->setAmbienteBB("T"); // em ambiente T usamos gw-dev-app-key nas requisições, em ambiente P, usamos gw-app-key.

$config->setHost("https://api.sandbox.bb.com.br/pix-bb/v1"); // HOST BB HMG 1
//$config->setHost("https://api.hm.bb.com.br/pix-bb/v1"); // HOST BB HMG 2
//$config->setHost("https://api.bb.com.br/pix-bb/v1"); // HOST BB PRODUÇÃO

$config->setUrlAutenticacaoOauth2("https://oauth.sandbox.bb.com.br/oauth/token"); //URL OAUTH BB 
//$config->setUrlAutenticacaoOauth2("https://oauth.hm.bb.com.br/oauth/token");  //URL OAUTH BB 
//$config->setUrlAutenticacaoOauth2("https://oauth.hm.bb.com.br/oauth/token");  //URL OAUTH BB PRD

//developer_application_key
$config->setChaveAplicacaoBB("d27b077907ffab60136de17dc0050656b911a5bb");
//client_id
$config->setUsername("eyJpZCI6IjJmYWRkNTYtY2QwMi00ODNhLTgiLCJjb2RpZ29QdWJsaWNhZG9yIjowLCJjb2RpZ29Tb2Z0d2FyZSI6MjIyODgsInNlcXVlbmNpYWxJbnN0YWxhY2FvIjoxfQ");
//client_secret
$config->setPassword("eyJpZCI6IjdhNjM3NTMtYjA3ZC00ODEyLWE4IiwiY29kaWdvUHVibGljYWRvciI6MCwiY29kaWdvU29mdHdhcmUiOjIyMjg4LCJzZXF1ZW5jaWFsSW5zdGFsYWNhbyI6MSwic2VxdWVuY2lhbENyZWRlbmNpYWwiOjEsImFtYmllbnRlIjoiaG9tb2xvZ2FjYW8iLCJpYXQiOjE2MzE3MzQ4MjM2MzF9");


/*********************************************************************************************
 * Obtendo access token e utilizando no configurador
 * ******************************************************************************************/
$oauth2Api = new Swagger\Client\Api\Oauth2Api(new GuzzleHttp\Client(),$config);

try {
    $token = $oauth2Api->gerarAccessToken();
    $config->setAccessToken($token);
} catch (Exception $e) {
    echo 'ERRO->', $e->getMessage(), PHP_EOL;
}

 
/*********************************************************************************************
 * Efetuando chamada a API de geração de QRCode usando o token obtido
 * ******************************************************************************************/

$apiInstance = new Swagger\Client\Api\QrCodesApi(new GuzzleHttp\Client(),$config);
$body = new \Swagger\Client\Model\ArrecadacaoqrcodesBody(); 

try {

$body['numero_convenio']=62191;
$body['indicador_codigo_barras'] = "S";
$body['codigo_guia_recebimento'] = "83660000000199800053846101172358000000000000";
$body['email_devedor'] = "[email protected]";
$body['codigo_pais_telefone_devedor'] = 55;
$body['ddd_telefone_devedor'] = 61;
$body['numero_telefone_devedor'] = "999731240";
$body['codigo_solicitacao_banco_central_brasil'] = "88a33759-78b0-43b7-8c60-e5e3e7cb55fe";
$body['descricao_solicitacao_pagamento'] = "Arrecadação Pix";
$body['valor_original_solicitacao'] = 18.98;
$body['cpf_devedor'] = "19917885250";
$body['cnpj_devedor'] = null;
$body['nome_devedor'] = "Contribuinte da Silva";
$body['quantidade_segundo_expiracao'] = 3600;
$body['lista_informacao_adicional'] = null;
$result = $apiInstance->criaBoletoBancarioId($body, $config->getAccessToken(), $config->getChaveAplicacaoBB());

} catch (Exception $e) {
  echo 'Erro na chamada QrCodesApi->criaBoletoBancarioId: ', $e->getMessage(), PHP_EOL;
}




/*******************************************************************************************************
 * Definindo as configurações para o consumo da API Arrecadação Integrada ao PIX do BB.
 * Aqui definimos a URL para autenticação oauth2, a URL de chamada para a API ( temos teste, hmg e prd)
 * e as credenciais da aplicação, que são obtidas em app.developers.bb.com.br
 * *****************************************************************************************************/
 
$config = Swagger\Client\Configuration::getDefaultConfiguration();
$config->setAmbienteBB("T"); // em ambiente T usamos gw-dev-app-key nas requisições, em ambiente P, usamos gw-app-key.

$config->setHost("https://api.sandbox.bb.com.br/pix-bb/v1"); // HOST BB HMG 1
//$config->setHost("https://api.hm.bb.com.br/pix-bb/v1"); // HOST BB HMG 2
//$config->setHost("https://api.bb.com.br/pix-bb/v1"); // HOST BB PRODUÇÃO

$config->setUrlAutenticacaoOauth2("https://oauth.sandbox.bb.com.br/oauth/token"); //URL OAUTH BB 
//$config->setUrlAutenticacaoOauth2("https://oauth.hm.bb.com.br/oauth/token");  //URL OAUTH BB 
//$config->setUrlAutenticacaoOauth2("https://oauth.hm.bb.com.br/oauth/token");  //URL OAUTH BB PRD

//developer_application_key
$config->setChaveAplicacaoBB("d27b077907ffab60136de17dc0050656b911a5bb");
//client_id
$config->setUsername("eyJpZCI6IjJmYWRkNTYtY2QwMi00ODNhLTgiLCJjb2RpZ29QdWJsaWNhZG9yIjowLCJjb2RpZ29Tb2Z0d2FyZSI6MjIyODgsInNlcXVlbmNpYWxJbnN0YWxhY2FvIjoxfQ");
//client_secret
$config->setPassword("eyJpZCI6IjdhNjM3NTMtYjA3ZC00ODEyLWE4IiwiY29kaWdvUHVibGljYWRvciI6MCwiY29kaWdvU29mdHdhcmUiOjIyMjg4LCJzZXF1ZW5jaWFsSW5zdGFsYWNhbyI6MSwic2VxdWVuY2lhbENyZWRlbmNpYWwiOjEsImFtYmllbnRlIjoiaG9tb2xvZ2FjYW8iLCJpYXQiOjE2MzE3MzQ4MjM2MzF9");


/*********************************************************************************************
 * Obtendo access token e utilizando no configurador
 * ******************************************************************************************/
$oauth2Api = new Swagger\Client\Api\Oauth2Api(new GuzzleHttp\Client(),$config);

try {
    $token = $oauth2Api->gerarAccessToken();
    $config->setAccessToken($token);
} catch (Exception $e) {
    echo 'ERRO->', $e->getMessage(), PHP_EOL;
}

 
/*********************************************************************************************
 * Efetuando chamada a API de consulta de QRCode usando o token obtido
 * ******************************************************************************************/

$apiInstance = new Swagger\Client\Api\QrCodesApi(new GuzzleHttp\Client(),$config);

try {

$numeroConvenio = 12345;
$codigoGuiaRecebimento = "54321";

$result = $apiInstance->consultaQrCodeGuiaRecolhimento($config->getAccessToken(), $config->getChaveAplicacaoBB(), $numeroConvenio, $codigoGuiaRecebimento);

} catch (Exception $e) {
  echo 'Erro na chamada QrCodesApi->consultaQrCodeGuiaRecolhimento: ', $e->getMessage(), PHP_EOL;
}



{
  "repositories": [
    {
     "type": "vcs",
	  "url": "[email protected]:tiagoskabrazil/pixbbrestclient-php.git"
    }
  ],
  "