diff --git a/typescript/.eslintrc.json b/.eslintrc.json similarity index 100% rename from typescript/.eslintrc.json rename to .eslintrc.json diff --git a/.github/workflows/calculate-coverage.yaml b/.github/workflows/calculate-coverage.yaml index b640a46..efd9b70 100644 --- a/.github/workflows/calculate-coverage.yaml +++ b/.github/workflows/calculate-coverage.yaml @@ -15,15 +15,12 @@ jobs: node-version: 20 - name: Install dependencies - working-directory: ./typescript run: npm install - name: Build project - working-directory: ./typescript run: npm run build - name: Execute tests - working-directory: ./typescript run: npm run test:coverage - name: Send to coveralls diff --git a/.github/workflows/on-commit-test.yaml b/.github/workflows/on-commit-test.yaml index f04162e..c1eb3b5 100644 --- a/.github/workflows/on-commit-test.yaml +++ b/.github/workflows/on-commit-test.yaml @@ -12,31 +12,10 @@ jobs: node-version: 20 - name: Install dependencies - working-directory: ./typescript run: npm install - name: Build project - working-directory: ./typescript run: npm run build - name: Execute tests - working-directory: ./typescript run: npm run test - - php-unit-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "8.2" - - - name: Install dependencies - run: composer update - - - name: Dump autoload classes - run: composer dump-autoload -o - - - name: Execute tests - run: vendor/phpunit/phpunit/phpunit -c php/phpunit.xml diff --git a/.gitignore b/.gitignore index e83bd31..90a0c16 100644 --- a/.gitignore +++ b/.gitignore @@ -121,6 +121,3 @@ lib/ # Ignore all local history of files .history .ionide - -# PHP -vendor/ diff --git a/typescript/.prettierrc.json b/.prettierrc.json similarity index 100% rename from typescript/.prettierrc.json rename to .prettierrc.json diff --git a/README.md b/README.md index 374ef4f..ee417b4 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,128 @@ -# Bling ERP API +- [Versão em PHP](https://github.com/AlexandreBellas/bling-erp-api-php/README.md) +- Versão em C# (em breve) -Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br). -O mais completo existente (e se não é, será). +# Bling ERP API - Javascript/Typescript -Disponível para: +[![](https://img.shields.io/npm/v/bling-erp-api.svg)](https://www.npmjs.com/package/bling-erp-api) +[![install size](https://packagephobia.com/badge?p=bling-erp-api)](https://packagephobia.com/result?p=bling-erp-api) +[![code coverage](https://coveralls.io/repos/github/AlexandreBellas/bling-erp-api-js/badge.svg?branch=main)](https://coveralls.io/github/AlexandreBellas/bling-erp-api?branch=main) -- [x] JavaScript ([veja a documentação](https://github.com/AlexandreBellas/bling-erp-api/tree/develop/typescript/README.md)) -- [x] TypeScript ([veja a documentação](https://github.com/AlexandreBellas/bling-erp-api/tree/develop/typescript/README.md)) -- [x] PHP ([veja a documentação](https://github.com/AlexandreBellas/bling-erp-api/tree/develop/php/README.md)) -- [ ] C# (em breve) +Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br) +para Javascript/TypeScript. O mais completo existente. -## Instalação +Atualizado com a versão `v291` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-01-31)). + +**Atenção**: a versão 5.0.0+ do `bling-erp-api` para Javascript/TypeScript +utiliza a API v3 do Bling. Caso deseja utilizar a API v2 do Bling, +[utilize a versão 4.0.0](https://github.com/AlexandreBellas/bling-erp-api-js/tree/v4.0.0). -Para instalar, execute o comando de acordo com a linguagem de programação -desejada. +## Instalação -### JavaScript / TypeScript +Para instalar, execute o comando: ```bash npm i bling-erp-api ``` -### PHP +## Importação do módulo + +### CommonJS + +```js +const Bling = require('bling-erp-api') +``` + +### ES6 + +```ts +import Bling from 'bling-erp-api' +``` + +## Criação de uma nova conexão + +Para criar uma conexão ao serviço do Bling, basta instanciar o objeto com a [API key](https://developer.bling.com.br/autenticacao) em seu construtor. + +```js +const apiKey = 'sua_api_key' +const blingConnection = new Bling(apiKey) +``` + +Vale destacar que o fluxo de criação e autorização do aplicativo **não é feito +pela biblioteca**. Ou seja, a biblioteca somente recebe o `access_token` gerado +a partir do _endpoint_ `/token`. [Veja a referência](https://developer.bling.com.br/aplicativos#tokens-de-acesso). + +Para entender na prática como a autenticação citada acima funciona, [veja o +projeto de demonstração](https://github.com/AlexandreBellas/bling-erp-api-js/tree/main/demo). + +## Entidades disponíveis + +Todas as entidades do Bling atualmente são permitidas para interação. São elas: + +- [x] Borderos (`.borderos`) +- [x] Campos customizados (`.camposCustomizados`) +- [x] Categorias - Lojas (`.categoriasLojas`) +- [x] Categorias - Produtos (`.categoriasProdutos`) +- [x] Categorias - Receitas e Despesas (`.categoriasReceitasDespesas`) +- [x] Contas a Pagar (`.contasPagar`) +- [x] Contas a Receber (`.contasReceber`) +- [x] Contas Contábeis (`.contasContabeis`) +- [x] Contatos (`.contatos`) +- [x] Contatos - Tipos (`.contatosTipos`) +- [x] Contratos (`.contratos`) +- [x] Depósitos (`.depositos`) +- [x] Empresas (`.empresas`) +- [x] Estoques (`.estoques`) +- [x] Formas de pagamento (`.formasDePagamento`) +- [x] Homologação (`.homologacao`) +- [x] Logísticas (`.logisticas`) +- [x] Logísticas - Etiquetas (`.logisticasEtiquetas`) +- [x] Logísticas - Objetos (`.logisticasObjetos`) +- [x] Logísticas - Remessas (`.logisticasRemessas`) +- [x] Logísticas - Serviços (`.logisticasServicos`) +- [x] Naturezas de Operações (`.naturezasDeOperacoes`) +- [x] Notas Fiscais de Consumidor Eletrônicas (`.nfces`) +- [x] Notas Fiscais de Serviço Eletrônicas (`.nfses`) +- [x] Notas Fiscais Eletrônicas (`.nfes`) +- [x] Notificações (`.notificacoes`) +- [x] Pedidos - Compras (`.pedidosCompras`) +- [x] Pedidos - Vendas (`.pedidosVendas`) +- [x] Produtos (`.produtos`) +- [x] Produtos - Estruturas (`.produtosEstruturas`) +- [x] Produtos - Fornecedores (`.produtosFornecedores`) +- [x] Produtos - Lojas (`.produtosLojas`) +- [x] Produtos - Variações (`.produtosVariacoes`) +- [x] Situações (`.situacoes`) +- [x] Situações - Módulos (`.situacoesModulos`) +- [x] Situações - Transições (`.situacoesTransicoes`) +- [x] Usuários (`.usuarios`) +- [x] Vendedores (`.vendedores`) + +## Exemplo de uso + +Para listar seus produtos, basta executar: + +```js +// Também disponível como: +// import Bling from 'bling-erp-api' +const Bling = require('bling-erp-api') +const apiKey = 'sua_api_key' + +const blingConnection = new Bling(apiKey) + +const products = await blingConnection.produtos.get() + +console.log(products) +``` + +## Executando os testes do projeto + +Faça o clone do projeto, instale as dependências e execute: ```bash -composer require alebatistella/bling-erp-api +npm run test ``` -## Recursos +## Contribuindo ao projeto -- [Guia de contribuição](https://github.com/AlexandreBellas/bling-erp-api/blob/v5.0.0/CONTRIBUTING.md) +- [Guia de contribuição](https://github.com/AlexandreBellas/bling-erp-api-js/blob/v5.0.0/CONTRIBUTING.md) - [Apoie o projeto](https://www.paypal.com/donate/?hosted_button_id=G2NJKZ5MUMKBS) diff --git a/typescript/demo/README.md b/demo/README.md similarity index 100% rename from typescript/demo/README.md rename to demo/README.md diff --git a/typescript/demo/index.html b/demo/index.html similarity index 100% rename from typescript/demo/index.html rename to demo/index.html diff --git a/typescript/demo/package-lock.json b/demo/package-lock.json similarity index 100% rename from typescript/demo/package-lock.json rename to demo/package-lock.json diff --git a/typescript/demo/package.json b/demo/package.json similarity index 100% rename from typescript/demo/package.json rename to demo/package.json diff --git a/typescript/demo/server.ts b/demo/server.ts similarity index 100% rename from typescript/demo/server.ts rename to demo/server.ts diff --git a/typescript/demo/tsconfig.json b/demo/tsconfig.json similarity index 100% rename from typescript/demo/tsconfig.json rename to demo/tsconfig.json diff --git a/typescript/jest.config.ts b/jest.config.ts similarity index 100% rename from typescript/jest.config.ts rename to jest.config.ts diff --git a/typescript/package-lock.json b/package-lock.json similarity index 100% rename from typescript/package-lock.json rename to package-lock.json diff --git a/typescript/package.json b/package.json similarity index 90% rename from typescript/package.json rename to package.json index 72735a4..4192013 100644 --- a/typescript/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/AlexandreBellas/bling-erp-api.git" + "url": "git+https://github.com/AlexandreBellas/bling-erp-api-js.git" }, "keywords": [ "javascript", @@ -38,9 +38,9 @@ "author": "AlexandreBellas; vitor-san", "license": "ISC", "bugs": { - "url": "https://github.com/AlexandreBellas/bling-erp-api/issues" + "url": "https://github.com/AlexandreBellas/bling-erp-api-js/issues" }, - "homepage": "https://github.com/AlexandreBellas/bling-erp-api#readme", + "homepage": "https://github.com/AlexandreBellas/bling-erp-api-js#readme", "dependencies": { "axios": "^1.6.2" }, @@ -67,4 +67,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/php/.gitattributes b/php/.gitattributes deleted file mode 100644 index 0555d1b..0000000 --- a/php/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/src/**/__tests__ export-ignore -*.spec.php export-ignore diff --git a/php/.gitignore b/php/.gitignore deleted file mode 100644 index 406abd8..0000000 --- a/php/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Dependencies -vendor/ -.phpunit.cache/ diff --git a/php/README.md b/php/README.md deleted file mode 100644 index 2207686..0000000 --- a/php/README.md +++ /dev/null @@ -1,95 +0,0 @@ -# Bling ERP API - PHP - -Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br) -para PHP 8.2+. O mais completo existente. - -Atualizado com a versão `v291` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-01-31)). - -## Instalação - -Para instalar, execute o comando: - -```bash -composer require alebatistella/bling-erp-api -``` - -## Criação de uma nova conexão - -Para criar uma conexão ao serviço do Bling, basta instanciar o objeto com a [API key](https://developer.bling.com.br/autenticacao) em seu construtor. - -```php -use AleBatistella\BlingErpApi\Bling; - -$apiKey = "sua_api_key"; -$blingConnection = new Bling($apiKey); -``` - -Vale destacar que o fluxo de criação e autorização do aplicativo **não é feito -pela biblioteca**. Ou seja, a biblioteca somente recebe o `access_token` gerado -a partir do _endpoint_ `/token`. [Veja a referência](https://developer.bling.com.br/aplicativos#tokens-de-acesso). - -## Entidades disponíveis - -Nem todas as entidades do Bling estão permitidas para interação. As atuais são: - -- [x] Borderos (`->borderos`) -- [ ] Campos customizados (`->camposCustomizados`) -- [ ] Categorias - Lojas (`->categoriasLojas`) -- [ ] Categorias - Produtos (`->categoriasProdutos`) -- [ ] Categorias - Receitas e Despesas (`->categoriasReceitasDespesas`) -- [ ] Contas a Pagar (`->contasPagar`) -- [ ] Contas a Receber (`->contasReceber`) -- [ ] Contas Contábeis (`->contasContabeis`) -- [ ] Contatos (`->contatos`) -- [ ] Contatos - Tipos (`->contatosTipos`) -- [ ] Contratos (`->contratos`) -- [ ] Depósitos (`->depositos`) -- [ ] Empresas (`->empresas`) -- [ ] Estoques (`->estoques`) -- [ ] Formas de pagamento (`->formasDePagamento`) -- [ ] Homologação (`->homologacao`) -- [ ] Logísticas (`->logisticas`) -- [ ] Logísticas - Etiquetas (`->logisticasEtiquetas`) -- [ ] Logísticas - Objetos (`->logisticasObjetos`) -- [ ] Logísticas - Remessas (`->logisticasRemessas`) -- [ ] Logísticas - Serviços (`->logisticasServicos`) -- [ ] Naturezas de Operações (`->naturezasDeOperacoes`) -- [ ] Notas Fiscais de Consumidor Eletrônicas (`->nfces`) -- [ ] Notas Fiscais de Serviço Eletrônicas (`->nfses`) -- [ ] Notas Fiscais Eletrônicas (`->nfes`) -- [ ] Notificações (`->notificacoes`) -- [ ] Pedidos - Compras (`->pedidosCompras`) -- [ ] Pedidos - Vendas (`->pedidosVendas`) -- [ ] Produtos (`->produtos`) -- [ ] Produtos - Estruturas (`->produtosEstruturas`) -- [ ] Produtos - Fornecedores (`->produtosFornecedores`) -- [ ] Produtos - Lojas (`->produtosLojas`) -- [ ] Produtos - Variações (`->produtosVariacoes`) -- [ ] Situações (`->situacoes`) -- [ ] Situações - Módulos (`->situacoesModulos`) -- [ ] Situações - Transições (`->situacoesTransicoes`) -- [ ] Usuários (`->usuarios`) -- [ ] Vendedores (`->vendedores`) - -## Exemplo de uso - -Para listar seus produtos, basta executar: - -```js -use AleBatistella\BlingErpApi\Bling; - -$apiKey = "sua_api_key"; -$blingConnection = new Bling($apiKey); - -$products = $blingConnection->produtos->get(); - -dd($products); -``` - -## Executando os testes do projeto - -Faça o clone do projeto, instale as dependências e execute: - -```bash -vendor/phpunit/phpunit/phpunit -c php/phpunit.xml -``` diff --git a/php/demo/composer.json b/php/demo/composer.json deleted file mode 100644 index c91255e..0000000 --- a/php/demo/composer.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "alebatistella/bling-erp-api-demo", - "type": "project", - "minimum-stability": "dev", - "autoload": { - "psr-4": { - "Alebatistella\\BlingErpApiDemo\\": "src/" - } - }, - "authors": [ - { - "name": "Alexandre Batistella Bellas", - "email": "alexandre.bellas@gmail.com" - } - ], - "require": { - "alebatistella/bling-erp-api": "dev-main" - } -} \ No newline at end of file diff --git a/php/demo/composer.lock b/php/demo/composer.lock deleted file mode 100644 index ce56a39..0000000 --- a/php/demo/composer.lock +++ /dev/null @@ -1,687 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "45efe585696fdb98264f4991e155a1e0", - "packages": [ - { - "name": "alebatistella/bling-erp-api", - "version": "dev-main", - "source": { - "type": "git", - "url": "https://github.com/AlexandreBellas/bling-erp-api.git", - "reference": "c46df63d657252d1b60211fab02cad406b1e6077" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/AlexandreBellas/bling-erp-api/zipball/c46df63d657252d1b60211fab02cad406b1e6077", - "reference": "c46df63d657252d1b60211fab02cad406b1e6077", - "shasum": "" - }, - "require": { - "guzzlehttp/guzzle": "^7.8" - }, - "require-dev": { - "fakerphp/faker": "^1.23", - "laravel/laravel": "^10.2", - "phpunit/phpunit": "^10.5" - }, - "default-branch": true, - "type": "library", - "autoload": { - "files": [ - "./php/src/Helpers/functions.php" - ], - "psr-4": { - "AleBatistella\\BlingErpApi\\": "./php/src/", - "AleBatistella\\BlingErpApi\\Entities\\Shared\\": "./php/src/Entities/@shared/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Alexandre Batistella Bellas", - "email": "alexandre.bellas@gmail.com" - } - ], - "description": "Pacote de integração com a API do Bling ERP", - "support": { - "issues": "https://github.com/AlexandreBellas/bling-erp-api/issues", - "source": "https://github.com/AlexandreBellas/bling-erp-api/tree/main" - }, - "funding": [ - { - "url": "https://www.paypal.com/donate/?hosted_button_id=G2NJKZ5MUMKBS", - "type": "custom" - }, - { - "url": "https://github.com/AlexandreBellas", - "type": "github" - }, - { - "url": "https://ko-fi.com/alebatistella", - "type": "ko_fi" - } - ], - "time": "2023-12-27T00:06:54+00:00" - }, - { - "name": "guzzlehttp/guzzle", - "version": "7.9.x-dev", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "41042bc7ab002487b876a0683fc8dce04ddce104" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/41042bc7ab002487b876a0683fc8dce04ddce104", - "reference": "41042bc7ab002487b876a0683fc8dce04ddce104", - "shasum": "" - }, - "require": { - "ext-json": "*", - "guzzlehttp/promises": "^1.5.3 || ^2.0.1", - "guzzlehttp/psr7": "^1.9.1 || ^2.5.1", - "php": "^7.2.5 || ^8.0", - "psr/http-client": "^1.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" - }, - "provide": { - "psr/http-client-implementation": "1.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.2", - "ext-curl": "*", - "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", - "php-http/message-factory": "^1.1", - "phpunit/phpunit": "^8.5.36 || ^9.6.15", - "psr/log": "^1.1 || ^2.0 || ^3.0" - }, - "suggest": { - "ext-curl": "Required for CURL handler support", - "ext-intl": "Required for Internationalized Domain Name (IDN) support", - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "GuzzleHttp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Jeremy Lindblom", - "email": "jeremeamia@gmail.com", - "homepage": "https://github.com/jeremeamia" - }, - { - "name": "George Mponos", - "email": "gmponos@gmail.com", - "homepage": "https://github.com/gmponos" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://github.com/sagikazarmark" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "psr-18", - "psr-7", - "rest", - "web service" - ], - "support": { - "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.8.1" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", - "type": "tidelift" - } - ], - "time": "2023-12-03T20:35:24+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "2.0.x-dev", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/bbff78d96034045e58e13dedd6ad91b5d1253223", - "reference": "bbff78d96034045e58e13dedd6ad91b5d1253223", - "shasum": "" - }, - "require": { - "php": "^7.2.5 || ^8.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.2", - "phpunit/phpunit": "^8.5.36 || ^9.6.15" - }, - "default-branch": true, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "support": { - "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.2" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", - "type": "tidelift" - } - ], - "time": "2023-12-03T20:19:20+00:00" - }, - { - "name": "guzzlehttp/psr7", - "version": "2.6.x-dev", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/45b30f99ac27b5ca93cb4831afe16285f57b8221", - "reference": "45b30f99ac27b5ca93cb4831afe16285f57b8221", - "shasum": "" - }, - "require": { - "php": "^7.2.5 || ^8.0", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.1 || ^2.0", - "ralouphie/getallheaders": "^3.0" - }, - "provide": { - "psr/http-factory-implementation": "1.0", - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.2", - "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.36 || ^9.6.15" - }, - "suggest": { - "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" - }, - "default-branch": true, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "George Mponos", - "email": "gmponos@gmail.com", - "homepage": "https://github.com/gmponos" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://github.com/sagikazarmark" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://sagikazarmark.hu" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "psr-7", - "request", - "response", - "stream", - "uri", - "url" - ], - "support": { - "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.6.2" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", - "type": "tidelift" - } - ], - "time": "2023-12-03T20:05:35+00:00" - }, - { - "name": "psr/http-client", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-client.git", - "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", - "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", - "shasum": "" - }, - "require": { - "php": "^7.0 || ^8.0", - "psr/http-message": "^1.0 || ^2.0" - }, - "default-branch": true, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Client\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP clients", - "homepage": "https://github.com/php-fig/http-client", - "keywords": [ - "http", - "http-client", - "psr", - "psr-18" - ], - "support": { - "source": "https://github.com/php-fig/http-client" - }, - "time": "2023-09-23T14:17:50+00:00" - }, - { - "name": "psr/http-factory", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-factory.git", - "reference": "7037f4b0950474e9d1350e8df89b15f1842085f6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/7037f4b0950474e9d1350e8df89b15f1842085f6", - "reference": "7037f4b0950474e9d1350e8df89b15f1842085f6", - "shasum": "" - }, - "require": { - "php": ">=7.0.0", - "psr/http-message": "^1.0 || ^2.0" - }, - "default-branch": true, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", - "keywords": [ - "factory", - "http", - "message", - "psr", - "psr-17", - "psr-7", - "request", - "response" - ], - "support": { - "source": "https://github.com/php-fig/http-factory" - }, - "time": "2023-09-22T11:16:44+00:00" - }, - { - "name": "psr/http-message", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "default-branch": true, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "support": { - "source": "https://github.com/php-fig/http-message/tree/2.0" - }, - "time": "2023-04-04T09:54:51+00:00" - }, - { - "name": "ralouphie/getallheaders", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "support": { - "issues": "https://github.com/ralouphie/getallheaders/issues", - "source": "https://github.com/ralouphie/getallheaders/tree/develop" - }, - "time": "2019-03-08T08:55:37+00:00" - }, - { - "name": "symfony/deprecation-contracts", - "version": "dev-main", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "default-branch": true, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-05-23T14:45:45+00:00" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "dev", - "stability-flags": { - "alebatistella/bling-erp-api": 20 - }, - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.6.0" -} diff --git a/php/demo/src/Main.php b/php/demo/src/Main.php deleted file mode 100644 index 28bff0c..0000000 --- a/php/demo/src/Main.php +++ /dev/null @@ -1,10 +0,0 @@ -borderos->delete(123); diff --git a/php/phpunit.xml b/php/phpunit.xml deleted file mode 100644 index 265ce67..0000000 --- a/php/phpunit.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - ./src/Entities - - - ./src/BlingTest.spec.php - - - - - - - ./src - - - ./src/Entities/@shared - ./vendor - - - \ No newline at end of file diff --git a/php/src/Bling.php b/php/src/Bling.php deleted file mode 100644 index 58e0aa3..0000000 --- a/php/src/Bling.php +++ /dev/null @@ -1,61 +0,0 @@ -repository = IoC::getRepository($accessToken); - $this->modules = []; - } - - /** - * Obtém um módulo através de sua assinatura (seguindo o _pattern_ `Instance`). - * - * @param string $entityClassName O nome da classe da entidade desejada. - * - * @return BaseEntity A instância da entidade. - */ - private function getModule(string $entityClassName): BaseEntity - { - if (!array_key_exists($entityClassName, $this->modules)) { - $this->modules[$entityClassName] = new $entityClassName($this->repository); - } - - return $this->modules[$entityClassName]; - } - - /** - * _Facade_ de busca da entidade correta. - */ - public function __get(string $name) - { - return match ($name) { - 'borderos' => $this->getModule(Borderos::class), - default => throw new BlingInternalException("A entidade \"$name\" não existe.") - }; - } -} diff --git a/php/src/BlingTest.spec.php b/php/src/BlingTest.spec.php deleted file mode 100644 index 8859e34..0000000 --- a/php/src/BlingTest.spec.php +++ /dev/null @@ -1,51 +0,0 @@ -word()); - } - - /** - * Testa a instanciação do módulo. - * - * @return void - */ - public function testShouldInstantiateCorrectly(): void - { - $expected = Bling::class; - - $actual = $this->getInstance(); - - $this->assertInstanceOf($expected, $actual); - } - - /** - * Testa obter a entidade Borderos. - * - * @return void - */ - public function testShouldGetBorderosCorrectly(): void - { - $expected = Borderos::class; - - $actual = $this->getInstance()->borderos; - - $this->assertInstanceOf($expected, $actual); - } -} diff --git a/php/src/Contracts/IResponseObject.php b/php/src/Contracts/IResponseObject.php deleted file mode 100644 index a493c88..0000000 --- a/php/src/Contracts/IResponseObject.php +++ /dev/null @@ -1,25 +0,0 @@ - ErrorField::from($item), - $attributes['fields'] - ) : null, - ); - } - - /** - * @inheritDoc - */ - public function toArray(): array - { - return [ - 'type' => $this->type, - 'message' => $this->message, - 'description' => $this->description, - 'fields' => array_map( - static fn(ErrorField $response): array => $response->toArray(), - $this->fields - ), - ]; - } -} diff --git a/php/src/Entities/@shared/DTO/Error/ErrorField.php b/php/src/Entities/@shared/DTO/Error/ErrorField.php deleted file mode 100644 index 7e5638f..0000000 --- a/php/src/Entities/@shared/DTO/Error/ErrorField.php +++ /dev/null @@ -1,63 +0,0 @@ - ErrorFieldCollection::from($item), - $attributes['collection'] - ) : null, - ); - } - - /** - * @inheritDoc - */ - public function toArray(): array - { - return [ - 'code' => $this->code, - 'msg' => $this->msg, - 'element' => $this->element, - 'namespace' => $this->namespace, - 'collection' => array_map( - static fn(ErrorFieldCollection $response): array => $response->toArray(), - $this->collection - ), - ]; - } -} diff --git a/php/src/Entities/@shared/DTO/Error/ErrorFieldCollection.php b/php/src/Entities/@shared/DTO/Error/ErrorFieldCollection.php deleted file mode 100644 index 59bb99c..0000000 --- a/php/src/Entities/@shared/DTO/Error/ErrorFieldCollection.php +++ /dev/null @@ -1,57 +0,0 @@ - $this->index, - 'code' => $this->code, - 'msg' => $this->msg, - 'element' => $this->element, - 'namespace' => $this->namespace, - ]; - } -} diff --git a/php/src/Entities/@shared/DTO/Error/ErrorResponse.php b/php/src/Entities/@shared/DTO/Error/ErrorResponse.php deleted file mode 100644 index 515ad87..0000000 --- a/php/src/Entities/@shared/DTO/Error/ErrorResponse.php +++ /dev/null @@ -1,49 +0,0 @@ -body->content); - } - - /** - * @inheritDoc - */ - public static function from(array $attributes): static - { - return new self( - error: Error::from($attributes['error']) - ); - } - - /** - * @inheritDoc - */ - public function toArray(): array - { - return [ - 'error' => $this->error->toArray(), - ]; - } -} diff --git a/php/src/Entities/@shared/DTO/Error/__tests__/ErrorResponseTest.spec.php b/php/src/Entities/@shared/DTO/Error/__tests__/ErrorResponseTest.spec.php deleted file mode 100644 index c48f853..0000000 --- a/php/src/Entities/@shared/DTO/Error/__tests__/ErrorResponseTest.spec.php +++ /dev/null @@ -1,136 +0,0 @@ -assertInstanceOf($expected, $actual); - } - - /** - * Testa a instanciação a partir de um `ResponseOptions`. - * - * @return void - */ - public function testShouldInstantiateFromResponseOptions(): void - { - $rawResponse = '{ - "error": { - "type": "VALIDATION_ERROR", - "message": "Não foi possível salvar a venda", - "description": "A venda não pode ser salva, pois ocorreram problemas em sua validação.", - "fields": [ - { - "code": 49, - "msg": "Uma ou mais parcelas da venda possuem erros de validação", - "element": "parcelas", - "namespace": "VENDAS", - "collection": [ - { - "index": 1, - "code": 12, - "msg": "Id da forma de pagamento inválido.", - "element": "formaPagamento", - "namespace": "VENDAS" - } - ] - } - ] - } - }'; - $rawResponseArray = json_decode($rawResponse, true); - $response = new class (endpoint: fake()->word(), - method: fake()->word(), - status: 200, - body: new class ($rawResponseArray) extends Body { }, - ) extends ResponseOptions { - }; - $expected = ErrorResponse::class; - - $actual = ErrorResponse::fromResponse($response); - - $this->assertInstanceOf($expected, $actual); - } - - /** - * Testa a formatação em _array_. - * - * @return void - */ - public function testShouldConvertToArray(): void - { - $rawExpected = '{ - "error": { - "type": "VALIDATION_ERROR", - "message": "Não foi possível salvar a venda", - "description": "A venda não pode ser salva, pois ocorreram problemas em sua validação.", - "fields": [ - { - "code": 49, - "msg": "Uma ou mais parcelas da venda possuem erros de validação", - "element": "parcelas", - "namespace": "VENDAS", - "collection": [ - { - "index": 1, - "code": 12, - "msg": "Id da forma de pagamento inválido.", - "element": "formaPagamento", - "namespace": "VENDAS" - } - ] - } - ] - } - }'; - $expected = json_decode($rawExpected, true); - - $actual = ErrorResponse::from($expected); - - $this->assertEquals($expected, $actual->toArray()); - } -} diff --git a/php/src/Entities/@shared/DTO/Request/Body.php b/php/src/Entities/@shared/DTO/Request/Body.php deleted file mode 100644 index c99f4b0..0000000 --- a/php/src/Entities/@shared/DTO/Request/Body.php +++ /dev/null @@ -1,20 +0,0 @@ - $content - * - * @return self - */ - public function __construct(public readonly array $content) - { - } -} diff --git a/php/src/Entities/@shared/DTO/Request/Headers.php b/php/src/Entities/@shared/DTO/Request/Headers.php deleted file mode 100644 index a2c5a60..0000000 --- a/php/src/Entities/@shared/DTO/Request/Headers.php +++ /dev/null @@ -1,18 +0,0 @@ - $content - */ - public function __construct(public array $content) - { - } -} diff --git a/php/src/Entities/@shared/DTO/Request/QueryParams.php b/php/src/Entities/@shared/DTO/Request/QueryParams.php deleted file mode 100644 index be75569..0000000 --- a/php/src/Entities/@shared/DTO/Request/QueryParams.php +++ /dev/null @@ -1,18 +0,0 @@ - $content - */ - public function __construct(public array $content) - { - } -} diff --git a/php/src/Entities/@shared/DTO/Request/RequestOptions.php b/php/src/Entities/@shared/DTO/Request/RequestOptions.php deleted file mode 100644 index 4d4d15e..0000000 --- a/php/src/Entities/@shared/DTO/Request/RequestOptions.php +++ /dev/null @@ -1,25 +0,0 @@ -= 400) { - try { - $errorResponse = ErrorResponse::fromResponse($this); - throw new BlingApiException(rawResponse: $errorResponse, status: $status); - } catch (\TypeError $e) { - throw new BlingInternalException( - message: "Não foi possível realizar a chamada HTTP: $method $endpoint", - code: $status, - previous: $e - ); - } - } - } -} diff --git a/php/src/Entities/@shared/DTO/Request/__tests__/ResponseOptionsTest.spec.php b/php/src/Entities/@shared/DTO/Request/__tests__/ResponseOptionsTest.spec.php deleted file mode 100644 index dca3667..0000000 --- a/php/src/Entities/@shared/DTO/Request/__tests__/ResponseOptionsTest.spec.php +++ /dev/null @@ -1,98 +0,0 @@ -word(), - method: fake()->word(), - status: 200 - ) extends ResponseOptions { - }; - - $this->assertInstanceOf($expected, $actual); - } - - /** - * Testa o lançamento de erro para requisição mal-sucedida e corpo esperado. - * - * @return void - */ - public function testShouldInstantiateWithErrorAndExpectedBody(): void - { - $this->expectException(BlingApiException::class); - $this->expectExceptionMessage("A venda não pode ser salva, pois ocorreram problemas em sua validação."); - $rawResponse = '{ - "error": { - "type": "VALIDATION_ERROR", - "message": "Não foi possível salvar a venda", - "description": "A venda não pode ser salva, pois ocorreram problemas em sua validação.", - "fields": [ - { - "code": 49, - "msg": "Uma ou mais parcelas da venda possuem erros de validação", - "element": "parcelas", - "namespace": "VENDAS", - "collection": [ - { - "index": 1, - "code": 12, - "msg": "Id da forma de pagamento inválido.", - "element": "formaPagamento", - "namespace": "VENDAS" - } - ] - } - ] - } - }'; - $rawResponseArray = json_decode($rawResponse, true); - - new class (endpoint: fake()->word(), - method: fake()->word(), - status: 400, - body: new class ($rawResponseArray) extends Body { } - ) extends ResponseOptions { - }; - } - - /** - * Testa o lançamento de erro para requisição mal-sucedida e corpo inesperado. - * - * @return void - */ - public function testShouldInstantiateWithErrorAndNotExpectedBody(): void - { - $endpoint = fake()->word(); - $method = fake()->word(); - $this->expectException(BlingInternalException::class); - $this->expectExceptionMessage("Não foi possível realizar a chamada HTTP: $method $endpoint"); - - new class (endpoint: $endpoint, - method: $method, - status: 400, - body: new class (['teste' => '123']) extends Body { } - ) extends ResponseOptions { - }; - } -} diff --git a/php/src/Entities/@shared/DTO/Schema/Id.php b/php/src/Entities/@shared/DTO/Schema/Id.php deleted file mode 100644 index 5c82e33..0000000 --- a/php/src/Entities/@shared/DTO/Schema/Id.php +++ /dev/null @@ -1,40 +0,0 @@ - $this->id, - ]; - } -} diff --git a/php/src/Entities/@shared/TestResponseTrait.php b/php/src/Entities/@shared/TestResponseTrait.php deleted file mode 100644 index c43f539..0000000 --- a/php/src/Entities/@shared/TestResponseTrait.php +++ /dev/null @@ -1,51 +0,0 @@ -word(), - method: $method ?? fake()->word(), - status: $status ?? fake()->numberBetween(200, 500), - headers: $headers, - body: $body, - ) extends ResponseOptions { - }; - } - - /** - * Gera um corpo de requisição. - * - * @param array $content - * - * @return Body - */ - private function buildBody(array $content): Body - { - return new class ($content) extends Body { }; - } -} diff --git a/php/src/Entities/Borderos/Borderos.php b/php/src/Entities/Borderos/Borderos.php deleted file mode 100644 index d8333b4..0000000 --- a/php/src/Entities/Borderos/Borderos.php +++ /dev/null @@ -1,55 +0,0 @@ -repository->destroy(new RequestOptions( - endpoint: "borderos/$idBordero" - )); - - return $response->body; - } - - /** - * Encontra um borderô. - * - * @param params Parâmetros para a busca (somente o ID). - * - * @return FindResponse Os dados do borderô pesquisado. - * @throws BlingApiException|BlingInternalException - * - * @see https://developer.bling.com.br/referencia#/Border%C3%B4s/get_borderos__idBordero_ - */ - public function find(int $idBordero): FindResponse - { - $response = $this->repository->show(new RequestOptions( - endpoint: "borderos/$idBordero" - )); - - return FindResponse::fromResponse($response); - } -} diff --git a/php/src/Entities/Borderos/Schema/Find/FindResponse.php b/php/src/Entities/Borderos/Schema/Find/FindResponse.php deleted file mode 100644 index 1c116fd..0000000 --- a/php/src/Entities/Borderos/Schema/Find/FindResponse.php +++ /dev/null @@ -1,50 +0,0 @@ -body->content); - } - - /** - * @inheritDoc - */ - public static function from(array $attributes): static - { - return new self( - data: FindResponseData::from($attributes['data']) - ); - } - - /** - * @inheritDoc - */ - public function toArray(): array - { - return [ - 'data' => $this->data->toArray(), - ]; - } -} diff --git a/php/src/Entities/Borderos/Schema/Find/FindResponseData.php b/php/src/Entities/Borderos/Schema/Find/FindResponseData.php deleted file mode 100644 index 5f2c5ad..0000000 --- a/php/src/Entities/Borderos/Schema/Find/FindResponseData.php +++ /dev/null @@ -1,68 +0,0 @@ - FindResponseDataPagamentos::from($item), - $attributes['pagamentos'] - ), - ); - } - - /** - * @inheritDoc - */ - public function toArray(): array - { - return [ - 'id' => $this->id, - 'data' => $this->data, - 'historico' => $this->historico, - 'portador' => $this->portador->toArray(), - 'categoria' => $this->categoria->toArray(), - 'pagamentos' => array_map( - static fn(FindResponseDataPagamentos $response): array => $response->toArray(), - $this->pagamentos - ), - ]; - } -} diff --git a/php/src/Entities/Borderos/Schema/Find/FindResponseDataPagamentos.php b/php/src/Entities/Borderos/Schema/Find/FindResponseDataPagamentos.php deleted file mode 100644 index 29401fa..0000000 --- a/php/src/Entities/Borderos/Schema/Find/FindResponseDataPagamentos.php +++ /dev/null @@ -1,66 +0,0 @@ - $this->contato->toArray(), - 'numeroDocumento' => $this->numeroDocumento, - 'valorPago' => $this->valorPago, - 'juros' => $this->juros, - 'desconto' => $this->desconto, - 'acrescimo' => $this->acrescimo, - 'tarifa' => $this->tarifa, - ]; - } -} diff --git a/php/src/Entities/Borderos/__tests__/BorderosTest.spec.php b/php/src/Entities/Borderos/__tests__/BorderosTest.spec.php deleted file mode 100644 index ce3c1fc..0000000 --- a/php/src/Entities/Borderos/__tests__/BorderosTest.spec.php +++ /dev/null @@ -1,76 +0,0 @@ -randomNumber(); - $repository = $this->getMockBuilder(IBlingRepository::class)->getMock(); - $repository->expects($this->once()) - ->method('destroy') - ->with($this->callback(fn(RequestOptions $requestOptions) => - $requestOptions->endpoint === "borderos/$idBordero" - )) - ->willReturn($this->buildResponse(status: 200, body: null)); - - /** @var IBlingRepository $repository */ - $response = $this->getInstance($repository)->delete($idBordero); - - $this->assertNull($response); - } - - /** - * Testa a busca pontual. - * - * @return void - */ - public function testShouldFindSuccessfully(): void - { - $idBordero = fake()->randomNumber(); - $findResponse = json_decode(file_get_contents(__DIR__ . '/find/response.json'), true); - $repository = $this->getMockBuilder(IBlingRepository::class)->getMock(); - $repository->expects($this->once()) - ->method('show') - ->with($this->callback(fn(RequestOptions $requestOptions) => - $requestOptions->endpoint === "borderos/$idBordero" - )) - ->willReturn($this->buildResponse(status: 200, body: $this->buildBody($findResponse))); - - /** @var IBlingRepository $repository */ - $response = $this->getInstance($repository)->find($idBordero); - - $this->assertInstanceOf(FindResponse::class, $response); - $this->assertEquals($findResponse, $response->toArray()); - } -} diff --git a/php/src/Entities/Borderos/__tests__/delete/response.json b/php/src/Entities/Borderos/__tests__/delete/response.json deleted file mode 100644 index ec747fa..0000000 --- a/php/src/Entities/Borderos/__tests__/delete/response.json +++ /dev/null @@ -1 +0,0 @@ -null \ No newline at end of file diff --git a/php/src/Entities/Borderos/__tests__/find/response.json b/php/src/Entities/Borderos/__tests__/find/response.json deleted file mode 100644 index 689b779..0000000 --- a/php/src/Entities/Borderos/__tests__/find/response.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "data": { - "id": 12345678, - "data": "2023-01-12", - "historico": "Referente ao pedido nº 12345678", - "portador": { - "id": 12345678 - }, - "categoria": { - "id": 12345678 - }, - "pagamentos": [ - { - "contato": { - "id": 12345678 - }, - "numeroDocumento": "", - "valorPago": 1500.75, - "juros": 10, - "desconto": 10, - "acrescimo": 10, - "tarifa": 10 - } - ] - } -} \ No newline at end of file diff --git a/php/src/Exceptions/BlingApiException.php b/php/src/Exceptions/BlingApiException.php deleted file mode 100644 index 8d601d7..0000000 --- a/php/src/Exceptions/BlingApiException.php +++ /dev/null @@ -1,42 +0,0 @@ -error->description, $status); - } - - /** - * Obtém a resposta da requisição. - */ - public function getResponse(): ErrorResponse - { - return $this->rawResponse; - } - - /** - * Obtém o _status_ HTTP. - * - * @return int - */ - public function getHttpStatus(): int - { - return $this->status; - } -} diff --git a/php/src/Exceptions/BlingInternalException.php b/php/src/Exceptions/BlingInternalException.php deleted file mode 100644 index 34657fd..0000000 --- a/php/src/Exceptions/BlingInternalException.php +++ /dev/null @@ -1,10 +0,0 @@ -format('Y-m-d'); - } -} - -if (!function_exists('fake')) { - /** - * Cria objeto para dados _fake_. - * - * @return \Faker\Generator - */ - function fake(): \Faker\Generator - { - return \Faker\Factory::create(); - } -} diff --git a/php/src/Providers/IoC.php b/php/src/Providers/IoC.php deleted file mode 100644 index a689dae..0000000 --- a/php/src/Providers/IoC.php +++ /dev/null @@ -1,27 +0,0 @@ -client = new Client([ - 'base_uri' => $baseUrl, - 'headers' => [ - 'Authorization' => "Bearer $accessToken", - ], - ]); - } - - /** - * @inheritDoc - */ - public function index(RequestOptions $options): ResponseOptions - { - $response = $this->client->get($options->endpoint, [ - 'query' => $options->queryParams?->content, - 'headers' => $options->headers?->content, - ]); - - return new ResponseOptions( - endpoint: $options->endpoint, - method: 'GET', - status: $response->getStatusCode(), - headers: new Headers($response->getHeaders()), - body: $this->buildResponseBody($response->getBody()->getContents()), - ); - } - - /** - * @inheritDoc - */ - public function show(RequestOptions $options): ResponseOptions - { - return $this->index($options); - } - - /** - * @inheritDoc - */ - public function store(RequestOptions $options): ResponseOptions - { - $response = $this->client->post($options->endpoint, [ - 'query' => $options->queryParams?->content, - 'json' => $options->body?->content, - 'headers' => $options->headers?->content, - ]); - - return new ResponseOptions( - endpoint: $options->endpoint, - method: 'POST', - status: $response->getStatusCode(), - headers: new Headers($response->getHeaders()), - body: $this->buildResponseBody($response->getBody()->getContents()), - ); - } - - /** - * @inheritDoc - */ - public function update(RequestOptions $options): ResponseOptions - { - $response = $this->client->patch($options->endpoint, [ - 'query' => $options->queryParams?->content, - 'json' => $options->body?->content, - 'headers' => $options->headers?->content, - ]); - - return new ResponseOptions( - endpoint: $options->endpoint, - method: 'PATCH', - status: $response->getStatusCode(), - headers: new Headers($response->getHeaders()), - body: $this->buildResponseBody($response->getBody()->getContents()), - ); - } - - /** - * @inheritDoc - */ - public function replace(RequestOptions $options): ResponseOptions - { - $response = $this->client->put($options->endpoint, [ - 'query' => $options->queryParams?->content, - 'json' => $options->body?->content, - 'headers' => $options->headers?->content, - ]); - - return new ResponseOptions( - endpoint: $options->endpoint, - method: 'PUT', - status: $response->getStatusCode(), - headers: new Headers($response->getHeaders()), - body: $this->buildResponseBody($response->getBody()->getContents()), - ); - } - - /** - * @inheritDoc - */ - public function destroy(RequestOptions $options): ResponseOptions - { - $response = $this->client->delete($options->endpoint, [ - 'query' => $options->queryParams?->content, - 'json' => $options->body?->content, - 'headers' => $options->headers?->content, - ]); - - return new ResponseOptions( - endpoint: $options->endpoint, - method: 'DELETE', - status: $response->getStatusCode(), - headers: new Headers($response->getHeaders()), - body: $this->buildResponseBody($response->getBody()->getContents()), - ); - } - - /** - * Monta o corpo da resposta. - * - * @param mixed $contents - * - * @return ?Body - */ - private function buildResponseBody(mixed $contents): ?Body - { - $body = null; - - if (!is_null($contents)) { - $arrResponseBody = json_decode($contents, true); - $body = is_array($arrResponseBody) ? new Body(json_decode($contents, true)) : null; - } - - return $body; - } -} diff --git a/php/src/Repositories/IBlingRepository.php b/php/src/Repositories/IBlingRepository.php deleted file mode 100644 index d950ce5..0000000 --- a/php/src/Repositories/IBlingRepository.php +++ /dev/null @@ -1,63 +0,0 @@ -