diff --git a/README.md b/README.md index ba25b07..dd9aa36 100755 --- a/README.md +++ b/README.md @@ -105,13 +105,32 @@ $cobranca = $asaas->Cobranca()->estorno(id); $cobranca = $asaas->Cobranca()->confirmacao(id); // Desfazer confirmação de recebimento em dinheiro -$cobranca = $asaas->Cobranca()->confirmacao(id); +$cobranca = $asaas->Cobranca()->dezconfirmacao(id); // Deleta uma cobrança $asaas->Cobranca()->delete(123); ``` +Pix +------------ + +Para criar o pix, precisa ser adicionar uma cobrança e com esse id da cobrança será gerado o qrCode do pix, lembrando o qrCode é gerado até as 23:59h do mesmo dia. +O QrCode vem em base64. + +```php + +$Pix = $asaas->Pix()->create($id_cobranca); +if($Pix->success){ + echo ''; +} + +//Consulta se foi efetivado o pagamento via Pix, (Obs: Recomendo um post a cada 30s, ou um botão para confirmação do pagamento, assim não sobrecarregado o seu sistema e nem o do asaas ;) ). +$retorno = $asaas->Pix()->get($id_cobranca); + +``` + + Link de Pagamemto ------------ diff --git a/composer.json b/composer.json index 5964020..8e23af3 100644 --- a/composer.json +++ b/composer.json @@ -8,12 +8,12 @@ "authors": [ { "name": "Max Alex", - "email": "contato@codephix.com.br", + "email": "contato@codephix.com", "homepage": "https://www.codephix.com" } ], "require": { - "php": "^7.2" + "php": "^7.2|^8.0" }, "autoload": { "psr-4": { diff --git a/.DS_Store b/src/.DS_Store similarity index 83% rename from .DS_Store rename to src/.DS_Store index 0be8f8a..3e72e0d 100644 Binary files a/.DS_Store and b/src/.DS_Store differ diff --git a/src/Asaas.php b/src/Asaas.php index a4583f5..d4f0eea 100755 --- a/src/Asaas.php +++ b/src/Asaas.php @@ -27,6 +27,8 @@ class Asaas { public $MinhaConta; public $InformacoesFiscais; public $ConsultaSerasa; + public $Pix; + public $Parcelamento; private $connection; @@ -48,6 +50,8 @@ public function __construct($token, $status = false) { $this->InformacoesFiscais = new InformacoesFiscais($this->connection); $this->ConsultaSerasa = new ConsultaSerasa($this->connection); $this->webhook = new Webhook($this->connection); + $this->Pix = new Pix($this->connection); + $this->Parcelamento = new Parcelamento($this->connection); } public function Assinatura(){ @@ -55,6 +59,16 @@ public function Assinatura(){ return $this->assinatura; } + public function Pix(){ + $this->Pix = new Pix($this->connection); + return $this->Pix; + } + + public function Parcelamento(){ + $this->Parcelamento = new Parcelamento($this->connection); + return $this->Parcelamento; + } + public function Cidade(){ $this->cidade = new Cidades($this->connection); return $this->cidade; diff --git a/src/Cliente.php b/src/Cliente.php index abfbae1..ce00344 100755 --- a/src/Cliente.php +++ b/src/Cliente.php @@ -183,6 +183,6 @@ public function setCliente($cliente) */ public function cliente_valid($cliente) { - return ! ( (empty($cliente['name']) OR empty($cliente['cpfCnpj']) OR empty($cliente['email'])) ? 1 : '' ); + return ! ( (empty($cliente['name']) OR empty($cliente['cpfCnpj'])) ? 1 : '' ); } -} \ No newline at end of file +} diff --git a/src/Cobranca.php b/src/Cobranca.php index 2a02d27..ac66c71 100755 --- a/src/Cobranca.php +++ b/src/Cobranca.php @@ -74,11 +74,12 @@ public function estorno($id){ // Confirmação em dinheiro public function confirmacao($id, $dados){ - return $this->http->post("/payments/{$id}/receiveInCash", array()); + return $this->http->post("/payments/{$id}/receiveInCash", $dados); } - // Confirmação em dinheiro - public function dezconfirmacao($id, $dados){ - return $this->http->post("/payments/{$id}/undoReceivedInCash", array()); + + // Desconfirmação em dinheiro + public function desconfirmacao($id, $dados){ + return $this->http->post("/payments/{$id}/undoReceivedInCash", $dados); } // Deleta uma cobrança @@ -86,6 +87,15 @@ public function delete($id){ return $this->http->get('/payments/'.$id,'','DELETE'); } + + + // Retorna a listagem de cobranças de acordo com o Id da Assinaturas + public function Carner($id){ + return $this->http->get('/installments/id'.$id); + } + + + /** * Cria um novo boleto no Asaas. * @param Array $cliente diff --git a/src/ConsultaSerasa.php b/src/ConsultaSerasa.php old mode 100644 new mode 100755 diff --git a/src/InformacoesFiscais.php b/src/InformacoesFiscais.php old mode 100644 new mode 100755 diff --git a/src/LinkPagamento.php b/src/LinkPagamento.php old mode 100644 new mode 100755 diff --git a/src/MinhaConta.php b/src/MinhaConta.php old mode 100644 new mode 100755 diff --git a/src/NotaFiscal.php b/src/NotaFiscal.php old mode 100644 new mode 100755 index 5f6fca1..fd078de --- a/src/NotaFiscal.php +++ b/src/NotaFiscal.php @@ -41,10 +41,10 @@ public function ListMunicipalServices($parametos){ } public function issueInvoice($id){ - return $this->http->post('/invoices/'.$id.'/authorize', arrat()); + return $this->http->post('/invoices/'.$id.'/authorize', array()); } - public function create($id){ + public function create($dadosConta){ return $this->http->post('/invoices', $dadosConta); } @@ -53,7 +53,7 @@ public function update($id, $dadosConta){ } public function cancel($id){ - return $this->http->post('/invoices/'.$id.'/cancel', []); + return $this->http->post('/invoices/'.$id.'/cancel', array()); } } diff --git a/src/Parcelamento.php b/src/Parcelamento.php new file mode 100755 index 0000000..8460fb1 --- /dev/null +++ b/src/Parcelamento.php @@ -0,0 +1,77 @@ +http = $connection; + } + + // Retorna a listagem de cobranças + public function getAll(array $filtros = array()){ + $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('/installments'.$filtro); + } + + // Retorna os dados da cobrança de acordo com o Id + public function getById($id){ + return $this->http->get('/installments/'.$id); + } + + // Retorna os dados da cobrança de acordo com o Id + public function getBeefPdf($id){ + $id = str_replace( + array( + 'ins_00000000000', + 'ins_0000000000', + 'ins_000000000', + 'ins_00000000', + 'ins_0000000', + 'ins_000000', + 'ins_00000', + 'ins_0000', + 'ins_000', + 'ins_00', + 'ins_0', + 'ins_' + ),'',$id); + + $link = $this->http->base_url.'.asaas.com/installment/paymentBook/'.$id; + return $link; + } + + // Retorna a listagem de cobranças de acordo com o Id do Cliente + public function getByCustomer($customer_id){ + return $this->http->get('/installments?customer='.$customer_id); + } + + // Estorna cobrança + public function estorno($id){ + return $this->http->post("/installment/{$id}/refund", []); + } + + // Deleta uma cobrança + public function delete($id){ + return $this->http->get('/installments/'.$id,'','DELETE'); + } + +} diff --git a/src/Pix.php b/src/Pix.php new file mode 100755 index 0000000..9ab0a27 --- /dev/null +++ b/src/Pix.php @@ -0,0 +1,81 @@ +http = $connection; + } + + //https://www.asaas.com/api/v3/payments/id/pixQrCode + + //Retorna informação via Pix, para conta com liberação. + public function create($id) + { + + $resturn = $this->http->get('/payments/'.$id.'/pixQrCode'); + + if(!empty($resturn->encodedImage)){ + $resturn->success = 1; + return $resturn; + }else{ + return json_encode(array('success' => false)); + } + + /* + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://www.asaas.com/pixQrCode/createAsaasPaymentQrCode/'.$id); + 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" + )); + + $response = curl_exec($ch); + curl_close($ch); + $response = json_decode($response); + + //$response = $this->http->request('GET', $this->base_url . $url); + + return $response;*/ + } + + //Retorna informação via Pix, para conta com liberação. + public function get($id) + { + + $id = str_replace('pay_','',$id); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://www.asaas.com/payment/isReceivedPayment/'.$id); + 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" + )); + + $response = curl_exec($ch); + curl_close($ch); + $response = json_decode($response); + + //$response = $this->http->request('GET', $this->base_url . $url); + + return $response; + } + +}