Completed
Push — master ( ea3bff...7fe9cf )
by Francimar
05:27
created

Pagamento::getForma()   D

Complexity

Conditions 19
Paths 19

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 152.5669

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 11
cts 39
cp 0.2821
rs 4.5166
c 0
b 0
f 0
cc 19
nc 19
nop 1
crap 152.5669

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * MIT License
5
 *
6
 * Copyright (c) 2016 GrandChef Desenvolvimento de Sistemas LTDA
7
 *
8
 * @author Francimar Alves <[email protected]>
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * of this software and associated documentation files (the "Software"), to deal
12
 * in the Software without restriction, including without limitation the rights
13
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * copies of the Software, and to permit persons to whom the Software is
15
 * furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included in all
18
 * copies or substantial portions of the Software.
19
 *
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
 * SOFTWARE.
27
 *
28
 */
29
30
namespace NFe\Entity;
31
32
use NFe\Common\Node;
33
use NFe\Common\Util;
34
35
class Pagamento implements Node
36
{
37
    /**
38
     * Indicador da forma de pagamento: 0 – pagamento à vista; 1 – pagamento à
39
     * prazo.
40
     */
41
    public const INDICADOR_AVISTA = 'avista';
42
    public const INDICADOR_APRAZO = 'aprazo';
43
44
    /**
45
     * Forma de Pagamento:01-Dinheiro;02-Cheque;03-Cartão de Crédito;04-Cartão
46
     * de Débito;05-Crédito Loja;10-Vale Alimentação;11-Vale Refeição;12-Vale
47
     * Presente;13-Vale Combustível;14 - Duplicata Mercantil;15 - Boleto
48
     * Bancario;16=Depósito Bancário;17=Pagamento Instantâneo
49
     * (PIX);18=Transferência bancária, Carteira Digital;19=Programa de
50
     * fidelidade, Cashback, Crédito Virtual.;90 - Sem Pagamento;99 - Outros
51
     */
52
    public const FORMA_DINHEIRO = 'dinheiro';
53
    public const FORMA_CHEQUE = 'cheque';
54
    public const FORMA_CREDITO = 'credito';
55
    public const FORMA_DEBITO = 'debito';
56
    public const FORMA_CREDIARIO = 'crediario';
57
    public const FORMA_ALIMENTACAO = 'alimentacao';
58
    public const FORMA_REFEICAO = 'refeicao';
59
    public const FORMA_PRESENTE = 'presente';
60
    public const FORMA_COMBUSTIVEL = 'combustivel';
61
    public const FORMA_DUPLICATA = 'duplicata';
62
    public const FORMA_BOLETO = 'boleto';
63
    public const FORMA_DEPOSITO = 'deposito';
64
    public const FORMA_INSTANTANEO = 'instantaneo';
65
    public const FORMA_TRANSFERENCIA = 'transferencia';
66
    public const FORMA_FIDELIDADE = 'fidelidade';
67
    public const FORMA_CORTESIA = 'cortesia';
68
    public const FORMA_OUTROS = 'outros';
69
70
    /**
71
     * Bandeira da operadora de cartão de crédito/débito:01–Visa;
72
     * 02–Mastercard; 03–American Express; 04–Sorocred;05-Diners
73
     * Club;06-Elo;07-Hipercard;08-Aura;09-Cabal;99–Outros
74
     */
75
    public const BANDEIRA_VISA = 'visa';
76
    public const BANDEIRA_MASTERCARD = 'mastercard';
77
    public const BANDEIRA_AMEX = 'amex';
78
    public const BANDEIRA_SOROCRED = 'sorocred';
79
    public const BANDEIRA_DINERS = 'diners';
80
    public const BANDEIRA_ELO = 'elo';
81
    public const BANDEIRA_HIPERCARD = 'hipercard';
82
    public const BANDEIRA_AURA = 'aura';
83
    public const BANDEIRA_CABAL = 'cabal';
84
    public const BANDEIRA_OUTROS = 'outros';
85
86
    /**
87
     * Indicador da forma de pagamento: 0 – pagamento à vista; 1 – pagamento à
88
     * prazo.
89
     */
90
    private $indicador;
91
92
    /**
93
     * Forma de Pagamento:01-Dinheiro;02-Cheque;03-Cartão de Crédito;04-Cartão
94
     * de Débito;05-Crédito Loja;10-Vale Alimentação;11-Vale Refeição;12-Vale
95
     * Presente;13-Vale Combustível;14 - Duplicata Mercantil;15 - Boleto
96
     * Bancario;16=Depósito Bancário;17=Pagamento Instantâneo
97
     * (PIX);18=Transferência bancária, Carteira Digital;19=Programa de
98
     * fidelidade, Cashback, Crédito Virtual.;90 - Sem Pagamento;99 - Outros
99
     *
100
     * @var string
101
     */
102
    private $forma;
103
104
    /**
105
     * Valor do Pagamento
106
     *
107
     * @var float
108
     */
109
    private $valor;
110
111
    /**
112
     * Tipo de Integração do processo de pagamento com o sistema de automação
113
     * da empresa/1=Pagamento integrado com o sistema de automação da empresa
114
     * Ex. equipamento TEF , Comercio Eletronico 2=Pagamento não integrado com
115
     * o sistema de automação da empresa Ex: equipamento POS
116
     *
117
     * @var string
118
     */
119
    private $integrado;
120
121
    /**
122
     * CNPJ da credenciadora de cartão de crédito/débito
123
     *
124
     * @var string
125
     */
126
    private $credenciadora;
127
128
    /**
129
     * Número de autorização da operação cartão de crédito/débito
130
     *
131
     * @var string
132
     */
133
    private $autorizacao;
134
135
    /**
136
     * Bandeira da operadora de cartão de crédito/débito:01–Visa;
137
     * 02–Mastercard; 03–American Express; 04–Sorocred;05-Diners
138
     * Club;06-Elo;07-Hipercard;08-Aura;09-Cabal;99–Outros
139
     *
140
     * @var string
141
     */
142
    private $bandeira;
143
144
    /**
145
     * Constroi uma instância de Pagamento vazia
146
     * @param array $pagamento Array contendo dados do Pagamento
147
     */
148 41
    public function __construct($pagamento = [])
149
    {
150 41
        $this->fromArray($pagamento);
151 41
    }
152
153
    /**
154
     * Indicador da forma de pagamento: 0 – pagamento à vista; 1 – pagamento à
155
     * prazo.
156
     * @param boolean $normalize informa se o indicador deve estar no formato do XML
157
     * @return mixed indicador da Nota
158
     */
159 40
    public function getIndicador($normalize = false)
160
    {
161 40
        if (!$normalize) {
162 40
            return $this->indicador;
163
        }
164 1
        switch ($this->indicador) {
165 1
            case self::INDICADOR_AVISTA:
166 1
                return '0';
167 1
            case self::INDICADOR_APRAZO:
168 1
                return '1';
169
        }
170 1
        return $this->indicador;
171
    }
172
173
    /**
174
     * Altera o valor do Indicador para o informado no parâmetro
175
     * @param mixed $indicador novo valor para Indicador
176
     * @return Nota A própria instância da classe
177
     */
178 41
    public function setIndicador($indicador)
179
    {
180
        switch ($indicador) {
181 41
            case '0':
182 1
                $indicador = self::INDICADOR_AVISTA;
183 1
                break;
184 41
            case '1':
185 1
                $indicador = self::INDICADOR_APRAZO;
186 1
                break;
187
        }
188 41
        $this->indicador = $indicador;
189 41
        return $this;
190
    }
191
192
    /**
193
     * Forma de Pagamento:01-Dinheiro;02-Cheque;03-Cartão de Crédito;04-Cartão
194
     * de Débito;05-Crédito Loja;10-Vale Alimentação;11-Vale Refeição;12-Vale
195
     * Presente;13-Vale Combustível;14 - Duplicata Mercantil;15 - Boleto
196
     * Bancario;16=Depósito Bancário;17=Pagamento Instantâneo
197
     * (PIX);18=Transferência bancária, Carteira Digital;19=Programa de
198
     * fidelidade, Cashback, Crédito Virtual.;90 - Sem Pagamento;99 - Outros
199
     * @param boolean $normalize informa se o forma deve estar no formato do XML
200
     * @return string forma of Pagamento
201
     */
202 39
    public function getForma($normalize = false)
203
    {
204 39
        if (!$normalize) {
205 39
            return $this->forma;
206
        }
207 38
        switch ($this->forma) {
208 38
            case self::FORMA_DINHEIRO:
209 34
                return '01';
210 36
            case self::FORMA_CHEQUE:
211
                return '02';
212 36
            case self::FORMA_CREDITO:
213 34
                return '03';
214 2
            case self::FORMA_DEBITO:
215 2
                return '04';
216
            case self::FORMA_CREDIARIO:
217
                return '05';
218
            case self::FORMA_ALIMENTACAO:
219
                return '10';
220
            case self::FORMA_REFEICAO:
221
                return '11';
222
            case self::FORMA_PRESENTE:
223
                return '12';
224
            case self::FORMA_COMBUSTIVEL:
225
                return '13';
226
            case self::FORMA_DUPLICATA:
227
                return '14';
228
            case self::FORMA_BOLETO:
229
                return '15';
230
            case self::FORMA_DEPOSITO:
231
                return '16';
232
            case self::FORMA_INSTANTANEO:
233
                return '17';
234
            case self::FORMA_TRANSFERENCIA:
235
                return '18';
236
            case self::FORMA_FIDELIDADE:
237
                return '19';
238
            case self::FORMA_CORTESIA:
239
                return '90';
240
            case self::FORMA_OUTROS:
241
                return '99';
242
        }
243
        return $this->forma;
244
    }
245
246
    /**
247
     * Altera o valor do Forma para o informado no parâmetro
248
     * @param mixed $forma novo valor para Forma
249
     * @param string $forma Novo forma para Pagamento
250
     * @return self A própria instância da classe
251
     */
252 41
    public function setForma($forma)
253
    {
254
        switch ($forma) {
255 41
            case '01':
256 29
                $forma = self::FORMA_DINHEIRO;
257 29
                break;
258 41
            case '02':
259
                $forma = self::FORMA_CHEQUE;
260
                break;
261 41
            case '03':
262 29
                $forma = self::FORMA_CREDITO;
263 29
                break;
264 41
            case '04':
265 1
                $forma = self::FORMA_DEBITO;
266 1
                break;
267 41
            case '05':
268
                $forma = self::FORMA_CREDIARIO;
269
                break;
270 41
            case '10':
271
                $forma = self::FORMA_ALIMENTACAO;
272
                break;
273 41
            case '11':
274
                $forma = self::FORMA_REFEICAO;
275
                break;
276 41
            case '12':
277
                $forma = self::FORMA_PRESENTE;
278
                break;
279 41
            case '13':
280
                $forma = self::FORMA_COMBUSTIVEL;
281
                break;
282 41
            case '14':
283
                $forma = self::FORMA_DUPLICATA;
284
                break;
285 41
            case '15':
286
                $forma = self::FORMA_BOLETO;
287
                break;
288 41
            case '16':
289
                $forma = self::FORMA_DEPOSITO;
290
                break;
291 41
            case '17':
292
                $forma = self::FORMA_INSTANTANEO;
293
                break;
294 41
            case '18':
295
                $forma = self::FORMA_TRANSFERENCIA;
296
                break;
297 41
            case '19':
298
                $forma = self::FORMA_FIDELIDADE;
299
                break;
300 41
            case '90':
301
                $forma = self::FORMA_CORTESIA;
302
                break;
303 41
            case '99':
304
                $forma = self::FORMA_OUTROS;
305
                break;
306
        }
307 41
        $this->forma = $forma;
308 41
        return $this;
309
    }
310
311
    /**
312
     * Valor do Pagamento
313
     * @param boolean $normalize informa se a valor deve estar no formato do XML
314
     * @return float valor of Pagamento
315
     */
316 40
    public function getValor($normalize = false)
317
    {
318 40
        if (!$normalize) {
319 40
            return $this->valor;
320
        }
321 40
        return Util::toCurrency($this->valor);
322
    }
323
324
    /**
325
     * Altera o valor da Valor para o informado no parâmetro
326
     * @param mixed $valor novo valor para Valor
327
     * @param float $valor Novo valor para Pagamento
328
     * @return self A própria instância da classe
329
     */
330 41
    public function setValor($valor)
331
    {
332 41
        $valor = floatval($valor);
333 41
        $this->valor = $valor;
334 41
        return $this;
335
    }
336
337
    /**
338
     * Tipo de Integração do processo de pagamento com o sistema de automação
339
     * da empresa/1=Pagamento integrado com o sistema de automação da empresa
340
     * Ex. equipamento TEF , Comercio Eletronico 2=Pagamento não integrado com
341
     * o sistema de automação da empresa Ex: equipamento POS
342
     * @param boolean $normalize informa se o integrado deve estar no formato do XML
343
     * @return string integrado of Pagamento
344
     */
345 38
    public function getIntegrado($normalize = false)
346
    {
347 38
        if (!$normalize) {
348 11
            return $this->integrado;
349
        }
350 36
        return $this->isIntegrado() ? '1' : '2';
351
    }
352
353
    /**
354
     * Tipo de Integração do processo de pagamento com o sistema de automação
355
     * da empresa/1=Pagamento integrado com o sistema de automação da empresa
356
     * Ex. equipamento TEF , Comercio Eletronico 2=Pagamento não integrado com
357
     * o sistema de automação da empresa Ex: equipamento POS
358
     * @return boolean informa se o Integrado está habilitado
359
     */
360 36
    public function isIntegrado()
361
    {
362 36
        return $this->integrado == 'Y';
363
    }
364
365
    /**
366
     * Altera o valor do Integrado para o informado no parâmetro
367
     * @param mixed $integrado novo valor para Integrado
368
     * @param string $integrado Novo integrado para Pagamento
369
     * @return self A própria instância da classe
370
     */
371 41
    public function setIntegrado($integrado)
372
    {
373 41
        if (is_bool($integrado)) {
374
            $integrado = $integrado ? 'Y' : 'N';
375
        }
376 41
        $this->integrado = in_array($integrado, ['Y', '1']) ? 'Y' : 'N';
377 41
        return $this;
378
    }
379
380
    /**
381
     * CNPJ da credenciadora de cartão de crédito/débito
382
     * @param boolean $normalize informa se a credenciadora deve estar no formato do XML
383
     * @return string credenciadora of Pagamento
384
     */
385 38
    public function getCredenciadora($normalize = false)
386
    {
387 38
        if (!$normalize) {
388 37
            return $this->credenciadora;
389
        }
390 2
        return $this->credenciadora;
391
    }
392
393
    /**
394
     * Altera o valor da Credenciadora para o informado no parâmetro
395
     * @param mixed $credenciadora novo valor para Credenciadora
396
     * @param string $credenciadora Novo credenciadora para Pagamento
397
     * @return self A própria instância da classe
398
     */
399 41
    public function setCredenciadora($credenciadora)
400
    {
401 41
        $this->credenciadora = $credenciadora;
402 41
        return $this;
403
    }
404
405
    /**
406
     * Número de autorização da operação cartão de crédito/débito
407
     * @param boolean $normalize informa se a autorizacao deve estar no formato do XML
408
     * @return string autorizacao of Pagamento
409
     */
410 12
    public function getAutorizacao($normalize = false)
411
    {
412 12
        if (!$normalize) {
413 11
            return $this->autorizacao;
414
        }
415 2
        return $this->autorizacao;
416
    }
417
418
    /**
419
     * Altera o valor da Autorizacao para o informado no parâmetro
420
     * @param mixed $autorizacao novo valor para Autorizacao
421
     * @param string $autorizacao Novo autorizacao para Pagamento
422
     * @return self A própria instância da classe
423
     */
424 41
    public function setAutorizacao($autorizacao)
425
    {
426 41
        $this->autorizacao = $autorizacao;
427 41
        return $this;
428
    }
429
430
    /**
431
     * Bandeira da operadora de cartão de crédito/débito:01–Visa;
432
     * 02–Mastercard; 03–American Express; 04–Sorocred;05-Diners
433
     * Club;06-Elo;07-Hipercard;08-Aura;09-Cabal;99–Outros
434
     * @param boolean $normalize informa se a bandeira deve estar no formato do XML
435
     * @return string bandeira of Pagamento
436
     */
437 38
    public function getBandeira($normalize = false)
438
    {
439 38
        if (!$normalize) {
440 38
            return $this->bandeira;
441
        }
442 36
        switch ($this->bandeira) {
443 36
            case self::BANDEIRA_VISA:
444 2
                return '01';
445 34
            case self::BANDEIRA_MASTERCARD:
446 34
                return '02';
447
            case self::BANDEIRA_AMEX:
448
                return '03';
449
            case self::BANDEIRA_SOROCRED:
450
                return '04';
451
            case self::BANDEIRA_DINERS:
452
                return '05';
453
            case self::BANDEIRA_ELO:
454
                return '06';
455
            case self::BANDEIRA_HIPERCARD:
456
                return '07';
457
            case self::BANDEIRA_AURA:
458
                return '08';
459
            case self::BANDEIRA_CABAL:
460
                return '09';
461
            case self::BANDEIRA_OUTROS:
462
                return '99';
463
        }
464
        return $this->bandeira;
465
    }
466
467
    /**
468
     * Altera o valor da Bandeira para o informado no parâmetro
469
     * @param mixed $bandeira novo valor para Bandeira
470
     * @param string $bandeira Novo bandeira para Pagamento
471
     * @return self A própria instância da classe
472
     */
473 41
    public function setBandeira($bandeira)
474
    {
475
        switch ($bandeira) {
476 41
            case '01':
477 1
                $bandeira = self::BANDEIRA_VISA;
478 1
                break;
479 41
            case '02':
480 29
                $bandeira = self::BANDEIRA_MASTERCARD;
481 29
                break;
482 41
            case '03':
483
                $bandeira = self::BANDEIRA_AMEX;
484
                break;
485 41
            case '04':
486
                $bandeira = self::BANDEIRA_SOROCRED;
487
                break;
488 41
            case '05':
489
                $bandeira = self::BANDEIRA_DINERS;
490
                break;
491 41
            case '06':
492
                $bandeira = self::BANDEIRA_ELO;
493
                break;
494 41
            case '07':
495
                $bandeira = self::BANDEIRA_HIPERCARD;
496
                break;
497 41
            case '08':
498
                $bandeira = self::BANDEIRA_AURA;
499
                break;
500 41
            case '09':
501
                $bandeira = self::BANDEIRA_CABAL;
502
                break;
503 41
            case '99':
504
                $bandeira = self::BANDEIRA_OUTROS;
505
                break;
506
        }
507 41
        $this->bandeira = $bandeira;
508 41
        return $this;
509
    }
510
511
    /**
512
     * Informa se o pagamento é em cartão
513
     */
514 38
    public function isCartao()
515
    {
516 38
        return in_array($this->getForma(), [self::FORMA_CREDITO, self::FORMA_DEBITO]);
517
    }
518
519 11
    public function toArray($recursive = false)
0 ignored issues
show
Unused Code introduced by
The parameter $recursive is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
520
    {
521 11
        $pagamento = [];
522 11
        $pagamento['indicador'] = $this->getIndicador();
523 11
        $pagamento['forma'] = $this->getForma();
524 11
        $pagamento['valor'] = $this->getValor();
525 11
        $pagamento['integrado'] = $this->getIntegrado();
526 11
        $pagamento['credenciadora'] = $this->getCredenciadora();
527 11
        $pagamento['autorizacao'] = $this->getAutorizacao();
528 11
        $pagamento['bandeira'] = $this->getBandeira();
529 11
        return $pagamento;
530
    }
531
532 41
    public function fromArray($pagamento = [])
533
    {
534 41
        if ($pagamento instanceof Pagamento) {
535 10
            $pagamento = $pagamento->toArray();
536 41
        } elseif (!is_array($pagamento)) {
537 10
            return $this;
538
        }
539 41
        if (isset($pagamento['indicador'])) {
540
            $this->setIndicador($pagamento['indicador']);
541
        } else {
542 41
            $this->setIndicador(null);
543
        }
544 41
        if (isset($pagamento['forma'])) {
545 10
            $this->setForma($pagamento['forma']);
546
        } else {
547 41
            $this->setForma(null);
548
        }
549 41
        if (isset($pagamento['valor'])) {
550 10
            $this->setValor($pagamento['valor']);
551
        } else {
552 41
            $this->setValor(null);
553
        }
554 41
        if (!isset($pagamento['integrado'])) {
555 41
            $this->setIntegrado('N');
556
        } else {
557 10
            $this->setIntegrado($pagamento['integrado']);
558
        }
559 41
        if (isset($pagamento['credenciadora'])) {
560 1
            $this->setCredenciadora($pagamento['credenciadora']);
561
        } else {
562 41
            $this->setCredenciadora(null);
563
        }
564 41
        if (isset($pagamento['autorizacao'])) {
565 1
            $this->setAutorizacao($pagamento['autorizacao']);
566
        } else {
567 41
            $this->setAutorizacao(null);
568
        }
569 41
        if (isset($pagamento['bandeira'])) {
570 8
            $this->setBandeira($pagamento['bandeira']);
571
        } else {
572 41
            $this->setBandeira(null);
573
        }
574 41
        return $this;
575
    }
576
577 40
    public function getNode($name = null)
578
    {
579 40
        $dom = new \DOMDocument('1.0', 'UTF-8');
580 40
        if ($this->getValor() < 0) {
581 4
            $element = $dom->createElement(is_null($name) ? 'vTroco' : $name);
582 4
            $this->setValor(-$this->getValor());
583 4
            $element->appendChild($dom->createTextNode($this->getValor(true)));
584 4
            $this->setValor(-$this->getValor());
585 4
            return $element;
586
        }
587 38
        $element = $dom->createElement(is_null($name) ? 'detPag' : $name);
588 38
        if (!is_null($this->getIndicador())) {
589
            Util::appendNode($element, 'indPag', $this->getIndicador(true));
590
        }
591 38
        Util::appendNode($element, 'tPag', $this->getForma(true));
592 38
        Util::appendNode($element, 'vPag', $this->getValor(true));
593 38
        if (!$this->isCartao()) {
594 34
            return $element;
595
        }
596 36
        $cartao = $dom->createElement('card');
597 36
        Util::appendNode($cartao, 'tpIntegra', $this->getIntegrado(true));
598 36
        if ($this->isIntegrado()) {
599 2
            Util::appendNode($cartao, 'CNPJ', $this->getCredenciadora(true));
600
        }
601 36
        if (!is_null($this->getBandeira())) {
602 36
            Util::appendNode($cartao, 'tBand', $this->getBandeira(true));
603
        }
604 36
        if ($this->isIntegrado()) {
605 2
            Util::appendNode($cartao, 'cAut', $this->getAutorizacao(true));
606
        }
607 36
        $element->appendChild($cartao);
608 36
        return $element;
609
    }
610
611 32
    public function loadNode($element, $name = null)
612
    {
613 32
        $name = is_null($name) ? 'detPag' : $name;
614 32
        if ($name == 'vTroco') {
615 3
            $this->setValor(
616 3
                '-' . Util::loadNode(
617 3
                    $element,
618 3
                    'vTroco',
619 3
                    'Tag "vTroco" do campo "Valor" não encontrada'
620
                )
621
            );
622 3
            return $element;
623
        }
624 31
        if ($element->nodeName != $name) {
625
            $_fields = $element->getElementsByTagName($name);
626
            if ($_fields->length == 0) {
627
                throw new \Exception('Tag "' . $name . '" não encontrada', 404);
628
            }
629
            $element = $_fields->item(0);
630
        }
631 31
        $this->setIndicador(
632 31
            Util::loadNode(
633 31
                $element,
634 31
                'indPag'
635
            )
636
        );
637 31
        $this->setForma(
638 31
            Util::loadNode(
639 31
                $element,
640 31
                'tPag',
641 31
                'Tag "tPag" do campo "Forma" não encontrada'
642
            )
643
        );
644 31
        $this->setValor(
645 31
            Util::loadNode(
646 31
                $element,
647 31
                'vPag',
648 31
                'Tag "vPag" do campo "Valor" não encontrada'
649
            )
650
        );
651 31
        $integrado = Util::loadNode($element, 'tpIntegra');
652 31
        if (is_null($integrado) && $this->isCartao()) {
653
            throw new \Exception('Tag "tpIntegra" do campo "Integrado" não encontrada', 404);
654
        }
655 31
        $this->setIntegrado($integrado);
656 31
        $this->setCredenciadora(Util::loadNode($element, 'CNPJ'));
657 31
        $autorizacao = Util::loadNode($element, 'cAut');
658 31
        if (is_null($autorizacao) && $this->isCartao() && is_numeric($this->getCredenciadora())) {
659
            throw new \Exception('Tag "cAut" do campo "Autorizacao" não encontrada', 404);
660
        }
661 31
        $this->setAutorizacao($autorizacao);
662 31
        $bandeira = Util::loadNode($element, 'tBand');
663 31
        if (is_null($bandeira) && $this->isCartao() && is_numeric($this->getCredenciadora())) {
664
            throw new \Exception('Tag "tBand" do campo "Bandeira" não encontrada', 404);
665
        }
666 31
        $this->setBandeira($bandeira);
667 31
        return $element;
668
    }
669
}
670