diff --git a/.gitignore b/.gitignore index ccef056..7d7b94f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -/vendor/ -.idea \ No newline at end of file +/vendor/ +.idea +/nbproject/private/ \ No newline at end of file diff --git a/composer.json b/composer.json index 86cf3f0..522692f 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "guzzlehttp/guzzle": "^6.2@dev", - "phpunit/phpunit": "^6.4@dev" + "guzzlehttp/guzzle": "^7.0.1" }, "scripts" : { "test" : "./vendor/bin/phpunit --colors --debug", diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..f835700 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_70 +source.encoding=UTF-8 +src.dir=src +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..6bd1086 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + pjbank-php-sdk + + + diff --git a/src/Boleto/Boleto.php b/src/Boleto/Boleto.php index 7d2b904..eb4e405 100644 --- a/src/Boleto/Boleto.php +++ b/src/Boleto/Boleto.php @@ -1,547 +1,578 @@ -credencial_boleto = $credencial; - $this->chave_boleto = $chave; - } - - /** - * @return mixed - */ - public function getLink() - { - return $this->link; - } - - /** - * @return mixed - */ - public function getNossoNumero() - { - return $this->nosso_numero; - } - - /** - * Undocumented function - * @return void - */ - public function getIdUnico() - { - return $this->id_unico; - } - - /** - * Setter do numero do pedido - * @param $pedido_numero - */ - public function setPedidoNumero($pedido_numero) - { - $this->pedido_numero = $pedido_numero; - return $this; - } - - /** - * Numero do pedido - * @return mixed - */ - public function getPedidoNumero() { - return $this->pedido_numero; - } - - /** - * Undocumented function - * @return void - */ - public function getLinhaDigitavel() - { - return $this->linha_digitavel; - } - - /** - * @return mixed - */ - public function getCredencialBoleto() - { - return $this->credencial_boleto; - } - - /** - * @param mixed $credencial_boleto - * @return Boleto - */ - public function setCredencialBoleto($credencial_boleto) - { - $this->credencial_boleto = $credencial_boleto; - return $this; - } - - /** - * @return mixed - */ - public function getChaveBoleto() - { - return $this->chave_boleto; - } - - /** - * @param mixed $chave_boleto - * @return Boleto - */ - public function setChaveBoleto($chave_boleto) - { - $this->chave_boleto = $chave_boleto; - return $this; - } - - - - /** - * @return date - */ - public function getVencimento() - { - return $this->vencimento; - } - - /** - * @param date $vencimento - * @return Boleto - */ - public function setVencimento($vencimento) - { - $this->vencimento = $vencimento; - return $this; - } - - /** - * @return mixed - */ - public function getValor() - { - return $this->valor; - } - - /** - * @param mixed $valor - * @return Boleto - */ - public function setValor($valor) - { - $this->valor = $valor; - return $this; - } - - /** - * @return float - */ - public function getJuros() - { - return $this->juros; - } - - /** - * @param float $juros - * @return Boleto - */ - public function setJuros($juros) - { - $this->juros = $juros; - return $this; - } - - /** - * @return float - */ - public function getMulta() - { - return $this->multa; - } - - /** - * @param float $multa - * @return Boleto - */ - public function setMulta($multa) - { - $this->multa = $multa; - return $this; - } - - /** - * @return float - */ - public function getDesconto() - { - return $this->desconto; - } - - /** - * @param float $desconto - * @return Boleto - */ - public function setDesconto($desconto) - { - $this->desconto = $desconto; - return $this; - } - - /** - * @return mixed - */ - public function getNomeCliente() - { - return $this->nome_cliente; - } - - /** - * @param mixed $nome_cliente - * @return Boleto - */ - public function setNomeCliente($nome_cliente) - { - $this->nome_cliente = $nome_cliente; - return $this; - } - - /** - * @return mixed - */ - public function getCpfCliente() - { - return $this->cpf_cliente; - } - - /** - * @param mixed $cpf_cliente - * @return Boleto - */ - public function setCpfCliente($cpf_cliente) - { - $this->cpf_cliente = $cpf_cliente; - return $this; - } - - /** - * @return mixed - */ - public function getEnderecoCliente() - { - return $this->endereco_cliente; - } - - /** - * @param mixed $endereco_cliente - * @return Boleto - */ - public function setEnderecoCliente($endereco_cliente) - { - $this->endereco_cliente = $endereco_cliente; - return $this; - } - - /** - * @return mixed - */ - public function getNumeroCliente() - { - return $this->numero_cliente; - } - - /** - * @param mixed $numero_cliente - * @return Boleto - */ - public function setNumeroCliente($numero_cliente) - { - $this->numero_cliente = $numero_cliente; - return $this; - } - - /** - * @return mixed - */ - public function getComplementoCliente() - { - return $this->complemento_cliente; - } - - /** - * @param mixed $complemento_cliente - * @return Boleto - */ - public function setComplementoCliente($complemento_cliente) - { - $this->complemento_cliente = $complemento_cliente; - return $this; - } - - /** - * @return mixed - */ - public function getBairroCliente() - { - return $this->bairro_cliente; - } - - /** - * @param mixed $bairro_cliente - * @return Boleto - */ - public function setBairroCliente($bairro_cliente) - { - $this->bairro_cliente = $bairro_cliente; - return $this; - } - - /** - * @return mixed - */ - public function getCidadeCliente() - { - return $this->cidade_cliente; - } - - /** - * @param mixed $cidade_cliente - * @return Boleto - */ - public function setCidadeCliente($cidade_cliente) - { - $this->cidade_cliente = $cidade_cliente; - return $this; - } - - /** - * @return mixed - */ - public function getCepCliente() - { - return $this->cep_cliente; - } - - /** - * @param mixed $cep_cliente - * @return Boleto - */ - public function setCepCliente($cep_cliente) - { - $this->cep_cliente = $cep_cliente; - return $this; - } - - /** - * @return mixed - */ - public function getLogoUrl() - { - return $this->logo_url; - } - - /** - * @param mixed $logo_url - * @return Boleto - */ - public function setLogoUrl($logo_url) - { - $this->logo_url = $logo_url; - return $this; - } - - /** - * @return mixed - */ - public function getTexto() - { - return $this->texto; - } - - /** - * @param mixed $texto - * @return Boleto - */ - public function setTexto($texto) - { - $this->texto = $texto; - return $this; - } - - /** - * @return mixed - */ - public function getGrupo() - { - return $this->grupo; - } - - /** - * @param mixed $grupo - * @return Boleto - */ - public function setGrupo($grupo) - { - $this->grupo = $grupo; - return $this; - } - - - /** - * Pega os campos utilizados para a emissão do boleto bancário. - * @return array - */ - public function getValues() - { - $objectValues = get_object_vars($this); - $boletoValues = array(); - foreach ($objectValues as $key => $value) { - if (!is_null($value)) { - $boletoValues[$key] = $value; - } - } - - return $boletoValues; - } - - - - /** - * Gera um boleto bancário no PJBank - * via API - */ - public function gerar() { - $emissor = new Emissor($this); - $boletoGerado = $emissor->emitir(); - - $this->nosso_numero = $boletoGerado->nossonumero; - $this->id_unico = $boletoGerado->id_unico; - $this->linha_digitavel = $boletoGerado->linhaDigitavel; - $this->link = $boletoGerado->linkBoleto; - } - - -} +credencial_boleto = $credencial; + $this->chave_boleto = $chave; + } + + /** + * @return mixed + */ + public function getLink() + { + return $this->link; + } + + /** + * @return mixed + */ + public function getNossoNumero() + { + return $this->nosso_numero; + } + + /** + * Undocumented function + * @return void + */ + public function getIdUnico() + { + return $this->id_unico; + } + + /** + * Setter do numero do pedido + * @param $pedido_numero + */ + public function setPedidoNumero($pedido_numero) + { + $this->pedido_numero = $pedido_numero; + return $this; + } + + /** + * Numero do pedido + * @return mixed + */ + public function getPedidoNumero() { + return $this->pedido_numero; + } + + /** + * Undocumented function + * @return void + */ + public function getLinhaDigitavel() + { + return $this->linha_digitavel; + } + + /** + * @return mixed + */ + public function getCredencialBoleto() + { + return $this->credencial_boleto; + } + + /** + * @param mixed $credencial_boleto + * @return Boleto + */ + public function setCredencialBoleto($credencial_boleto) + { + $this->credencial_boleto = $credencial_boleto; + return $this; + } + + /** + * @return mixed + */ + public function getChaveBoleto() + { + return $this->chave_boleto; + } + + /** + * @param mixed $chave_boleto + * @return Boleto + */ + public function setChaveBoleto($chave_boleto) + { + $this->chave_boleto = $chave_boleto; + return $this; + } + + + + /** + * @return date + */ + public function getVencimento() + { + return $this->vencimento; + } + + /** + * @param date $vencimento + * @return Boleto + */ + public function setVencimento($vencimento) + { + $this->vencimento = $vencimento; + return $this; + } + + /** + * @return mixed + */ + public function getValor() + { + return $this->valor; + } + + /** + * @param mixed $valor + * @return Boleto + */ + public function setValor($valor) + { + $this->valor = $valor; + return $this; + } + + /** + * @return float + */ + public function getJuros() + { + return $this->juros; + } + + /** + * @param float $juros + * @return Boleto + */ + public function setJuros($juros) + { + $this->juros = $juros; + return $this; + } + + /** + * @return float + */ + public function getMulta() + { + return $this->multa; + } + + /** + * @param float $multa + * @return Boleto + */ + public function setMulta($multa) + { + $this->multa = $multa; + return $this; + } + + /** + * @return float + */ + public function getDesconto() + { + return $this->desconto; + } + + /** + * @param float $desconto + * @return Boleto + */ + public function setDesconto($desconto) + { + $this->desconto = $desconto; + return $this; + } + + /** + * @return mixed + */ + public function getNomeCliente() + { + return $this->nome_cliente; + } + + /** + * @param mixed $nome_cliente + * @return Boleto + */ + public function setNomeCliente($nome_cliente) + { + $this->nome_cliente = $nome_cliente; + return $this; + } + + /** + * @return mixed + */ + public function getCpfCliente() + { + return $this->cpf_cliente; + } + + /** + * @param mixed $cpf_cliente + * @return Boleto + */ + public function setCpfCliente($cpf_cliente) + { + $this->cpf_cliente = $cpf_cliente; + return $this; + } + + /** + * @return mixed + */ + public function getEnderecoCliente() + { + return $this->endereco_cliente; + } + + /** + * @param mixed $endereco_cliente + * @return Boleto + */ + public function setEnderecoCliente($endereco_cliente) + { + $this->endereco_cliente = $endereco_cliente; + return $this; + } + + /** + * @return mixed + */ + public function getNumeroCliente() + { + return $this->numero_cliente; + } + + /** + * @param mixed $numero_cliente + * @return Boleto + */ + public function setNumeroCliente($numero_cliente) + { + $this->numero_cliente = $numero_cliente; + return $this; + } + + /** + * @return mixed + */ + public function getComplementoCliente() + { + return $this->complemento_cliente; + } + + /** + * @param mixed $complemento_cliente + * @return Boleto + */ + public function setComplementoCliente($complemento_cliente) + { + $this->complemento_cliente = $complemento_cliente; + return $this; + } + + /** + * @return mixed + */ + public function getBairroCliente() + { + return $this->bairro_cliente; + } + + /** + * @param mixed $bairro_cliente + * @return Boleto + */ + public function setBairroCliente($bairro_cliente) + { + $this->bairro_cliente = $bairro_cliente; + return $this; + } + + /** + * @param mixed $estado_cliente + * @return Boleto + */ + public function setEstadoCliente($estado_cliente) + { + $this->estado_cliente = $estado_cliente; + return $this; + } + + /** + * @return mixed + */ + function getEstadoCliente() { + return $this->estado_cliente; + } + + /** + * @return mixed + */ + public function getCidadeCliente() + { + return $this->cidade_cliente; + } + + /** + * @param mixed $cidade_cliente + * @return Boleto + */ + public function setCidadeCliente($cidade_cliente) + { + $this->cidade_cliente = $cidade_cliente; + return $this; + } + + /** + * @return mixed + */ + public function getCepCliente() + { + return $this->cep_cliente; + } + + /** + * @param mixed $cep_cliente + * @return Boleto + */ + public function setCepCliente($cep_cliente) + { + $this->cep_cliente = $cep_cliente; + return $this; + } + + /** + * @return mixed + */ + public function getLogoUrl() + { + return $this->logo_url; + } + + /** + * @param mixed $logo_url + * @return Boleto + */ + public function setLogoUrl($logo_url) + { + $this->logo_url = $logo_url; + return $this; + } + + /** + * @return mixed + */ + public function getTexto() + { + return $this->texto; + } + + /** + * @param mixed $texto + * @return Boleto + */ + public function setTexto($texto) + { + $this->texto = $texto; + return $this; + } + + /** + * @return mixed + */ + public function getGrupo() + { + return $this->grupo; + } + + /** + * @param mixed $grupo + * @return Boleto + */ + public function setGrupo($grupo) + { + $this->grupo = $grupo; + return $this; + } + + + /** + * Pega os campos utilizados para a emissão do boleto bancário. + * @return array + */ + public function getValues() + { + $objectValues = get_object_vars($this); + $boletoValues = array(); + foreach ($objectValues as $key => $value) { + if (!is_null($value)) { + $boletoValues[$key] = $value; + } + } + + return $boletoValues; + } + + + + /** + * Gera um boleto bancário no PJBank + * via API + */ + public function gerar() { + $emissor = new Emissor($this); + $boletoGerado = $emissor->emitir(); + + $this->nosso_numero = isset($boletoGerado->nossonumero) ? $boletoGerado->nossonumero : null; + $this->id_unico = isset($boletoGerado->id_unico) ? $boletoGerado->id_unico : null; + $this->linha_digitavel = isset($boletoGerado->linhaDigitavel) ? $boletoGerado->linhaDigitavel : null; + $this->link = isset($boletoGerado->linkBoleto) ? $boletoGerado->linkBoleto : null; + } + + /** + * Gera um boleto bancário no PJBank + * via API + */ + public function invalidar() { + $emissor = new Emissor($this); + return $emissor->invalidar(); + } + + +} diff --git a/src/Boleto/Emissor.php b/src/Boleto/Emissor.php index ed58931..1d5c0cd 100644 --- a/src/Boleto/Emissor.php +++ b/src/Boleto/Emissor.php @@ -38,6 +38,8 @@ public function emitir() $PJBankClient = new PJBankClient(); $client = $PJBankClient->getClient(); $boletoItens = $this->boleto->getValues(); + + $boletoItens['pix'] = 'pix-e-boleto'; try { @@ -56,8 +58,38 @@ public function emitir() throw new \Exception($responseBody->msg, $responseBody->status); } + + } + + /** + * Invalida um boleto bancário via API + * @return Boleto + */ + public function invalidar() + { + $PJBankClient = new PJBankClient(); + $client = $PJBankClient->getClient(); + $boletoItens = $this->boleto->getValues(); + try { + + $resource = "recebimentos/{$this->boleto->getCredencialBoleto()}/transacoes/{$this->boleto->getPedidoNumero()}"; + $res = $client->request('DELETE', $resource, ['json' => $boletoItens, 'headers' => [ + 'Content-Type' => 'Application/json', + 'X-CHAVE' => $this->boleto->getChaveBoleto() + ]]); + + return json_decode((string) $res->getBody()); + + } catch (ClientException $e) { + + $responseBody = json_decode($e->getResponse()->getBody()); + throw new \Exception($responseBody->msg, $responseBody->status); + + } + } + } diff --git a/src/Extrato/Extrato.php b/src/Extrato/Extrato.php index 8485cee..064eb4c 100644 --- a/src/Extrato/Extrato.php +++ b/src/Extrato/Extrato.php @@ -1,206 +1,206 @@ - - * @package PJBank\Extrato - */ -class Extrato -{ - - /** - * Credencial da conta - * @var - */ - private $credencial; - - /** - * Chave da conta - * @var - */ - private $chave; - - /** - * Filtro: Data inicio do extrato - * @var - */ - private $data_inicio; - - /** - * Filtro: Data fim do extrato - * @var - */ - private $data_fim; - - /** - * Flag que define se o extrato irá mostrar somente - * as cobranças liquidadas - * @var - */ - private $pago; - - /** - * Paginação - * @var int - */ - private $pagina = 1; - - /** - * Itens do extrato - * @var - */ - private $itens; - - /** - * @return mixed - */ - public function getCredencial() - { - return $this->credencial; - } - - /** - * @param mixed $credencial - * @return Extrato - */ - public function setCredencial($credencial) - { - $this->credencial = $credencial; - return $this; - } - - /** - * @return mixed - */ - public function getChave() - { - return $this->chave; - } - - /** - * @param mixed $chave - * @return Extrato - */ - public function setChave($chave) - { - $this->chave = $chave; - return $this; - } - - /** - * @return mixed - */ - public function getDataInicio() - { - return $this->data_inicio; - } - - /** - * @param mixed $data_inicio - * @return Extrato - */ - public function setDataInicio($data_inicio) - { - $this->data_inicio = $data_inicio; - return $this; - } - - /** - * @return mixed - */ - public function getDataFim() - { - return $this->data_fim; - } - - /** - * @param mixed $data_fim - * @return Extrato - */ - public function setDataFim($data_fim) - { - $this->data_fim = $data_fim; - return $this; - } - - /** - * @return mixed - */ - public function getPago() - { - return $this->pago; - } - - /** - * @param mixed $pago - * @return Extrato - */ - public function apenasPagos($pago = true) - { - $this->pago = $pago; - return $this; - } - - /** - * @param int $pagina - * @return $this - */ - public function setPagina($pagina = 1) - { - $this->pagina = $pagina; - return $this; - } - - /** - * Extrato constructor. - * @param $credencial - * @param $chave - */ - public function __construct($credencial, $chave) - { - $this->credencial = $credencial; - $this->chave = $chave; - } - - /** - * Retorna os itens do extrato - * @return mixed - */ - public function getItens() - { - return $this->itens; - } - - - /** - * Retorna os atributos preenchidos para serem emitidos no extrato - * @return array - */ - public function getValues() - { - $objectValues = get_object_vars($this); - $transacaoValues = array(); - foreach ($objectValues as $key => $value) { - if (!is_null($value)) { - $transacaoValues[$key] = $value; - } - } - - return $transacaoValues; - } - - /** - * Gera o extrato propriamente dito - */ - public function gerar() { - - $impressorinha = new Impressorinha($this); - $extrato = $impressorinha->gerar(); - - $this->itens = $extrato->extrato; - - } - + + * @package PJBank\Extrato + */ +class Extrato +{ + + /** + * Credencial da conta + * @var + */ + private $credencial; + + /** + * Chave da conta + * @var + */ + private $chave; + + /** + * Filtro: Data inicio do extrato + * @var + */ + private $data_inicio; + + /** + * Filtro: Data fim do extrato + * @var + */ + private $data_fim; + + /** + * Flag que define se o extrato irá mostrar somente + * as cobranças liquidadas + * @var + */ + private $pago; + + /** + * Paginação + * @var int + */ + private $pagina = 1; + + /** + * Itens do extrato + * @var + */ + private $itens; + + /** + * @return mixed + */ + public function getCredencial() + { + return $this->credencial; + } + + /** + * @param mixed $credencial + * @return Extrato + */ + public function setCredencial($credencial) + { + $this->credencial = $credencial; + return $this; + } + + /** + * @return mixed + */ + public function getChave() + { + return $this->chave; + } + + /** + * @param mixed $chave + * @return Extrato + */ + public function setChave($chave) + { + $this->chave = $chave; + return $this; + } + + /** + * @return mixed + */ + public function getDataInicio() + { + return $this->data_inicio; + } + + /** + * @param mixed $data_inicio + * @return Extrato + */ + public function setDataInicio($data_inicio) + { + $this->data_inicio = $data_inicio; + return $this; + } + + /** + * @return mixed + */ + public function getDataFim() + { + return $this->data_fim; + } + + /** + * @param mixed $data_fim + * @return Extrato + */ + public function setDataFim($data_fim) + { + $this->data_fim = $data_fim; + return $this; + } + + /** + * @return mixed + */ + public function getPago() + { + return $this->pago; + } + + /** + * @param mixed $pago + * @return Extrato + */ + public function apenasPagos($pago = true) + { + $this->pago = $pago; + return $this; + } + + /** + * @param int $pagina + * @return $this + */ + public function setPagina($pagina = 1) + { + $this->pagina = $pagina; + return $this; + } + + /** + * Extrato constructor. + * @param $credencial + * @param $chave + */ + public function __construct($credencial, $chave) + { + $this->credencial = $credencial; + $this->chave = $chave; + } + + /** + * Retorna os itens do extrato + * @return mixed + */ + public function getItens() + { + return $this->itens; + } + + + /** + * Retorna os atributos preenchidos para serem emitidos no extrato + * @return array + */ + public function getValues() + { + $objectValues = get_object_vars($this); + $transacaoValues = array(); + foreach ($objectValues as $key => $value) { + if (!is_null($value)) { + $transacaoValues[$key] = $value; + } + } + + return $transacaoValues; + } + + /** + * Gera o extrato propriamente dito + */ + public function gerar() { + + $impressorinha = new Impressorinha($this); + $extrato = $impressorinha->gerar(); + + $this->itens = $extrato; + + } + } \ No newline at end of file