VaultDataBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 26 4
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\Gateway\Request;
10
11
use InvalidArgumentException;
12
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
13
use Magento\Payment\Gateway\Request\BuilderInterface;
14
use Magento\Payment\Model\InfoInterface;
15
use Magento\Vault\Model\Ui\VaultConfigProvider;
16
17
class VaultDataBuilder implements BuilderInterface
18
{
19
    /**
20
     * Credit - Block name.
21
     */
22
    public const CREDIT = 'credit';
23
24
    /**
25
     * Save Card Data - Block name.
26
     */
27
    public const SAVE_CARD_DATA = 'save_card_data';
28
29
    /**
30
     * The option that determines whether the payment method associated with
31
     * the successful transaction should be stored in the Vault.
32
     */
33
    public const STORE_IN_VAULT_ON_SUCCESS = 'true';
34
35
    /**
36
     * Build.
37
     *
38
     * @param array $buildSubject
39
     */
40
    public function build(array $buildSubject): array
41
    {
42
        if (!isset($buildSubject['payment'])
43
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
44
        ) {
45
            throw new InvalidArgumentException('Payment data object should be provided');
46
        }
47
48
        $result = [];
49
50
        $save = false;
51
52
        $paymentDO = $buildSubject['payment'];
53
54
        /** @var InfoInterface $payment * */
55
        $payment = $paymentDO->getPayment();
56
57
        if (!empty($payment->getAdditionalInformation(VaultConfigProvider::IS_ACTIVE_CODE))) {
58
            $save = self::STORE_IN_VAULT_ON_SUCCESS;
59
        }
60
61
        $result[self::CREDIT] = [
62
            self::SAVE_CARD_DATA => $save,
63
        ];
64
65
        return $result;
66
    }
67
}
68