Passed
Push[email protected] ( 164fc1...e52068 )
by Bruno
01:55
created

DataAssignObserverCcVault::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * Copyright © Wirecard Brasil. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See COPYING.txt for license details.
7
 */
8
9
namespace Moip\Magento2\Observer;
10
11
use Magento\Framework\Event\Observer;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Event\Observer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Magento\Payment\Observer\AbstractDataAssignObserver;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Observer...tractDataAssignObserver was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Magento\Quote\Api\Data\PaymentInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Api\Data\PaymentInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Moip\Magento2\Gateway\Config\Config;
15
16
/**
17
 * Class DataAssignObserverCc - Capture credit card payment information.
18
 */
19
class DataAssignObserverCcVault extends AbstractDataAssignObserver
20
{
21
    /**
22
     * @const Method Name Block
23
     */
24
    const METHOD_NAME = 'method_name';
25
26
    /**
27
     * @const Method Name
28
     */
29
    const METHOD_NAME_TYPE = 'Cartão de Crédito - Cofre';
30
31
    /**
32
     * @const Credit Card - CVV
33
     */
34
    const PAYER_CC_CVV = 'cc_cvv';
35
36
    /**
37
     * @const Installment
38
     */
39
    const PAYER_CC_INSTALLMENTS = 'cc_installments';
40
41
    /**
42
     * @var array
43
     */
44
    protected $addInformationList = [
45
        self::PAYER_CC_CVV,
46
        self::PAYER_CC_INSTALLMENTS,
47
    ];
48
49
    /**
50
     * @var
51
     */
52
    protected $config;
53
54
    /**
55
     * @param Config $config
56
     */
57
    public function __construct(
58
        Config $config
59
    ) {
60
        $this->config = $config;
61
    }
62
63
    /**
64
     * @param Observer $observer
65
     */
66
    public function execute(Observer $observer)
67
    {
68
        $data = $this->readDataArgument($observer);
69
70
        $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
71
72
        if (!is_array($additionalData)) {
73
            return;
74
        }
75
76
        $paymentInfo = $this->readPaymentModelArgument($observer);
77
78
        $paymentInfo->setAdditionalInformation(
79
            self::METHOD_NAME,
80
            self::METHOD_NAME_TYPE
81
        );
82
83
        foreach ($this->addInformationList as $addInformationKey) {
84
            if (isset($additionalData[$addInformationKey])) {
85
                if ($additionalData[$addInformationKey]) {
86
                    $paymentInfo->setAdditionalInformation(
87
                        $addInformationKey,
88
                        $additionalData[$addInformationKey]
89
                    );
90
                }
91
            }
92
        }
93
    }
94
}
95