Your IP : 216.73.216.84


Current Path : /home/helpink/www/components/com_jbusinessdirectory/classes/payment/processors/Asaas/
Upload File :
Current File : /home/helpink/www/components/com_jbusinessdirectory/classes/payment/processors/Asaas/Payment.php

<?php

namespace CodePhix\Asaas;

use CodePhix\Asaas\Connection;
use \Exception;

class Payment {
    public $http;
    protected $payment;

    public function __construct(Connection $connection)
    {
        $this->http = $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 Customer
    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 $paymentData){
        $paymentData = $this->setPayment($paymentData);
        if(!empty($paymentData['error'])){
            return $paymentData;
        }else {
            return $this->http->post('/payments', $paymentData);
        }
    }

    // Atualiza os dados da cobrança
    public function update($id, array $paymentData){
        return $this->http->post('/payments/' . $id, $paymentData);
    }

    // Atualiza os dados da cobrança
    public function getInfoBoleto($id){
        return $this->http->post('/payments/'.$id.'/identificationField', []);
    }

    // Restaura cobrança removida
    public function restore($id){
        return $this->http->post("/payments/{$id}/restore", []);
    }

    // Estorna cobrança
    public function estorno($id){
        return $this->http->post("/payments/{$id}/refund", []);
    }

    // Confirmação em dinheiro
    public function confirmacao($id, $data){
        return $this->http->post("/payments/{$id}/receiveInCash", array());
    }
    // Confirmação em dinheiro
    public function dezconfirmacao($id, $data){
        return $this->http->post("/payments/{$id}/undoReceivedInCash", array());
    }

    // Deleta uma cobrança
    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 $customer
     * @return Boolean
     */
    public function create2($data)
    {
        // Preenche as informações da cobranca
        $payment = $this->setPayment($data);

        // Faz o post e retorna array de resposta
        return $this->http->post('/payments', ['form_params' => $payment]);
    }

    /**
     * Faz merge nas informações das cobranças.
     *
     * @see https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobrancas
     * @param Array $customer
     * @return Array
     */
    public function setPayment($data)
    {
        try {
            $this->payment = array(
                'customer'             => '',
                'billingType'          => '',
                'value'                => '',
                'dueDate'              => '',
                'description'          => '',
                'externalReference'    => '',
                'installmentCount'     => '',
                'installmentValue'     => '',
                'discount'             => '',
                'interest'             => '',
                'fine'                 => '',
            );

            $this->payment = array_merge($this->payment, $data);
            return $this->payment;

        } 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 $customer
     * @return Array
     */
    public function setCobrancaCartao($data)
    {
        try {
            $this->payment = array(
                'customer'             => '',
                'billingType'          => '',
                'value'                => '',
                'dueDate'              => '',
                'description'          => '',
                'externalReference'    => '',
                'installmentCount'     => '',
                'installmentValue'     => '',
                'discount'             => '',
                'interest'             => '',
                'fine'                 => '',
            );

            $this->payment = array_merge($this->payment, $data);
            return $this->payment;

        } catch (Exception $e) {
            return 'Erro ao definir o cliente. - ' . $e->getMessage();
        }
    }
}