Passed
Push — master ( 230365...2345ea )
by Max Alex
01:50
created

Cobranca::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CodePhix\Asaas;
4
5
use CodePhix\Asaas\Connection;
6
7
class Cobranca {
8
    public $http;
9
    protected $cobranca;
10
    
11
    public function __construct()
12
    {
13
        $this->http = new Connection;
14
    }
15
16
    /**
17
     * Cria um novo boleto no Asaas.
18
     * @param Array $cliente
19
     * @return Boolean
20
     */
21
    public function create($dados)
22
    {
23
        // Preenche as informações da cobranca
24
        $cobranca = $this->setCobranca($dados);
25
        
26
        // Faz o post e retorna array de resposta
27
        return $this->http->post('/payments', ['form_params' => $cobranca]);
28
    }
29
    
30
    /**
31
     * Faz merge nas informações das cobranças.
32
     * 
33
     * @see https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobrancas
34
     * @param Array $cliente
35
     * @return Array
36
     */
37
    public function setCobranca($dados)
38
    {
39
        try {
40
            
41
            $this->cobranca = array(
42
                'customer'             => '',
43
                'billingType'          => '',
44
                'value'                => '',
45
                'dueDate'              => '',
46
                'description'          => '',
47
                'externalReference'    => '',
48
                'installmentCount'     => '',
49
                'installmentValue'     => '',
50
                'discount'             => '',
51
                'interest'             => '',
52
                'fine'                 => '',
53
            );
54
            
55
            $this->cobranca = array_merge($this->cobranca, $dados);
56
            return $this->cobranca;
57
            
58
        } catch (Exception $e) {
59
            return 'Erro ao definir o cliente. - ' . $e->getMessage();
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'Erro ao definir ... - ' . $e->getMessage() returns the type string which is incompatible with the documented return type array.
Loading history...
60
        }
61
    }
62
}
63