From 277a67f20013d52633f4c4c2fecf0580be22e4ab Mon Sep 17 00:00:00 2001 From: Max Alex Date: Sat, 23 May 2020 17:10:33 -0300 Subject: [PATCH] 1.0.0.1 --- CONTRIBUTING.md | 15 ++ LICENSE | 12 +- README.md | 1 + composer.json | 24 ++++ src/.DS_Store | Bin 0 -> 6148 bytes src/Cobranca.php | 178 ++++++++++++++++++++++++ src/Connection.php | 81 +++++++++++ src/Exceptions/AccessTokenException.php | 13 ++ src/Exceptions/AssinaturaException.php | 18 +++ src/Exceptions/ClienteException.php | 11 ++ src/Exceptions/CobrancaException.php | 18 +++ src/Exceptions/NotificacaoException.php | 18 +++ src/Exceptions/WebhookException.php | 18 +++ src/GetNet.php | 27 ++++ src/Notificacao.php | 60 ++++++++ src/Transferencia.php | 47 +++++++ src/Webhook.php | 14 ++ 17 files changed, 549 insertions(+), 6 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 README.md create mode 100644 composer.json create mode 100644 src/.DS_Store create mode 100644 src/Cobranca.php create mode 100644 src/Connection.php create mode 100644 src/Exceptions/AccessTokenException.php create mode 100644 src/Exceptions/AssinaturaException.php create mode 100644 src/Exceptions/ClienteException.php create mode 100644 src/Exceptions/CobrancaException.php create mode 100644 src/Exceptions/NotificacaoException.php create mode 100644 src/Exceptions/WebhookException.php create mode 100644 src/GetNet.php create mode 100644 src/Notificacao.php create mode 100644 src/Transferencia.php create mode 100644 src/Webhook.php diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..6457cf0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,15 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +We accept contributions via Pull Requests on [Github](https://github.com/codephix/getnet). + +## Pull Requests + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). +- **Document any change in behaviour** - Make sure the README and any other relevant documentation are kept up-to-date. +- **Create topic branches** - Don't ask us to pull from your master branch. +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. + +**Happy CodePhix/GetNet**! diff --git a/LICENSE b/LICENSE index 5fc3d8d..2c93e08 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ -MIT License +The MIT License (MIT) -Copyright (c) 2020 Max Alex +Copyright (c) 2020 Max Alex @CodePhix Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..647627d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Iniciando a programação em breve estará disponivel \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..025f2db --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "codephix/getnet", + "type" : "library", + "description": "GetNet PHP API Wrapper", + "keywords" : ["GetNet", "API", "Payment SaaS", "Credit Card", "Boleto"], + "homepage": "http://www.codephix.com", + "license": "MIT", + "authors": [ + { + "name": "Max Alex", + "email": "contato@codephix.com", + "role": "Developer", + "homepage": "https://www.codephix.com" + } + ], + "require": { + "php": "^7.2" + }, + "autoload": { + "psr-4": { + "CodePhix\\GetNet\\": "src" + } + } +} diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..45572f3b939d551348432f5989299329a6a669d9 GIT binary patch literal 6148 zcmeHKJx>Bb5Pgdzeqart`w|yt zWW3ICchJH!SzYdwFXm)1AKprw3&u}zrKRk#)p_Q}xXQRQnrHlu- zF;yn$G3%Hv3iWM|m-2^~r5http = $connection; + } + + // Retorna a listagem de cobranças + public function getAll(array $filtros){ + $filtro = ''; + if(is_array($filtros)){ + if($filtros){ + foreach($filtros as $key => $f){ + if(!empty($f)){ + if($filtro){ + $filtro .= '&'; + } + $filtro .= $key.'='.$f; + } + } + $filtro = '?'.$filtro; + } + } + return $this->http->get('/payments'.$filtro); + } + + // Retorna os dados da cobrança de acordo com o Id + public function getById($id){ + return $this->http->get('/payments/'.$id); + } + + // Retorna a listagem de cobranças de acordo com o Id do Cliente + public function getByCustomer($customer_id){ + return $this->http->get('/payments?customer='.$customer_id); + } + + // Retorna a listagem de cobranças de acordo com o Id da Assinaturas + public function getBySubscription($subscription_id){ + return $this->http->get('/payments?subscription='.$subscription_id); + } + + // Insere uma nova cobrança + public function create(array $dadosCobranca){ + $dadosCobranca = $this->setCobranca($dadosCobranca); + if(!empty($dadosCobranca['error'])){ + return $dadosCobranca; + }else { + return $this->http->post('/payments', $dadosCobranca); + } + } + + // Insere uma nova cobrança parcelada + public function parcelada(array $dadosCobranca){ + + } + + // Insere uma nova cobrança com split + /* Saldo dividido em multiplas contas do Asaas*/ + public function split(array $dadosCobranca){ + + } + + // Atualiza os dados da cobrança + public function update($id, array $dadosCobranca){ + + return $this->http->post('/payments/' . $id, $dadosCobranca); + } + + // Restaura cobrança removida + public function restore($id){ + + } + + // Estorna cobrança + public function estorno($id){ + + } + + // Confirmação em dinheiro + public function confirmacao($id, $dados){ + $data = array( + "paymentDate" => "2019-09-03", + "value" => 100.00, + ); + return $this->http->post('/customers', $data); + } + + // Deleta uma cobrança + public function delete($id){ + return $this->http->get('/payments/'.$id,'','DELETE'); + } + + /** + * Cria um novo boleto no Asaas. + * @param Array $cliente + * @return Boolean + */ + public function create2($dados) + { + // Preenche as informações da cobranca + $cobranca = $this->setCobranca($dados); + + // Faz o post e retorna array de resposta + return $this->http->post('/payments', ['form_params' => $cobranca]); + } + + /** + * Faz merge nas informações das cobranças. + * + * @see https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobrancas + * @param Array $cliente + * @return Array + */ + public function setCobranca($dados) + { + try { + $this->cobranca = array( + 'customer' => '', + 'billingType' => '', + 'value' => '', + 'dueDate' => '', + 'description' => '', + 'externalReference' => '', + 'installmentCount' => '', + 'installmentValue' => '', + 'discount' => '', + 'interest' => '', + 'fine' => '', + ); + + $this->cobranca = array_merge($this->cobranca, $dados); + return $this->cobranca; + + } catch (Exception $e) { + return 'Erro ao definir o cliente. - ' . $e->getMessage(); + } + } + + /** + * Faz merge nas informações das cobranças. + * + * @see https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobrancas + * @param Array $cliente + * @return Array + */ + public function setCobrancaCartao($dados) + { + try { + $this->cobranca = array( + 'customer' => '', + 'billingType' => '', + 'value' => '', + 'dueDate' => '', + 'description' => '', + 'externalReference' => '', + 'installmentCount' => '', + 'installmentValue' => '', + 'discount' => '', + 'interest' => '', + 'fine' => '', + ); + + $this->cobranca = array_merge($this->cobranca, $dados); + return $this->cobranca; + + } catch (Exception $e) { + return 'Erro ao definir o cliente. - ' . $e->getMessage(); + } + } +} diff --git a/src/Connection.php b/src/Connection.php new file mode 100644 index 0000000..e53e0f0 --- /dev/null +++ b/src/Connection.php @@ -0,0 +1,81 @@ +api_status = false; + }elseif($status == 'homologacao'){ + $this->api_status = 1; + }else{ + die('Tipo de homologação invalida'); + } + $this->api_key = $token; + //$this->api_status = PAYMENT['asaas']['status']; + $this->base_url = "https://" . (($this->api_status) ? 'sandbox' : 'www'); + + return $this; + } + + + public function get($url, $option = false, $custom = false ) + { + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url.$option); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_HEADER, FALSE); + + if(!empty($custom)){ + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $custom); + } + + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + "Content-Type: application/json", + "access_token: ".$this->api_key + )); + + $response = curl_exec($ch); + curl_close($ch); + $response = json_decode($response); + + //$response = $this->http->request('GET', $this->base_url . $url); + + return $response; + } + + public function post($url, $params) + { + $params = json_encode($params); + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_HEADER, FALSE); + + curl_setopt($ch, CURLOPT_POST, TRUE); + + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + "Content-Type: application/json", + "access_token: ".$this->api_key + )); + + $response = curl_exec($ch); + curl_close($ch); + $response = json_decode($response); + + return $response; + + } + +} diff --git a/src/Exceptions/AccessTokenException.php b/src/Exceptions/AccessTokenException.php new file mode 100644 index 0000000..c963561 --- /dev/null +++ b/src/Exceptions/AccessTokenException.php @@ -0,0 +1,13 @@ +'Os dados Obrigatorio são Nome, Cpf\Cnpj, E-mail, Os dados fornecidos para o cadastro do cliente não são válidos.'); + } +} diff --git a/src/Exceptions/CobrancaException.php b/src/Exceptions/CobrancaException.php new file mode 100644 index 0000000..b611b95 --- /dev/null +++ b/src/Exceptions/CobrancaException.php @@ -0,0 +1,18 @@ +cobranca = new Cobranca($connection); + $this->notificacao = new Notificacao($connection); + $this->transferencia = new Transferencia($connection); + $this->webhook = new Webhook($connection); + } +} diff --git a/src/Notificacao.php b/src/Notificacao.php new file mode 100644 index 0000000..3814a28 --- /dev/null +++ b/src/Notificacao.php @@ -0,0 +1,60 @@ +http = $connection; + } + + // Retorna a listagem de notificações + public function getAll(array $filtros){ + $filtro = ''; + if(is_array($filtros)){ + if($filtros){ + foreach($filtros as $key => $f){ + if(!empty($f)){ + if($filtro){ + $filtro .= '&'; + } + $filtro .= $key.'='.$f; + } + } + $filtro = '?'.$filtro; + } + } + return $this->http->get('/notifications'.$filtro); + } + + // Retorna os dados da notificação de acordo com o Id + public function getById($id){ + return $this->http->get('/notifications/'.$id); + } + + // Retorna a listagem de notificações de acordo com o Id do Cliente + public function getByCustomer($customer_id){ + return $this->http->get('/customers/'.$id.'/notifications'); + } + + // Insere uma nova notificação + public function create(array $dadosNotificacao){ + return $this->http->post('/notifications', $dadosNotificacao); + } + + // Atualiza os dados da notificação + public function update($id, array $dadosNotificacao){ + return $this->http->post('/notifications', $dadosNotificacao); + } + + // Deleta uma notificação + public function delete($id){ + return $this->http->get('/notifications/'.$id,'','DELETE'); + } + +} diff --git a/src/Transferencia.php b/src/Transferencia.php new file mode 100644 index 0000000..6767de6 --- /dev/null +++ b/src/Transferencia.php @@ -0,0 +1,47 @@ +http = $connection; + } + + + public function getAll($parametos = false){ + $filtro = ''; + if(is_array($parametos)){ + if($parametos){ + foreach($parametos as $key => $f){ + if(!empty($f)){ + if($filtro){ + $filtro .= '&'; + } + $filtro .= $key.'='.$f; + } + } + $filtro = '?'.$filtro; + } + } + return $this->http->get('/transfers/'.$filtro); + //https://www.asaas.com/api/v3/subscriptions/id/invoices?offset=&limit=&status= + } + + public function consultaSaldo(){ + return $this->http->get('/finance/getCurrentBalance'); + } + + public function consultaWalletId(){ + return $this->http->get('/wallets'); + } + + + public function conta($dadosConta){ + return $this->http->post('/transfers', $dadosConta); + } +} diff --git a/src/Webhook.php b/src/Webhook.php new file mode 100644 index 0000000..303244e --- /dev/null +++ b/src/Webhook.php @@ -0,0 +1,14 @@ +http = $connection; + } +}