|
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){ |
|
|
|
|
|
|
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){ |
|
|
|
|
|
|
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){ |
|
|
|
|
|
|
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){ |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// Estorna cobrança |
|
83
|
|
|
public function estorno($id){ |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// Confirmação em dinheiro |
|
88
|
|
|
public function confirmacao($id, $dados){ |
|
|
|
|
|
|
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
|
|
|
|