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(Connection $connection) |
||||||
12 | { |
||||||
13 | $this->http = $connection; |
||||||
14 | } |
||||||
15 | |||||||
16 | // Retorna a listagem de cobranças |
||||||
17 | public function getAll(array $filtros){ |
||||||
18 | $filtro = ''; |
||||||
19 | if(is_array($filtros)){ |
||||||
20 | if($filtros){ |
||||||
0 ignored issues
–
show
|
|||||||
21 | foreach($filtros as $key => $f){ |
||||||
22 | if(!empty($f)){ |
||||||
23 | if($filtro){ |
||||||
24 | $filtro .= '&'; |
||||||
25 | } |
||||||
26 | $filtro .= $key.'='.$f; |
||||||
27 | } |
||||||
28 | } |
||||||
29 | $filtro = '?'.$filtro; |
||||||
30 | } |
||||||
31 | } |
||||||
32 | return $this->http->get('/payments'.$filtro); |
||||||
33 | } |
||||||
34 | |||||||
35 | // Retorna os dados da cobrança de acordo com o Id |
||||||
36 | public function getById($id){ |
||||||
37 | return $this->http->get('/payments/'.$id); |
||||||
38 | } |
||||||
39 | |||||||
40 | // Retorna a listagem de cobranças de acordo com o Id do Cliente |
||||||
41 | public function getByCustomer($customer_id){ |
||||||
42 | return $this->http->get('/payments?customer='.$customer_id); |
||||||
43 | } |
||||||
44 | |||||||
45 | // Retorna a listagem de cobranças de acordo com o Id da Assinaturas |
||||||
46 | public function getBySubscription($subscription_id){ |
||||||
47 | return $this->http->get('/payments?subscription='.$subscription_id); |
||||||
48 | } |
||||||
49 | |||||||
50 | // Insere uma nova cobrança |
||||||
51 | public function create(array $dadosCobranca){ |
||||||
52 | $dadosCobranca = $this->setCobranca($dadosCobranca); |
||||||
53 | if(!empty($dadosCobranca['error'])){ |
||||||
54 | return $dadosCobranca; |
||||||
55 | }else { |
||||||
56 | return $this->http->post('/payments', $dadosCobranca); |
||||||
57 | } |
||||||
58 | } |
||||||
59 | |||||||
60 | // Insere uma nova cobrança parcelada |
||||||
61 | public function parcelada(array $dadosCobranca){ |
||||||
0 ignored issues
–
show
The parameter
$dadosCobranca is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
62 | |||||||
63 | } |
||||||
64 | |||||||
65 | // Insere uma nova cobrança com split |
||||||
66 | /* Saldo dividido em multiplas contas do Asaas*/ |
||||||
67 | public function split(array $dadosCobranca){ |
||||||
0 ignored issues
–
show
The parameter
$dadosCobranca is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
68 | |||||||
69 | } |
||||||
70 | |||||||
71 | // Atualiza os dados da cobrança |
||||||
72 | public function update($id, array $dadosCobranca){ |
||||||
73 | |||||||
74 | return $this->http->post('/payments/' . $id, $dadosCobranca); |
||||||
75 | } |
||||||
76 | |||||||
77 | // Restaura cobrança removida |
||||||
78 | public function restore($id){ |
||||||
0 ignored issues
–
show
The parameter
$id is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
79 | |||||||
80 | } |
||||||
81 | |||||||
82 | // Estorna cobrança |
||||||
83 | public function estorno($id){ |
||||||
0 ignored issues
–
show
The parameter
$id is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
84 | |||||||
85 | } |
||||||
86 | |||||||
87 | // Confirmação em dinheiro |
||||||
88 | public function confirmacao($id, $dados){ |
||||||
0 ignored issues
–
show
The parameter
$id is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$dados is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
89 | $data = array( |
||||||
90 | "paymentDate" => "2019-09-03", |
||||||
91 | "value" => 100.00, |
||||||
92 | ); |
||||||
93 | return $this->http->post('/customers', $data); |
||||||
94 | } |
||||||
95 | |||||||
96 | // Deleta uma cobrança |
||||||
97 | public function delete($id){ |
||||||
98 | return $this->http->get('/payments/'.$id,'','DELETE'); |
||||||
99 | } |
||||||
100 | |||||||
101 | /** |
||||||
102 | * Cria um novo boleto no Asaas. |
||||||
103 | * @param Array $cliente |
||||||
104 | * @return Boolean |
||||||
105 | */ |
||||||
106 | public function create2($dados) |
||||||
107 | { |
||||||
108 | // Preenche as informações da cobranca |
||||||
109 | $cobranca = $this->setCobranca($dados); |
||||||
110 | |||||||
111 | // Faz o post e retorna array de resposta |
||||||
112 | return $this->http->post('/payments', ['form_params' => $cobranca]); |
||||||
113 | } |
||||||
114 | |||||||
115 | /** |
||||||
116 | * Faz merge nas informações das cobranças. |
||||||
117 | * |
||||||
118 | * @see https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobrancas |
||||||
119 | * @param Array $cliente |
||||||
120 | * @return Array |
||||||
121 | */ |
||||||
122 | public function setCobranca($dados) |
||||||
123 | { |
||||||
124 | try { |
||||||
125 | $this->cobranca = array( |
||||||
126 | 'customer' => '', |
||||||
127 | 'billingType' => '', |
||||||
128 | 'value' => '', |
||||||
129 | 'dueDate' => '', |
||||||
130 | 'description' => '', |
||||||
131 | 'externalReference' => '', |
||||||
132 | 'installmentCount' => '', |
||||||
133 | 'installmentValue' => '', |
||||||
134 | 'discount' => '', |
||||||
135 | 'interest' => '', |
||||||
136 | 'fine' => '', |
||||||
137 | ); |
||||||
138 | |||||||
139 | $this->cobranca = array_merge($this->cobranca, $dados); |
||||||
140 | return $this->cobranca; |
||||||
141 | |||||||
142 | } catch (Exception $e) { |
||||||
143 | return 'Erro ao definir o cliente. - ' . $e->getMessage(); |
||||||
144 | } |
||||||
145 | } |
||||||
146 | |||||||
147 | /** |
||||||
148 | * Faz merge nas informações das cobranças. |
||||||
149 | * |
||||||
150 | * @see https://asaasv3.docs.apiary.io/#reference/0/cobrancas/criar-nova-cobrancas |
||||||
151 | * @param Array $cliente |
||||||
152 | * @return Array |
||||||
153 | */ |
||||||
154 | public function setCobrancaCartao($dados) |
||||||
155 | { |
||||||
156 | try { |
||||||
157 | $this->cobranca = array( |
||||||
158 | 'customer' => '', |
||||||
159 | 'billingType' => '', |
||||||
160 | 'value' => '', |
||||||
161 | 'dueDate' => '', |
||||||
162 | 'description' => '', |
||||||
163 | 'externalReference' => '', |
||||||
164 | 'installmentCount' => '', |
||||||
165 | 'installmentValue' => '', |
||||||
166 | 'discount' => '', |
||||||
167 | 'interest' => '', |
||||||
168 | 'fine' => '', |
||||||
169 | ); |
||||||
170 | |||||||
171 | $this->cobranca = array_merge($this->cobranca, $dados); |
||||||
172 | return $this->cobranca; |
||||||
173 | |||||||
174 | } catch (Exception $e) { |
||||||
175 | return 'Erro ao definir o cliente. - ' . $e->getMessage(); |
||||||
176 | } |
||||||
177 | } |
||||||
178 | } |
||||||
179 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.