diff --git a/composer.json b/composer.json index d1ad9ae..40d7d09 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "ext-json": "*", "psr/log": "^1.1", "guzzlehttp/guzzle": ">=6.2", - "italodeveloper/guzzle-zend": "^1.2" + "italodeveloper/guzzle-zend": "^1.2", + "spatie/array-to-xml": "^2.11" }, "require-dev": { "phpunit/phpunit": "^6.5", diff --git a/composer.lock b/composer.lock index 8de9b5e..ec2e8cc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "40413cbe180ab1dca86190d79a3eb5e0", + "content-hash": "965ded9bddcf940613b34354a94c0553", "packages": [ { "name": "guzzlehttp/guzzle", @@ -193,6 +193,43 @@ ], "time": "2019-07-01T23:21:34+00:00" }, + { + "name": "italodeveloper/guzzle-zend", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/italodeveloper/guzzle-zend.git", + "reference": "d44434a880c345488dedc50727f7f805dd1f0820" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/italodeveloper/guzzle-zend/zipball/d44434a880c345488dedc50727f7f805dd1f0820", + "reference": "d44434a880c345488dedc50727f7f805dd1f0820", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": ">=5.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "ZendAdapter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ítalo Araújo", + "email": "italoaraujo788@gmail.com" + } + ], + "description": "Abstrai o modelo de requisição do Guzzle e transforma em Zend Http Requests XD", + "time": "2019-05-24T14:57:07+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -243,6 +280,53 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "psr/log", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2018-11-20T15:27:04+00:00" + }, { "name": "ralouphie/getallheaders", "version": "3.0.3", @@ -282,6 +366,56 @@ ], "description": "A polyfill for getallheaders.", "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "spatie/array-to-xml", + "version": "2.11.2", + "source": { + "type": "git", + "url": "https://github.com/spatie/array-to-xml.git", + "reference": "bdb5bc735b0639f6f438e935b13f7ac216239679" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/array-to-xml/zipball/bdb5bc735b0639f6f438e935b13f7ac216239679", + "reference": "bdb5bc735b0639f6f438e935b13f7ac216239679", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "php": "^7.2" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^8.0", + "spatie/phpunit-snapshot-assertions": "^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\ArrayToXml\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "role": "Developer", + "email": "freek@spatie.be", + "homepage": "https://murze.be" + } + ], + "description": "Convert an array to xml", + "homepage": "https://github.com/spatie/array-to-xml", + "keywords": [ + "array", + "convert", + "xml" + ], + "time": "2019-08-21T06:32:31+00:00" } ], "packages-dev": [ @@ -2964,53 +3098,6 @@ ], "time": "2017-02-14T16:28:37+00:00" }, - { - "name": "psr/log", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2018-11-20T15:27:04+00:00" - }, { "name": "psr/simple-cache", "version": "1.0.1", @@ -4395,26 +4482,26 @@ }, { "name": "twig/twig", - "version": "v1.42.2", + "version": "v1.42.3", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "21707d6ebd05476854805e4f91b836531941bcd4" + "reference": "201baee843e0ffe8b0b956f336dd42b2a92fae4e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/21707d6ebd05476854805e4f91b836531941bcd4", - "reference": "21707d6ebd05476854805e4f91b836531941bcd4", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/201baee843e0ffe8b0b956f336dd42b2a92fae4e", + "reference": "201baee843e0ffe8b0b956f336dd42b2a92fae4e", "shasum": "" }, "require": { - "php": ">=5.4.0", + "php": ">=5.5.0", "symfony/polyfill-ctype": "^1.8" }, "require-dev": { "psr/container": "^1.0", - "symfony/debug": "^2.7", - "symfony/phpunit-bridge": "^3.4.19|^4.1.8|^5.0" + "symfony/debug": "^3.4|^4.2", + "symfony/phpunit-bridge": "^4.4@dev|^5.0" }, "type": "library", "extra": { @@ -4441,15 +4528,15 @@ "email": "fabien@symfony.com", "homepage": "http://fabien.potencier.org" }, - { - "name": "Armin Ronacher", - "role": "Project Founder", - "email": "armin.ronacher@active-4.com" - }, { "name": "Twig Team", "role": "Contributors", "homepage": "https://twig.symfony.com/contributors" + }, + { + "name": "Armin Ronacher", + "role": "Project Founder", + "email": "armin.ronacher@active-4.com" } ], "description": "Twig, the flexible, fast, and secure template language for PHP", @@ -4457,20 +4544,20 @@ "keywords": [ "templating" ], - "time": "2019-06-18T15:35:16+00:00" + "time": "2019-08-24T12:51:03+00:00" }, { "name": "zendframework/zend-cache", - "version": "2.8.2", + "version": "2.8.3", "source": { "type": "git", "url": "https://github.com/zendframework/zend-cache.git", - "reference": "4983dff629956490c78b88adcc8ece4711d7d8a3" + "reference": "edde41f1ee5c28e01701a032f434d03751b65df4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-cache/zipball/4983dff629956490c78b88adcc8ece4711d7d8a3", - "reference": "4983dff629956490c78b88adcc8ece4711d7d8a3", + "url": "https://api.github.com/repos/zendframework/zend-cache/zipball/edde41f1ee5c28e01701a032f434d03751b65df4", + "reference": "edde41f1ee5c28e01701a032f434d03751b65df4", "shasum": "" }, "require": { @@ -4540,7 +4627,7 @@ "psr-6", "zf" ], - "time": "2018-05-01T21:58:00+00:00" + "time": "2019-08-28T21:34:32+00:00" }, { "name": "zendframework/zend-config", @@ -4598,6 +4685,51 @@ ], "time": "2016-02-04T23:01:10+00:00" }, + { + "name": "zendframework/zend-escaper", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-escaper.git", + "reference": "31d8aafae982f9568287cb4dce987e6aff8fd074" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-escaper/zipball/31d8aafae982f9568287cb4dce987e6aff8fd074", + "reference": "31d8aafae982f9568287cb4dce987e6aff8fd074", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2", + "zendframework/zend-coding-standard": "~1.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6.x-dev", + "dev-develop": "2.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Escaper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs", + "keywords": [ + "ZendFramework", + "escaper", + "zf" + ], + "time": "2018-04-25T15:48:53+00:00" + }, { "name": "zendframework/zend-eventmanager", "version": "3.2.1", @@ -4717,6 +4849,61 @@ ], "time": "2019-08-19T07:08:04+00:00" }, + { + "name": "zendframework/zend-http", + "version": "2.8.4", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-http.git", + "reference": "d160aedc096be230af0fe9c31151b2b33ad4e807" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-http/zipball/d160aedc096be230af0fe9c31151b2b33ad4e807", + "reference": "d160aedc096be230af0fe9c31151b2b33ad4e807", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0", + "zendframework/zend-loader": "^2.5.1", + "zendframework/zend-stdlib": "^3.1 || ^2.7.7", + "zendframework/zend-uri": "^2.5.2", + "zendframework/zend-validator": "^2.10.1" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.3", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-config": "^3.1 || ^2.6" + }, + "suggest": { + "paragonie/certainty": "For automated management of cacert.pem" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8.x-dev", + "dev-develop": "2.9.x-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Http\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests", + "keywords": [ + "ZendFramework", + "http", + "http client", + "zend", + "zf" + ], + "time": "2019-02-07T17:47:08+00:00" + }, { "name": "zendframework/zend-hydrator", "version": "1.1.0", @@ -4893,6 +5080,51 @@ ], "time": "2019-06-18T10:54:52+00:00" }, + { + "name": "zendframework/zend-loader", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-loader.git", + "reference": "78f11749ea340f6ca316bca5958eef80b38f9b6c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-loader/zipball/78f11749ea340f6ca316bca5958eef80b38f9b6c", + "reference": "78f11749ea340f6ca316bca5958eef80b38f9b6c", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.4", + "zendframework/zend-coding-standard": "~1.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6.x-dev", + "dev-develop": "2.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Loader\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Autoloading and plugin loading strategies", + "keywords": [ + "ZendFramework", + "loader", + "zf" + ], + "time": "2018-04-30T15:20:54+00:00" + }, { "name": "zendframework/zend-serializer", "version": "2.9.0", @@ -5061,6 +5293,126 @@ ], "time": "2016-04-12T21:17:31+00:00" }, + { + "name": "zendframework/zend-uri", + "version": "2.7.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-uri.git", + "reference": "b2785cd38fe379a784645449db86f21b7739b1ee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-uri/zipball/b2785cd38fe379a784645449db86f21b7739b1ee", + "reference": "b2785cd38fe379a784645449db86f21b7739b1ee", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0", + "zendframework/zend-escaper": "^2.5", + "zendframework/zend-validator": "^2.10" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.4", + "zendframework/zend-coding-standard": "~1.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7.x-dev", + "dev-develop": "2.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Zend\\Uri\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "A component that aids in manipulating and validating » Uniform Resource Identifiers (URIs)", + "keywords": [ + "ZendFramework", + "uri", + "zf" + ], + "time": "2019-02-27T21:39:04+00:00" + }, + { + "name": "zendframework/zend-validator", + "version": "2.11.1", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-validator.git", + "reference": "3c28dfe4e5951ba38059cea895244d9d206190b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-validator/zipball/3c28dfe4e5951ba38059cea895244d9d206190b3", + "reference": "3c28dfe4e5951ba38059cea895244d9d206190b3", + "shasum": "" + }, + "require": { + "container-interop/container-interop": "^1.1", + "php": "^5.6 || ^7.0", + "zendframework/zend-stdlib": "^2.7.6 || ^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.0.8 || ^5.7.15", + "psr/http-message": "^1.0", + "zendframework/zend-cache": "^2.6.1", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-config": "^2.6", + "zendframework/zend-db": "^2.7", + "zendframework/zend-filter": "^2.6", + "zendframework/zend-http": "^2.5.4", + "zendframework/zend-i18n": "^2.6", + "zendframework/zend-math": "^2.6", + "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", + "zendframework/zend-session": "^2.8", + "zendframework/zend-uri": "^2.5" + }, + "suggest": { + "psr/http-message": "psr/http-message, required when validating PSR-7 UploadedFileInterface instances via the Upload and UploadFile validators", + "zendframework/zend-db": "Zend\\Db component, required by the (No)RecordExists validator", + "zendframework/zend-filter": "Zend\\Filter component, required by the Digits validator", + "zendframework/zend-i18n": "Zend\\I18n component to allow translation of validation error messages", + "zendframework/zend-i18n-resources": "Translations of validator messages", + "zendframework/zend-math": "Zend\\Math component, required by the Csrf validator", + "zendframework/zend-servicemanager": "Zend\\ServiceManager component to allow using the ValidatorPluginManager and validator chains", + "zendframework/zend-session": "Zend\\Session component, ^2.8; required by the Csrf validator", + "zendframework/zend-uri": "Zend\\Uri component, required by the Uri and Sitemap\\Loc validators" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.11.x-dev", + "dev-develop": "2.12.x-dev" + }, + "zf": { + "component": "Zend\\Validator", + "config-provider": "Zend\\Validator\\ConfigProvider" + } + }, + "autoload": { + "psr-4": { + "Zend\\Validator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "provides a set of commonly needed validators", + "homepage": "https://github.com/zendframework/zend-validator", + "keywords": [ + "validator", + "zf2" + ], + "time": "2019-01-29T22:26:39+00:00" + }, { "name": "zetacomponents/base", "version": "1.9.1", @@ -5182,6 +5534,10 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "php": ">=5.5", + "ext-curl": "*", + "ext-json": "*" + }, "platform-dev": [] } diff --git a/src/Core/Bling.php b/src/Core/Bling.php index f410bd5..44ba961 100644 --- a/src/Core/Bling.php +++ b/src/Core/Bling.php @@ -36,14 +36,9 @@ public function __construct(array $configurations) */ private function getBundles() { - // return [ - // Marketplace\Transactions::class, - // MarketPlace\Sellers::class, - // WebHook\WebHook::class, - // MarketPlace\Buyers::class, - // Payment\CreditCard::class, - // Payment\Ticket::class - // ]; + return [ + Contato\Contatos::class + ]; } /** diff --git a/src/Core/Config.php b/src/Core/Config.php index e52d46e..b0ec7cf 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -12,7 +12,7 @@ * @method Bling/Core/Config::configure(string $token, string $marketplace, string $vendedor) * * @package Bling/Core - * @author italodeveloper + * @author Andre Bellafronte * @version 1.0.0 */ class Config diff --git a/src/Resources/Contato/Contatos.php b/src/Resources/Contato/Contatos.php new file mode 100644 index 0000000..739bdd7 --- /dev/null +++ b/src/Resources/Contato/Contatos.php @@ -0,0 +1,127 @@ + + * @version 1.0.0 + */ +class Contatos extends Bling +{ + public function __construct(array $configurations) + { + parent::__construct($configurations); + } + + /** + * createContato function + * + * Cria o contato dentro do Bling + * + * @param array $contatoData + * @see https://manuais.bling.com.br/manual/?item=contatos#POSTcontato + * @return bool|array + * @throws \Exception + */ + public function createContato(array $contatoData) + { + try { + $request = $this->configurations['guzzle']->request( + 'POST', '/contato/json/', + ['query' => ['xml' => $contatoData]] + ); + $response = \json_decode($request->getBody()->getContents(), true); + if($response && is_array($response)){ + return $response; + } + return false; + } catch (\Exception $e){ + return $this->ResponseException($e); + } + } + + /** + * getAllContatos function + * + * Lista todos os contatos no Bling + * + * @return bool|array + * @throws \Exception + */ + public function getAllContatos() + { + try { + $request = $this->configurations['guzzle']->request( + 'GET', '/contatos/json/' + ); + $response = \json_decode($request->getBody()->getContents(), true); + if($response && is_array($response)){ + return $response; + } + return false; + } catch (\Exception $e){ + return $this->ResponseException($e); + } + } + + /** + * function getContato + * + * Pega os dados do contato associado + * ao CPF ou CNPJ passado como parametro. + * + * @param string $cpfCnpj + * + * @return bool|array + * @throws \Exception + */ + public function getContato($cpfCnpj) + { + try { + $request = $this->configurations['guzzle']->request( + 'GET', '/contato/' . $cpfCnpj . '/json/' + ); + $response = \json_decode($request->getBody()->getContents(), true); + if($response && is_array($response)){ + return $response; + } + return false; + } catch (\Exception $e){ + return $this->ResponseException($e); + } + } + + /** + * updateContato function + * + * Atualiza um contato no Bling com novo array de dados buscando por seu ID + * + * + * @param $userId + * + * @return bool|mixed|void + * @throws \Exception + */ + public function updateContato($contatoId, $contatoData) + { + try { + $request = $this->configurations['guzzle']->request( + 'PUT', '/contato/'. $contatoId .'/json/', + ['query' => ['xml' => $contatoData]] + ); + $response = \json_decode($request->getBody()->getContents(), true); + if($response && is_array($response)){ + return $response; + } + return false; + } catch (\Exception $e){ + return $this->ResponseException($e); + } + } +}