├── .github └── ISSUE_TEMPLATE │ └── feature_request.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE.md ├── README.md ├── _config.yml ├── composer.json ├── composer.lock └── src ├── Core ├── Config.php └── Zoop.php ├── Resources ├── MarketPlace │ ├── Buyers.php │ ├── Sellers.php │ └── Transactions.php ├── Payment │ ├── CreditCard.php │ └── Ticket.php └── WebHook │ └── WebHook.php └── ZoopClient.php /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | vendor/ 3 | public/ -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at italoaraujo788@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ítalo Araújo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![alt text](https://zoop.co/dist/imgs/zoop-logo3.png "Logo Zoop") 2 | 3 | # Zoop SDK - PHP :elephant: 4 | SDK Não oficial Zoop PHP, para realizar integração com o gateway de pagamento. 5 | 6 | Observação a contribuidores: só será mergido bundles com o mesmo padrão de projeto, não repita nomes de funções dentro dos novos bundles para não confitar com os atuais. 7 | 8 | instalando via composer 9 | ``` 10 | composer require italodeveloper/zoop-sdk 11 | ``` 12 | 13 | ## Criando o cliente para realizar as operações da Zoop 14 | ``` php 15 | getAllTransactions(); 35 | print_r($listarTransacoes); 36 | #var_dump($listarTransacoes); 37 | } catch (\Exception $e) { 38 | echo $e->getMessage() . PHP_EOL; 39 | } 40 | ``` 41 | Para as demais funções, acesse nossa wiki e confira: 42 | [Zoop SDK Wiki](https://github.com/italodeveloper/zoop-sdk/wiki). 43 | 44 | Desenvolvido com :heart: por [italodeveloper](https://www.linkedin.com/in/%C3%ADtalo-araujo/) e contribuidores. 45 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "italodeveloper/zoop-sdk", 3 | "description": "SDK de pagamentos Zoop", 4 | "license": "MIT", 5 | "type": "library", 6 | "keywords": [ 7 | "italodeveloper", 8 | "zoop", 9 | "payment", 10 | "gateway " 11 | ], 12 | "authors": [ 13 | { 14 | "name": "Ítalo Araújo", 15 | "email": "italoaraujo@gmail.com" 16 | } 17 | ], 18 | "config": { 19 | "optimize-autoloader": true 20 | }, 21 | "require": { 22 | "php": ">=5.5", 23 | "ext-curl": "*", 24 | "ext-json": "*", 25 | "psr/log": "^1.1", 26 | "guzzlehttp/guzzle": ">=6.2", 27 | "italodeveloper/guzzle-zend": "^1.2" 28 | }, 29 | "require-dev": { 30 | "zendframework/zend-http": ">=2.5" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Zoop\\": "src/" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "9b8f9f6709166ea8241e431f594c6d60", 8 | "packages": [ 9 | { 10 | "name": "guzzlehttp/guzzle", 11 | "version": "6.3.3", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/guzzle/guzzle.git", 15 | "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", 20 | "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "guzzlehttp/promises": "^1.0", 25 | "guzzlehttp/psr7": "^1.4", 26 | "php": ">=5.5" 27 | }, 28 | "require-dev": { 29 | "ext-curl": "*", 30 | "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", 31 | "psr/log": "^1.0" 32 | }, 33 | "suggest": { 34 | "psr/log": "Required for using the Log middleware" 35 | }, 36 | "type": "library", 37 | "extra": { 38 | "branch-alias": { 39 | "dev-master": "6.3-dev" 40 | } 41 | }, 42 | "autoload": { 43 | "files": [ 44 | "src/functions_include.php" 45 | ], 46 | "psr-4": { 47 | "GuzzleHttp\\": "src/" 48 | } 49 | }, 50 | "notification-url": "https://packagist.org/downloads/", 51 | "license": [ 52 | "MIT" 53 | ], 54 | "authors": [ 55 | { 56 | "name": "Michael Dowling", 57 | "email": "mtdowling@gmail.com", 58 | "homepage": "https://github.com/mtdowling" 59 | } 60 | ], 61 | "description": "Guzzle is a PHP HTTP client library", 62 | "homepage": "http://guzzlephp.org/", 63 | "keywords": [ 64 | "client", 65 | "curl", 66 | "framework", 67 | "http", 68 | "http client", 69 | "rest", 70 | "web service" 71 | ], 72 | "time": "2018-04-22T15:46:56+00:00" 73 | }, 74 | { 75 | "name": "guzzlehttp/promises", 76 | "version": "v1.3.1", 77 | "source": { 78 | "type": "git", 79 | "url": "https://github.com/guzzle/promises.git", 80 | "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" 81 | }, 82 | "dist": { 83 | "type": "zip", 84 | "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", 85 | "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", 86 | "shasum": "" 87 | }, 88 | "require": { 89 | "php": ">=5.5.0" 90 | }, 91 | "require-dev": { 92 | "phpunit/phpunit": "^4.0" 93 | }, 94 | "type": "library", 95 | "extra": { 96 | "branch-alias": { 97 | "dev-master": "1.4-dev" 98 | } 99 | }, 100 | "autoload": { 101 | "psr-4": { 102 | "GuzzleHttp\\Promise\\": "src/" 103 | }, 104 | "files": [ 105 | "src/functions_include.php" 106 | ] 107 | }, 108 | "notification-url": "https://packagist.org/downloads/", 109 | "license": [ 110 | "MIT" 111 | ], 112 | "authors": [ 113 | { 114 | "name": "Michael Dowling", 115 | "email": "mtdowling@gmail.com", 116 | "homepage": "https://github.com/mtdowling" 117 | } 118 | ], 119 | "description": "Guzzle promises library", 120 | "keywords": [ 121 | "promise" 122 | ], 123 | "time": "2016-12-20T10:07:11+00:00" 124 | }, 125 | { 126 | "name": "guzzlehttp/psr7", 127 | "version": "1.5.2", 128 | "source": { 129 | "type": "git", 130 | "url": "https://github.com/guzzle/psr7.git", 131 | "reference": "9f83dded91781a01c63574e387eaa769be769115" 132 | }, 133 | "dist": { 134 | "type": "zip", 135 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", 136 | "reference": "9f83dded91781a01c63574e387eaa769be769115", 137 | "shasum": "" 138 | }, 139 | "require": { 140 | "php": ">=5.4.0", 141 | "psr/http-message": "~1.0", 142 | "ralouphie/getallheaders": "^2.0.5" 143 | }, 144 | "provide": { 145 | "psr/http-message-implementation": "1.0" 146 | }, 147 | "require-dev": { 148 | "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" 149 | }, 150 | "type": "library", 151 | "extra": { 152 | "branch-alias": { 153 | "dev-master": "1.5-dev" 154 | } 155 | }, 156 | "autoload": { 157 | "psr-4": { 158 | "GuzzleHttp\\Psr7\\": "src/" 159 | }, 160 | "files": [ 161 | "src/functions_include.php" 162 | ] 163 | }, 164 | "notification-url": "https://packagist.org/downloads/", 165 | "license": [ 166 | "MIT" 167 | ], 168 | "authors": [ 169 | { 170 | "name": "Michael Dowling", 171 | "email": "mtdowling@gmail.com", 172 | "homepage": "https://github.com/mtdowling" 173 | }, 174 | { 175 | "name": "Tobias Schultze", 176 | "homepage": "https://github.com/Tobion" 177 | } 178 | ], 179 | "description": "PSR-7 message implementation that also provides common utility methods", 180 | "keywords": [ 181 | "http", 182 | "message", 183 | "psr-7", 184 | "request", 185 | "response", 186 | "stream", 187 | "uri", 188 | "url" 189 | ], 190 | "time": "2018-12-04T20:46:45+00:00" 191 | }, 192 | { 193 | "name": "italodeveloper/guzzle-zend", 194 | "version": "1.2", 195 | "source": { 196 | "type": "git", 197 | "url": "https://github.com/italodeveloper/guzzle-zend.git", 198 | "reference": "51e3148fd60f24ffe59d04a5fc1f999ad0e94e81" 199 | }, 200 | "dist": { 201 | "type": "zip", 202 | "url": "https://api.github.com/repos/italodeveloper/guzzle-zend/zipball/51e3148fd60f24ffe59d04a5fc1f999ad0e94e81", 203 | "reference": "51e3148fd60f24ffe59d04a5fc1f999ad0e94e81", 204 | "shasum": "" 205 | }, 206 | "require": { 207 | "ext-curl": "*", 208 | "php": ">=5.5" 209 | }, 210 | "type": "library", 211 | "autoload": { 212 | "psr-4": { 213 | "ZendAdapter\\": "src/" 214 | } 215 | }, 216 | "notification-url": "https://packagist.org/downloads/", 217 | "license": [ 218 | "MIT" 219 | ], 220 | "authors": [ 221 | { 222 | "name": "Ítalo Araújo", 223 | "email": "italoaraujo788@gmail.com" 224 | } 225 | ], 226 | "description": "Abstrai o modelo de requisição do Guzzle e transforma em Zend Http Requests XD", 227 | "time": "2019-05-21T17:59:31+00:00" 228 | }, 229 | { 230 | "name": "psr/http-message", 231 | "version": "1.0.1", 232 | "source": { 233 | "type": "git", 234 | "url": "https://github.com/php-fig/http-message.git", 235 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" 236 | }, 237 | "dist": { 238 | "type": "zip", 239 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", 240 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", 241 | "shasum": "" 242 | }, 243 | "require": { 244 | "php": ">=5.3.0" 245 | }, 246 | "type": "library", 247 | "extra": { 248 | "branch-alias": { 249 | "dev-master": "1.0.x-dev" 250 | } 251 | }, 252 | "autoload": { 253 | "psr-4": { 254 | "Psr\\Http\\Message\\": "src/" 255 | } 256 | }, 257 | "notification-url": "https://packagist.org/downloads/", 258 | "license": [ 259 | "MIT" 260 | ], 261 | "authors": [ 262 | { 263 | "name": "PHP-FIG", 264 | "homepage": "http://www.php-fig.org/" 265 | } 266 | ], 267 | "description": "Common interface for HTTP messages", 268 | "homepage": "https://github.com/php-fig/http-message", 269 | "keywords": [ 270 | "http", 271 | "http-message", 272 | "psr", 273 | "psr-7", 274 | "request", 275 | "response" 276 | ], 277 | "time": "2016-08-06T14:39:51+00:00" 278 | }, 279 | { 280 | "name": "psr/log", 281 | "version": "1.1.0", 282 | "source": { 283 | "type": "git", 284 | "url": "https://github.com/php-fig/log.git", 285 | "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" 286 | }, 287 | "dist": { 288 | "type": "zip", 289 | "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", 290 | "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", 291 | "shasum": "" 292 | }, 293 | "require": { 294 | "php": ">=5.3.0" 295 | }, 296 | "type": "library", 297 | "extra": { 298 | "branch-alias": { 299 | "dev-master": "1.0.x-dev" 300 | } 301 | }, 302 | "autoload": { 303 | "psr-4": { 304 | "Psr\\Log\\": "Psr/Log/" 305 | } 306 | }, 307 | "notification-url": "https://packagist.org/downloads/", 308 | "license": [ 309 | "MIT" 310 | ], 311 | "authors": [ 312 | { 313 | "name": "PHP-FIG", 314 | "homepage": "http://www.php-fig.org/" 315 | } 316 | ], 317 | "description": "Common interface for logging libraries", 318 | "homepage": "https://github.com/php-fig/log", 319 | "keywords": [ 320 | "log", 321 | "psr", 322 | "psr-3" 323 | ], 324 | "time": "2018-11-20T15:27:04+00:00" 325 | }, 326 | { 327 | "name": "ralouphie/getallheaders", 328 | "version": "2.0.5", 329 | "source": { 330 | "type": "git", 331 | "url": "https://github.com/ralouphie/getallheaders.git", 332 | "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" 333 | }, 334 | "dist": { 335 | "type": "zip", 336 | "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", 337 | "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", 338 | "shasum": "" 339 | }, 340 | "require": { 341 | "php": ">=5.3" 342 | }, 343 | "require-dev": { 344 | "phpunit/phpunit": "~3.7.0", 345 | "satooshi/php-coveralls": ">=1.0" 346 | }, 347 | "type": "library", 348 | "autoload": { 349 | "files": [ 350 | "src/getallheaders.php" 351 | ] 352 | }, 353 | "notification-url": "https://packagist.org/downloads/", 354 | "license": [ 355 | "MIT" 356 | ], 357 | "authors": [ 358 | { 359 | "name": "Ralph Khattar", 360 | "email": "ralph.khattar@gmail.com" 361 | } 362 | ], 363 | "description": "A polyfill for getallheaders.", 364 | "time": "2016-02-11T07:05:27+00:00" 365 | } 366 | ], 367 | "packages-dev": [], 368 | "aliases": [], 369 | "minimum-stability": "stable", 370 | "stability-flags": [], 371 | "prefer-stable": false, 372 | "prefer-lowest": false, 373 | "platform": { 374 | "php": ">=5.5", 375 | "ext-curl": "*", 376 | "ext-json": "*" 377 | }, 378 | "platform-dev": [] 379 | } 380 | -------------------------------------------------------------------------------- /src/Core/Config.php: -------------------------------------------------------------------------------- 1 | 16 | * @version 1.0.0 17 | */ 18 | class Config 19 | { 20 | public static function configure($token, $marketplace, $vendedor, $is_zend = null) 21 | { 22 | $configurations = [ 23 | 'marketplace' => $marketplace, 24 | 'gatway' => 'zoop', 25 | 'base_url' => 'https://api.zoop.ws', 26 | 'auth' => [ 27 | 'on_behalf_of' => $vendedor, 28 | 'token' => $token 29 | ], 30 | 'configurations' => [ 31 | 'limit' => 20, 32 | 'sort' => 'time-descending', 33 | 'offset' => 0, 34 | 'date_range' => null, 35 | 'date_range[gt]' => null, 36 | 'date_range[gte]' => null, 37 | 'date_range[lt]'=> null, 38 | 'date_range[lte]' => null, 39 | 'reference_id'=> null, 40 | 'status' => null, 41 | 'payment_type' => null, 42 | ], 43 | 'guzzle' => [ 44 | 'base_uri' => 'https://api.zoop.ws', 45 | 'timeout' => 10, 46 | 'headers' => [ 47 | 'Authorization' => 'Basic ' . \base64_encode($token . ':') 48 | ] 49 | ] 50 | ]; 51 | return self::ClientHelper($configurations, $is_zend); 52 | } 53 | 54 | private static function ClientHelper(array $configurations, $is_zend = null) 55 | { 56 | $client = $configurations['guzzle']; 57 | unset($configurations['guzzle']); 58 | if(\is_null($is_zend)){ 59 | $configurations['guzzle'] = new \GuzzleHttp\Client($client); 60 | } else { 61 | $configurations['guzzle'] = new \ZendAdapter\ZendRequest($client); 62 | } 63 | return $configurations; 64 | } 65 | } -------------------------------------------------------------------------------- /src/Core/Zoop.php: -------------------------------------------------------------------------------- 1 | 16 | * @version 1.0.0 17 | */ 18 | abstract class Zoop 19 | { 20 | /** @var $configurations */ 21 | public $configurations; 22 | /** @var $namespace */ 23 | private $namespace; 24 | 25 | public function __construct(array $configurations) 26 | { 27 | $this->configurations = $configurations; 28 | $this->namespace = __NAMESPACE__ . '\\'; 29 | } 30 | 31 | /** 32 | * function getBundles 33 | * 34 | * Registra todas as classes da biblioteca 35 | * em um array para serem listados para utilização 36 | * 37 | * @return array 38 | */ 39 | private function getBundles() 40 | { 41 | return [ 42 | Marketplace\Transactions::class, 43 | MarketPlace\Sellers::class, 44 | WebHook\WebHook::class, 45 | MarketPlace\Buyers::class, 46 | Payment\CreditCard::class, 47 | Payment\Ticket::class 48 | ]; 49 | } 50 | 51 | /** 52 | * checkBundlesRepeat function 53 | * 54 | * Lista todos os bundles registados para observar se não existem funções 55 | * que se sobrescrevem 56 | * 57 | * @return array 58 | */ 59 | public function checkBundlesRepeat() 60 | { 61 | $bundles = $this->getAllBundle(); 62 | unset($bundles['binary']); 63 | return $bundles; 64 | } 65 | 66 | /** 67 | * getBundle function 68 | * 69 | * Pega o noem do Bundle dono da função 70 | * que foi requisitada 71 | * 72 | * @param array $bundles 73 | * @param string $function 74 | * @return string|bool 75 | */ 76 | private function getBundle(array $bundles, $function) 77 | { 78 | unset($bundles['binary']); 79 | 80 | foreach ($bundles as $bundleKey => $bundleMethods) { 81 | if(\in_array($function, $bundleMethods)){ 82 | return $bundleKey; 83 | } 84 | } 85 | return false; 86 | } 87 | 88 | /** 89 | * getAllBundle function 90 | * 91 | * Lista todos os metodos que estão dentro dos Bundles 92 | * registados e lista todos os bundles também para serem 93 | * reutilizados. 94 | * 95 | * @return array 96 | */ 97 | private function getAllBundle() 98 | { 99 | $bundlesArray = array('binary' => array()); 100 | $bundles = $this->getBundles(); 101 | foreach ($bundles as $bundle) { 102 | if(!isset($bundlesArray[$bundle])){ 103 | $bundlesArray[$bundle] = array(); 104 | } 105 | } 106 | foreach ($bundlesArray as $bundleKey => $bundle) { 107 | $bundleMethods = \get_class_methods($bundleKey); 108 | if(is_array($bundleMethods) && !empty($bundleMethods)){ 109 | foreach ($bundleMethods as $method) { 110 | if($method != '__construct' 111 | && $method != '__call' 112 | && $method != 'hookBundle' 113 | && $method != 'getAllBundle' 114 | && $method != 'getBundle' 115 | && $method != 'getBundles' 116 | && $method != 'ResponseException' 117 | ){ 118 | $bundlesArray[$bundleKey][] = $method; 119 | $bundlesArray['binary'][] = $method; 120 | } 121 | } 122 | } 123 | } 124 | return $bundlesArray; 125 | } 126 | 127 | /** 128 | * hookBundle function 129 | * 130 | * @param string $class 131 | * @param string $method 132 | * @param $params 133 | * @return mixed|bool 134 | */ 135 | private function hookBundle($class, $method, $params) 136 | { 137 | $metodos = \get_class_methods($class); 138 | if(in_array($method, $metodos)){ 139 | return call_user_func_array(array(new $class($this->configurations), $method), $params); 140 | } 141 | return false; 142 | } 143 | 144 | /** 145 | * gunction __call 146 | * 147 | * Pega metodos que estão fora dessa classe 148 | * porem que pertencem ao namespace e estão 149 | * registados no registro de bundles acima 150 | * e utiliza de funções especiais para habiliar 151 | * esses metodos fora dessas classes 152 | * 153 | * @param [type] $name 154 | * @param [type] $arguments 155 | * @return bool|mixed 156 | */ 157 | public function __call($name, $arguments) 158 | { 159 | $bundles = $this->getAllBundle(); 160 | if(!in_array($name, $bundles['binary'])){ 161 | return false; 162 | } 163 | $bundle = $this->getBundle($bundles, $name); 164 | if(!$bundle){ 165 | return false; 166 | } 167 | return $this->hookBundle($bundle, $name, $arguments); 168 | } 169 | 170 | public function ResponseException(\Exception $e) 171 | { 172 | if(!in_array('getResponse', \get_class_methods($e))){ 173 | throw new \Exception($e->getMessage(), 1); 174 | } 175 | throw new \Exception(\json_encode(\json_decode($e->getResponse()->getBody()->getContents(), true)), 1); 176 | } 177 | } -------------------------------------------------------------------------------- /src/Resources/MarketPlace/Buyers.php: -------------------------------------------------------------------------------- 1 | 13 | * @version 1.0.0 14 | */ 15 | class Buyers extends Zoop 16 | { 17 | public function __construct(array $configurations) 18 | { 19 | parent::__construct($configurations); 20 | } 21 | 22 | /** 23 | * createBuyer function 24 | * 25 | * Cria o usuario dentro do markeplace ('não é associado ao vendedor') 26 | * 27 | * @param array $user 28 | * 29 | * @return bool|array 30 | * @throws \Exception 31 | */ 32 | public function createBuyer(array $user) 33 | { 34 | try { 35 | $request = $this->configurations['guzzle']->request( 36 | 'POST', '/v1/marketplaces/'. $this->configurations['marketplace']. '/buyers', 37 | ['json' => $user] 38 | ); 39 | $response = \json_decode($request->getBody()->getContents(), true); 40 | if($response && is_array($response)){ 41 | return $response; 42 | } 43 | return false; 44 | } catch (\Exception $e){ 45 | return $this->ResponseException($e); 46 | } 47 | } 48 | 49 | /** 50 | * getAllBuyers function 51 | * 52 | * Lista todos os usuarios do marketplace 53 | * ('não realiza associação com o vendedor') 54 | * 55 | * @return bool|array 56 | * @throws \Exception 57 | */ 58 | public function getAllBuyers() 59 | { 60 | try { 61 | $request = $this->configurations['guzzle']->request( 62 | 'GET', '/v1/marketplaces/'. $this->configurations['marketplace']. '/buyers' 63 | ); 64 | $response = \json_decode($request->getBody()->getContents(), true); 65 | if($response && is_array($response)){ 66 | return $response; 67 | } 68 | return false; 69 | } catch (\Exception $e){ 70 | return $this->ResponseException($e); 71 | } 72 | } 73 | 74 | /** 75 | * function getBuyer 76 | * 77 | * Pega os dados do usuario associado 78 | * ao id passado como parametro. 79 | * 80 | * @param string $userId 81 | * 82 | * @return bool|array 83 | * @throws \Exception 84 | */ 85 | public function getBuyer($userId) 86 | { 87 | try { 88 | $request = $this->configurations['guzzle']->request( 89 | 'GET', '/v1/marketplaces/'. $this->configurations['marketplace']. '/buyers/' . $userId 90 | ); 91 | $response = \json_decode($request->getBody()->getContents(), true); 92 | if($response && is_array($response)){ 93 | return $response; 94 | } 95 | return false; 96 | } catch (\Exception $e){ 97 | return $this->ResponseException($e); 98 | } 99 | } 100 | 101 | /** 102 | * function deleteBuyer 103 | * 104 | * Delta um usuario do marketplace utilizando como parametro 105 | * seu id. 106 | * 107 | * @param $userId 108 | * 109 | * @return bool|mixed|void 110 | * @throws \Exception 111 | */ 112 | public function deleteBuyer($userId) 113 | { 114 | try { 115 | $request = $this->configurations['guzzle']->request( 116 | 'DELETE', '/v1/marketplaces/'. $this->configurations['marketplace']. '/buyers/' . $userId 117 | ); 118 | $response = \json_decode($request->getBody()->getContents(), true); 119 | if($response && is_array($response)){ 120 | return $response; 121 | } 122 | return false; 123 | } catch (\Exception $e){ 124 | return $this->ResponseException($e); 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /src/Resources/MarketPlace/Sellers.php: -------------------------------------------------------------------------------- 1 | 13 | * @version 1.0.0 14 | */ 15 | class Sellers extends Zoop 16 | { 17 | public function __construct(array $configurations) 18 | { 19 | parent::__construct($configurations); 20 | } 21 | 22 | /** 23 | * getSeller function 24 | * 25 | * Pega os dados de um vendedor utilizando seu id 26 | * como paramtro. 27 | * 28 | * @param string|int $sallerId 29 | * 30 | * @return void 31 | * @throws \Exception 32 | */ 33 | public function getSeller($sallerId) 34 | { 35 | try { 36 | $request = $this->configurations['guzzle']->request( 37 | 'GET', '/v1/marketplaces/'. $this->configurations['marketplace']. '/sellers/'. $sallerId 38 | ); 39 | $response = \json_decode($request->getBody()->getContents(), true); 40 | if($response && is_array($response)){ 41 | return $response; 42 | } 43 | return false; 44 | } catch (\Exception $e){ 45 | return $this->ResponseException($e); 46 | } 47 | } 48 | 49 | /** 50 | * getAllSellers function 51 | * 52 | * Lista todos os vendedores do marketplace 53 | * 54 | * @throws \Exception 55 | * @return array|void 56 | */ 57 | public function getAllSellers() 58 | { 59 | try { 60 | $request = $this->configurations['guzzle']->request( 61 | 'GET', '/v1/marketplaces/'. $this->configurations['marketplace']. '/sellers' 62 | ); 63 | $response = \json_decode($request->getBody()->getContents(), true); 64 | if($response && is_array($response)){ 65 | return $response; 66 | } 67 | return false; 68 | } catch (\Exception $e){ 69 | return $this->ResponseException($e); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /src/Resources/MarketPlace/Transactions.php: -------------------------------------------------------------------------------- 1 | 14 | * @version 1.0.0 15 | */ 16 | class Transactions extends Zoop 17 | { 18 | public function __construct(array $configurations) 19 | { 20 | parent::__construct($configurations); 21 | } 22 | 23 | /** 24 | * function getAllTransactions 25 | * 26 | * Pega todas as transações do vendedor dentro 27 | * do marketplace 28 | * 29 | * @return bool|array 30 | * @throws \Exception 31 | */ 32 | public function getAllTransactions() 33 | { 34 | try { 35 | $request = $this->configurations['guzzle']->request( 36 | 'GET', '/v1/marketplaces/'. $this->configurations['marketplace']. '/sellers/' . $this->configurations['auth']['on_behalf_of'] .'/transactions' 37 | ); 38 | $response = \json_decode($request->getBody()->getContents(), true); 39 | if($response && is_array($response)){ 40 | return $response; 41 | } 42 | return false; 43 | } catch (\Exception $e){ 44 | return $this->ResponseException($e); 45 | } 46 | } 47 | 48 | /** 49 | * getTransaction function 50 | * 51 | * Pega os detalhes de uma transação em especifico 52 | * utilizando como parametro o id da mesma. 53 | * 54 | * @param string $transaction 55 | * 56 | * @return array|bool 57 | * @throws \Exception 58 | */ 59 | public function getTransaction($transaction) 60 | { 61 | try { 62 | $request = $this->configurations['guzzle']->request( 63 | 'GET', '/v1/marketplaces/'. $this->configurations['marketplace']. '/transactions/'. $transaction 64 | ); 65 | $response = \json_decode($request->getBody()->getContents(), true); 66 | if($response && is_array($response)){ 67 | return $response; 68 | } 69 | return false; 70 | } catch (\Exception $e){ 71 | return $this->ResponseException($e); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /src/Resources/Payment/CreditCard.php: -------------------------------------------------------------------------------- 1 | 14 | * @version 1.0.0 15 | */ 16 | class CreditCard extends Zoop 17 | { 18 | public function __construct($configurations) 19 | { 20 | parent::__construct($configurations); 21 | } 22 | 23 | /** 24 | * prepareCreditCard function 25 | * 26 | * Hidrata o array basico do cartão de credito 27 | * adicionando dados imutaveis para realizar a operação. 28 | * 29 | * @param array $card 30 | * @param null|string $referenceId 31 | * @return array 32 | */ 33 | private function prepareCreditCard(array $card, $referenceId = null) 34 | { 35 | $payment = array( 36 | 'amount' => ($card['amount'] * 100), 37 | 'currency' => 'BRL', 38 | 'description' => $card['description'], 39 | 'on_behalf_of' => $this->configurations['auth']['on_behalf_of'], 40 | 'statement_descriptor' => 'SEMINOVOS BH', 41 | 'payment_type' => 'credit', 42 | 'source' => array( 43 | 'usage' => 'single_use', 44 | 'amount' => ($card['amount'] * 100), 45 | 'currency' => 'BRL', 46 | 'type' => 'card', 47 | 'card' => array( 48 | 'card_number' => $card['card']['card_number'], 49 | 'holder_name' => $card['card']['holder_name'], 50 | 'expiration_month' => $card['card']['expiration_month'], 51 | 'expiration_year' => $card['card']['expiration_year'], 52 | 'security_code' => $card['card']['security_code'], 53 | ), 54 | ), 55 | ); 56 | if(isset($card['installment_plan']) && is_array($card['installment_plan']) && $this->validateInstallment($card['installment_plan'])){ 57 | $payment['installment_plan'] = $card['installment_plan']; 58 | } 59 | 60 | if(!is_null($referenceId)){ 61 | $payment['reference_id'] = $referenceId; 62 | } 63 | return $payment; 64 | } 65 | 66 | /** 67 | * validateInstallment function 68 | * 69 | * Valida o parcelamento por cartão de credito. 70 | * 71 | * @param array $installment 72 | * @return bool 73 | */ 74 | private function validateInstallment(array $installment) 75 | { 76 | if(!isset($installment['mode']) 77 | || !isset($installment['number_installments']) 78 | || empty($installment['mode']) 79 | || empty($installment['number_installments'])){ 80 | return false; 81 | } 82 | if($installment['mode'] == 'with_interest' || $installment['mode'] == 'interest_free'){ 83 | return true; 84 | } 85 | return false; 86 | } 87 | 88 | /** 89 | * 90 | * payCreditCard function 91 | * 92 | * Gera o pagamento com cartão de credito, 93 | * realizando com simplicidade a operação. 94 | * 95 | * @param array $card 96 | * @param null|string $referenceId 97 | * 98 | * @return array|bool|void 99 | * @throws \Exception 100 | */ 101 | public function payCreditCard(array $card, $referenceId = null) 102 | { 103 | /** 104 | * Adiciona o pacerlamento ao cartão de credito mantendo a integridade com o funcionamento atual. 105 | */ 106 | try { 107 | $payment = $this->prepareCreditCard($card, $referenceId); 108 | $request = $this->configurations['guzzle']->request( 109 | 'POST', '/v1/marketplaces/'. $this->configurations['marketplace']. '/transactions', 110 | ['json' => $payment] 111 | ); 112 | $response = \json_decode($request->getBody()->getContents(), true); 113 | if($response && is_array($response)){ 114 | return $response; 115 | } 116 | return false; 117 | } catch (\Exception $e){ 118 | return $this->ResponseException($e); 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /src/Resources/Payment/Ticket.php: -------------------------------------------------------------------------------- 1 | 14 | * @version 1.0.0 15 | */ 16 | class Ticket extends Zoop 17 | { 18 | public function __construct(array $configurations) 19 | { 20 | parent::__construct($configurations); 21 | } 22 | 23 | /** 24 | * prepareTicket function 25 | * 26 | * Prepara o boleto e preenche o mesmo 27 | * com dados fixos utilizados na request para geração 28 | * de boletos. 29 | * 30 | * @param array $ticket 31 | * @param string $userId 32 | * @return array 33 | */ 34 | private function prepareTicket(array $ticket, $userId) 35 | { 36 | return [ 37 | 'amount' => ($ticket['amount'] * 100), 38 | 'currency' => 'BRL', 39 | 'logo' => array_key_exists('logo', $ticket) ? $ticket['logo'] : null, 40 | 'description' => $ticket['description'], 41 | 'payment_type' => 'boleto', 42 | 'payment_method' => [ 43 | 'top_instructions' => $ticket['top_instructions'], 44 | 'body_instructions' => $ticket['body_instructions'], 45 | 'expiration_date' => $ticket['expiration_date'], 46 | 'payment_limit_date' => $ticket['payment_limit_date'], 47 | ], 48 | 'capture' => false, 49 | 'on_behalf_of' => $this->configurations['auth']['on_behalf_of'], 50 | 'source' => [ 51 | 'usage' => 'single_use', 52 | 'type' => 'customer', 53 | 'capture' => false, 54 | 'on_behalf_of' => $this->configurations['auth']['on_behalf_of'] 55 | ], 56 | 'customer' => $userId, 57 | ]; 58 | } 59 | 60 | /** 61 | * processTicket function 62 | * 63 | * Processa o boleto na Zoop, e retorna somente os dados 64 | * necessarios para pegar o boleto e mostrar dados de valor. 65 | * 66 | * @param array $ticket 67 | * @param string $userId 68 | * @param null|string $referenceId 69 | * 70 | * @return array|bool 71 | * @throws \Exception 72 | */ 73 | private function processTicket(array $ticket, $userId, $referenceId = null) 74 | { 75 | if(!is_null($referenceId)){ 76 | $ticket['reference_id'] = $referenceId; 77 | } 78 | try { 79 | $ticket = $this->prepareTicket($ticket, $userId); 80 | $request = $this->configurations['guzzle']->request( 81 | 'POST', '/v1/marketplaces/'. $this->configurations['marketplace']. '/transactions', 82 | ['json' => $ticket] 83 | ); 84 | $response = \json_decode($request->getBody()->getContents(), true); 85 | if($response && is_array($response)){ 86 | return [ 87 | 'id' => $response['id'], 88 | 'ticketId' => $response['payment_method']['id'], 89 | 'status' => $response['status'], 90 | ]; 91 | } 92 | return false; 93 | } catch (\Exception $e){ 94 | return $this->ResponseException($e); 95 | } 96 | } 97 | 98 | /** 99 | * generateTicket function 100 | * 101 | * Gera o boleto e retorna os dados principais 102 | * do mesmo, como codigo de barras, url para download 103 | * no s3 e mais. 104 | * 105 | * @param array $ticket 106 | * @param string $userId 107 | * @param null|string $referenceId 108 | * 109 | * @return array|bool 110 | * @throws \Exception 111 | */ 112 | public function generateTicket(array $ticket, $userId, $referenceId = null) 113 | { 114 | try { 115 | $generatedTicket = $this->processTicket($ticket, $userId, $referenceId); 116 | $request = $this->configurations['guzzle']->request( 117 | 'GET', '/v1/marketplaces/'. $this->configurations['marketplace']. '/boletos/' . $generatedTicket['ticketId'] 118 | ); 119 | $response = \json_decode($request->getBody()->getContents(), true); 120 | if($response && is_array($response)){ 121 | return array( 122 | 'payment' => array( 123 | 'id' => $generatedTicket['id'], 124 | 'ticketId' => $generatedTicket['ticketId'], 125 | 'url' => $response['url'], 126 | 'barcode' => $response['barcode'], 127 | 'status' => $generatedTicket['status'] 128 | ), 129 | 'userId' => $userId 130 | ); 131 | } 132 | return false; 133 | } catch (\Exception $e){ 134 | return $this->ResponseException($e); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/Resources/WebHook/WebHook.php: -------------------------------------------------------------------------------- 1 | 15 | * @version 3.0.2 16 | */ 17 | class WebHook extends Zoop 18 | { 19 | /** 20 | * WebHook constructor. 21 | * 22 | * @param array $configurations 23 | */ 24 | public function __construct(array $configurations) 25 | { 26 | parent::__construct($configurations); 27 | $this->configurations = $configurations; 28 | } 29 | 30 | /** 31 | * validatePayload function 32 | * 33 | * Valida dados basicos da resposta recebida da zoop 34 | * garantindo que a mesma é uma resposta valida para 35 | * recebimento do evento. 36 | * 37 | * @param string $payload 38 | * @return bool|array 39 | */ 40 | private function validatePayload(string $payload) 41 | { 42 | $payload = \json_decode($payload, TRUE); 43 | if(isset($payload) 44 | && !empty($payload) 45 | && \is_array($payload) 46 | ) { 47 | if (isset($payload['id']) 48 | && isset($payload['type']) 49 | && isset($payload['resource']) 50 | && isset($payload['payload']) 51 | && isset($payload['payload']['object']['status']) 52 | ) { 53 | return $payload; 54 | } 55 | return false; 56 | } 57 | return false; 58 | } 59 | 60 | /** 61 | * resumePayload funtion 62 | * 63 | * Recebe os dados do payload e preenche somente os campos 64 | * realmente necessarios para se tomar ações dentro da aplicação. 65 | * 66 | * @param array $payload 67 | * @return array 68 | */ 69 | private function resumePayload(array $payload) 70 | { 71 | $payloadReturn = array( 72 | 'event' => array( 73 | 'id' => $payload['id'], 74 | 'type' => $payload['type'] 75 | ), 76 | 'payment' => array( 77 | 'id' => $payload['payload']['object']['id'], 78 | 'type' => $payload['payload']['object']['payment_type'], 79 | 'amount' => $payload['payload']['object']['amount'], 80 | ) 81 | ); 82 | if(isset($payload['payload']['object']['reference_id']) 83 | && !empty($payload['payload']['object']['reference_id'])){ 84 | $payloadReturn['referenceId'] = $payload['payload']['object']['reference_id']; 85 | } 86 | return $payloadReturn; 87 | } 88 | 89 | /** 90 | * webHookListen function 91 | * 92 | * Escuta as possiveis chamadas json, valida as mesma 93 | * (valida como um evento valido) e resume o evento, 94 | * para que você possa tomar a decisão correta baseado 95 | * no resultado do mesmo, exemplo, pagamento aprovado 96 | * ou paagemnto reprovado. 97 | * 98 | * @return array|bool|false|string 99 | */ 100 | public function webHookListen() 101 | { 102 | $payload = \file_get_contents('php://input'); 103 | $payload = $this->validatePayload($payload); 104 | if($payload && is_array($payload)){ 105 | $payload = $this->resumePayload($payload); 106 | return $payload; 107 | } 108 | //O Payload não é valido, exibe resposta padrão de exibição 109 | return false; 110 | } 111 | 112 | /** 113 | * createWebHook function 114 | * 115 | * Criando WebHook com cenario "advinhado" pois o mesmo 116 | * não se encontra na documentação oficial, passando a url 117 | * de callback e a descrição do hook 118 | * 119 | * @param string $url 120 | * @param string $description 121 | * @return array|bool 122 | * @throws \Exception Erro basico de requisição 123 | */ 124 | public function createWebHook($url, $description) 125 | { 126 | try { 127 | $request = $this->configurations['guzzle']->request( 128 | 'POST', '/v1/marketplaces/'. $this->configurations['marketplace']. '/webhooks', 129 | ['json' => array( 130 | 'url' => $url, 131 | 'method' => 'POST', 132 | 'description' => $description 133 | )] 134 | ); 135 | $response = \json_decode($request->getBody()->getContents(), true); 136 | if($response && is_array($response)){ 137 | return $response; 138 | } 139 | return false; 140 | } catch (\Exception $e){ 141 | return $this->ResponseException($e); 142 | } 143 | } 144 | 145 | /** 146 | * getAllWebHooks function 147 | * 148 | * Lista todos os webhooks adicioandos ao projeto 149 | * 150 | * @return array|bool 151 | * @throws \Exception Erro basico de requisição 152 | */ 153 | public function getAllWebHooks() 154 | { 155 | try { 156 | $request = $this->configurations['guzzle']->request( 157 | 'GET', '/v1/marketplaces/'. $this->configurations['marketplace']. '/webhook' 158 | ); 159 | $response = \json_decode($request->getBody()->getContents(), true); 160 | if($response && is_array($response)){ 161 | return $response; 162 | } 163 | return false; 164 | } catch (\Exception $e){ 165 | return $this->ResponseException($e); 166 | } 167 | } 168 | 169 | /** 170 | * deleteWebHook function 171 | * 172 | * Deleta o webhook criado no projeto passando como parametro 173 | * o id do mesmo (retornado na criação). 174 | * 175 | * @param string $webhookId 176 | * @return array|bool 177 | * @throws \Exception Erro basico de requisição 178 | */ 179 | public function deleteWebHook($webhookId) 180 | { 181 | try { 182 | $request = $this->configurations['guzzle']->request( 183 | 'DELETE', '/v1/marketplaces/'. $this->configurations['marketplace']. '/webhooks/' . $webhookId 184 | ); 185 | $response = \json_decode($request->getBody()->getContents(), true); 186 | if($response && is_array($response)){ 187 | return $response; 188 | } 189 | return false; 190 | } catch (\Exception $e){ 191 | return $this->ResponseException($e); 192 | } 193 | } 194 | } -------------------------------------------------------------------------------- /src/ZoopClient.php: -------------------------------------------------------------------------------- 1 | 36 | * @package ZoopClient 37 | * @version 1.0.0 38 | */ 39 | class ZoopClient extends Zoop 40 | { 41 | public function __construct($configurations) 42 | { 43 | parent::__construct($configurations); 44 | } 45 | } --------------------------------------------------------------------------------