Head::buildData()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 41
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 25
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 41
rs 9.52
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Ratepay\Business\Api\Builder;
9
10
use SprykerEco\Zed\Ratepay\Business\Api\Constants;
11
12
class Head extends AbstractBuilder implements HeadInterface
13
{
14
    public const ROOT_TAG = 'head';
15
16
    /**
17
     * @return array
18
     */
19
    public function buildData()
20
    {
21
        $return = [
22
            'system-id' => $this->requestTransfer->getHead()->getSystemId(),
23
            'transaction-id' => $this->requestTransfer->getHead()->getTransactionId(),
24
            'transaction-short-id' => $this->requestTransfer->getHead()->getTransactionShortId(),
25
            'credential' => [
26
                'profile-id' => $this->requestTransfer->getHead()->getProfileId(),
27
                'securitycode' => $this->requestTransfer->getHead()->getSecurityCode(),
28
            ],
29
            'customer-device' => [
30
                'device-token' => $this->requestTransfer->getHead()->getDeviceFingerprint(),
31
            ],
32
            'external' => [
33
                'merchant-consumer-id' => $this->requestTransfer->getHead()->getCustomerId(),
34
            ],
35
            'meta' => [
36
                'systems' => [
37
                    'system' => [
38
                        '@name' => Constants::CLIENT_NAME,
39
                        '@version' => Constants::CLIENT_VERSION,
40
                    ],
41
                ],
42
            ],
43
            'operation' => $this->requestTransfer->getHead()->getOperation(),
44
        ];
45
46
        if ($this->requestTransfer->getHead()->getOperationSubstring() !== null) {
47
            $return['operation'] = [
48
                '@subtype' => $this->requestTransfer->getHead()->getOperationSubstring(),
49
                '#' => $this->requestTransfer->getHead()->getOperation(),
50
            ];
51
        }
52
53
        if ($this->requestTransfer->getHead()->getExternalOrderId() !== null) {
54
            $return['external'] = [
55
                'order-id' => $this->requestTransfer->getHead()->getExternalOrderId(),
56
            ];
57
        }
58
59
        return $return;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getRootTag()
66
    {
67
        return static::ROOT_TAG;
68
    }
69
70
    /**
71
     * @param string $operation
72
     *
73
     * @return void
74
     */
75
    public function setOperation($operation)
76
    {
77
        $this->requestTransfer->getHead()->setOperation($operation);
78
    }
79
80
    /**
81
     * @param string $subOperation
82
     *
83
     * @return void
84
     */
85
    public function setOperationSubstring($subOperation)
86
    {
87
        $this->requestTransfer->getHead()->setOperationSubstring($subOperation);
88
    }
89
}
90