Passed
Branch [email protected] (aae97d)
by Bruno
10:40
created

DataAssignObserverWallet   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
c 2
b 0
f 0
dl 0
loc 51
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 Data Assign Observer Wallet - Capture wallet payment information.
17
 */
18
class DataAssignObserverWallet extends AbstractDataAssignObserver
19
{
20
    /**
21
     * @const string
22
     */
23
    public const PAYMENT_INFO_WALLET_CARD_TYPE = 'wallet_card_type';
24
25
    /**
26
     * @const string
27
     */
28
    public const PAYMENT_INFO_WALLET_INSTALLMENTS = 'cc_installments';
29
30
    /**
31
     * @const string
32
     */
33
    public const PAYMENT_INFO_WALLET_PAYER_PHONE = 'wallet_payer_phone';
34
35
    /**
36
     * @var array
37
     */
38
    protected $addInformationList = [
39
        self::PAYMENT_INFO_WALLET_CARD_TYPE,
40
        self::PAYMENT_INFO_WALLET_INSTALLMENTS,
41
        self::PAYMENT_INFO_WALLET_PAYER_PHONE,
42
    ];
43
44
    /**
45
     * Execute.
46
     *
47
     * @param Observer $observer
48
     *
49
     * @return void
50
     */
51
    public function execute(Observer $observer)
52
    {
53
        $data = $this->readDataArgument($observer);
54
55
        $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
56
57
        if (!is_array($additionalData)) {
58
            return;
59
        }
60
61
        $paymentInfo = $this->readPaymentModelArgument($observer);
62
63
        foreach ($this->addInformationList as $addInformationKey) {
64
            if (isset($additionalData[$addInformationKey])) {
65
                if ($additionalData[$addInformationKey]) {
66
                    $paymentInfo->setAdditionalInformation(
67
                        $addInformationKey,
68
                        $additionalData[$addInformationKey]
69
                    );
70
                }
71
            }
72
        }
73
    }
74
}
75