DataAssignBoletoObserver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 5
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
namespace Getnet\PaymentMagento\Observer;
10
11
use Magento\Framework\Event\Observer;
12
use Magento\Payment\Observer\AbstractDataAssignObserver;
13
use Magento\Quote\Api\Data\PaymentInterface;
14
15
/**
16
 * Class DataAssignBoletoObserver - Captures payment information by boleto.
17
 */
18
class DataAssignBoletoObserver extends AbstractDataAssignObserver
19
{
20
    /**
21
     * @const string
22
     */
23
    public const PAYER_FULLNAME = 'boleto_payer_fullname';
24
25
    /**
26
     * @const string
27
     */
28
    public const PAYER_TAX_DOCUMENT = 'boleto_payer_tax_document';
29
30
    /**
31
     * @var array
32
     */
33
    protected $addInformationList = [
34
        self::PAYER_FULLNAME,
35
        self::PAYER_TAX_DOCUMENT,
36
    ];
37
38
    /**
39
     * Execute.
40
     *
41
     * @param Observer $observer
42
     *
43
     * @return void
44
     */
45
    public function execute(Observer $observer)
46
    {
47
        $data = $this->readDataArgument($observer);
48
49
        $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
50
51
        if (!is_array($additionalData)) {
52
            return;
53
        }
54
55
        $paymentInfo = $this->readPaymentModelArgument($observer);
56
57
        foreach ($this->addInformationList as $addInformationKey) {
58
            if (isset($additionalData[$addInformationKey])) {
59
                if ($additionalData[$addInformationKey]) {
60
                    $paymentInfo->setAdditionalInformation(
61
                        $addInformationKey,
62
                        $additionalData[$addInformationKey]
63
                    );
64
                }
65
            }
66
        }
67
    }
68
}
69