|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
5
|
|
|
* To change this template file, choose Tools | Templates |
|
6
|
|
|
* and open the template in the editor. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace OBRSDK\HttpClient; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Description of BoletosCliente |
|
13
|
|
|
* |
|
14
|
|
|
* @author Antonio |
|
15
|
|
|
*/ |
|
16
|
|
|
class BoletosCliente extends Nucleo\Instancia { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* |
|
20
|
|
|
* @var \OBRSDK\Entidades\Boletos[] |
|
21
|
|
|
*/ |
|
22
|
|
|
private $boletosParaGerar = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Adiciona um boleto para ser gerado |
|
26
|
|
|
* |
|
27
|
|
|
* @param \OBRSDK\Entidades\Boletos $boleto |
|
28
|
|
|
*/ |
|
29
|
|
|
public function addBoletoParaGerar(\OBRSDK\Entidades\Boletos $boleto) { |
|
30
|
|
|
$this->boletosParaGerar[] = $boleto; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Gera os boletos adicionado na lista |
|
35
|
|
|
* |
|
36
|
|
|
* @param \OBRSDK\Entidades\Abstratos\ABanco $banco |
|
37
|
|
|
* @param \OBRSDK\Entidades\Beneficiario $beneficiario |
|
38
|
|
|
* @param \OBRSDK\Entidades\Boletos[] $boletos |
|
39
|
|
|
* @return \OBRSDK\Entidades\Boletos[] |
|
40
|
|
|
* @throws \OBRSDK\Exceptions\PreenchimentoIncorreto |
|
41
|
|
|
*/ |
|
42
|
|
|
public function gerarBoletos(\OBRSDK\Entidades\Abstratos\ABanco $banco, \OBRSDK\Entidades\Beneficiario $beneficiario) { |
|
43
|
|
|
$resposta = $this->apiCliente->addAuthorization() |
|
44
|
|
|
->postJson('boletos', $this->getBodyGerarBoletos($banco, $beneficiario)) |
|
45
|
|
|
->getRespostaArray(); |
|
46
|
|
|
|
|
47
|
|
|
$quantidadeBoletos = !isset($resposta['boletos']) ? 0 : count($resposta['boletos']); |
|
48
|
|
|
|
|
49
|
|
|
$boletos = $this->boletosParaGerar; |
|
50
|
|
|
for ($i = 0; $i < $quantidadeBoletos; $i++) { |
|
51
|
|
|
$boletos[$i]->setAtributos($resposta['boletos'][$i]); |
|
52
|
|
|
} |
|
53
|
|
|
$this->boletosParaGerar = []; |
|
54
|
|
|
|
|
55
|
|
|
return $boletos; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* |
|
60
|
|
|
* @param \OBRSDK\Entidades\Beneficiario $beneficiario |
|
61
|
|
|
* @param array $query_string_opcional |
|
62
|
|
|
* @return \OBRSDK\Entidades\Boletos[] |
|
63
|
|
|
*/ |
|
64
|
|
|
public function listarBoletos(\OBRSDK\Entidades\Beneficiario $beneficiario, array $query_string_opcional) { |
|
65
|
|
|
$query_string = array_merge($beneficiario->getAtributes(), $query_string_opcional); |
|
66
|
|
|
|
|
67
|
|
|
$this->apiCliente->addAuthorization() |
|
68
|
|
|
->get('boletos', $query_string); |
|
69
|
|
|
|
|
70
|
|
|
return $this->getListaEntidade('boletos', new \OBRSDK\Entidades\Boletos()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* |
|
75
|
|
|
* @param \OBRSDK\Entidades\Abstratos\ABanco $banco |
|
76
|
|
|
* @param \OBRSDK\Entidades\Beneficiario $beneficiario |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
private function getBodyGerarBoletos(\OBRSDK\Entidades\Abstratos\ABanco $banco, \OBRSDK\Entidades\Beneficiario $beneficiario) { |
|
80
|
|
|
$boletos_dados = []; |
|
81
|
|
|
foreach ($this->boletosParaGerar as $boleto) { |
|
82
|
|
|
$boletos_dados[] = $boleto->getAtributes(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return [ |
|
86
|
|
|
$banco->getNomeBancoJson() => $banco->getAtributes(), |
|
87
|
|
|
"beneficiario" => $beneficiario->getAtributes(), |
|
88
|
|
|
"boletos" => $boletos_dados |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|