Passed
Pull Request — feature/eco-3047/dev (#35)
by Aleksey
09:26 queued 04:02
created

NotificationExpander::addTransactionData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\Heidelpay\Business\Processor\Notification\Expander;
9
10
use Generated\Shared\Transfer\HeidelpayNotificationTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...payNotificationTransfer 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...
11
use SprykerEco\Zed\Heidelpay\Business\Processor\Notification\Converter\NotificationXmlConverterInterface;
12
use SprykerEco\Zed\Heidelpay\Dependency\Service\HeidelpayToUtilEncodingServiceInterface;
13
14
class NotificationExpander implements NotificationExpanderInterface
15
{
16
    protected const KEY_ATTRIBUTES = '@attributes';
17
    protected const KEY_IDENTIFICATION = 'Identification';
18
    protected const KEY_PROCESSING = 'Processing';
19
    protected const KEY_PAYMENT = 'Payment';
20
    protected const KEY_CLEARING = 'Clearing';
21
    protected const KEY_ACCOUNT = 'Account';
22
    protected const KEY_CUSTOMER = 'Customer';
23
    protected const KEY_TRANSACTION_SOURCE = 'source';
24
    protected const KEY_CHANNEL = 'channel';
25
    protected const KEY_RESPONSE = 'response';
26
    protected const KEY_MODE = 'mode';
27
    protected const KEY_TRANSACTION_ID = 'TransactionID';
28
    protected const KEY_UNIQUE_ID = 'UniqueID';
29
    protected const KEY_SHORT_ID = 'ShortID';
30
    protected const KEY_IDENTIFICATION_SOURCE = 'Source';
31
    protected const KEY_CODE = 'code';
32
    protected const KEY_TIMESTAMP = 'Timestamp';
33
    protected const KEY_RESULT = 'Result';
34
    protected const KEY_STATUS = 'Status';
35
    protected const KEY_REASON = 'Reason';
36
    protected const KEY_RETURN = 'Return';
37
    protected const KEY_AMOUNT = 'Amount';
38
    protected const KEY_CURRENCY = 'Currency';
39
    protected const KEY_DESCRIPTOR = 'Descriptor';
40
41
    /**
42
     * @var \SprykerEco\Zed\Heidelpay\Business\Processor\Notification\Converter\NotificationXmlConverterInterface
43
     */
44
    protected $xmlConverter;
45
46
    /**
47
     * @var \SprykerEco\Zed\Heidelpay\Dependency\Service\HeidelpayToUtilEncodingServiceInterface
48
     */
49
    protected $utilEncodingService;
50
51
    /**
52
     * @var \SprykerEco\Zed\Heidelpay\Dependency\Plugin\HeidelpayNotificationExpanderPluginInterface[]
53
     */
54
    protected $notificationExpanderPlugins;
55
56
    /**
57
     * @param \SprykerEco\Zed\Heidelpay\Business\Processor\Notification\Converter\NotificationXmlConverterInterface $xmlConverter
58
     * @param \SprykerEco\Zed\Heidelpay\Dependency\Service\HeidelpayToUtilEncodingServiceInterface $utilEncodingService
59
     * @param \SprykerEco\Zed\Heidelpay\Dependency\Plugin\HeidelpayNotificationExpanderPluginInterface[] $notificationExpanderPlugins
60
     */
61
    public function __construct(
62
        NotificationXmlConverterInterface $xmlConverter,
63
        HeidelpayToUtilEncodingServiceInterface $utilEncodingService,
64
        array $notificationExpanderPlugins = []
65
    ) {
66
        $this->xmlConverter = $xmlConverter;
67
        $this->utilEncodingService = $utilEncodingService;
68
        $this->notificationExpanderPlugins = $notificationExpanderPlugins;
69
    }
70
71
    /**
72
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
73
     *
74
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
75
     */
76
    public function expandWithNotificationData(HeidelpayNotificationTransfer $notificationTransfer): HeidelpayNotificationTransfer
77
    {
78
        $notificationData = $this->xmlConverter->convert($notificationTransfer->getNotificationBody());
79
80
        $notificationTransfer = $this->addTransactionData($notificationTransfer, $notificationData[static::KEY_ATTRIBUTES]);
81
        $notificationTransfer = $this->addIdentificationData($notificationTransfer, $notificationData[static::KEY_IDENTIFICATION]);
82
        $notificationTransfer = $this->addProcessingData($notificationTransfer, $notificationData[static::KEY_PROCESSING]);
83
        $notificationTransfer = $this->addPaymentData($notificationTransfer, $notificationData[static::KEY_PAYMENT]);
84
        $notificationTransfer = $this->addAccountData($notificationTransfer, $notificationData[static::KEY_ACCOUNT]);
85
        $notificationTransfer = $this->addCustomerData($notificationTransfer, $notificationData[static::KEY_CUSTOMER]);
86
87
        $notificationTransfer = $this->executeExpanderPlugins($notificationTransfer, $notificationData);
88
89
        return $notificationTransfer;
90
    }
91
92
    /**
93
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
94
     * @param array $transactionData
95
     *
96
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
97
     */
98
    protected function addTransactionData(
99
        HeidelpayNotificationTransfer $notificationTransfer,
100
        array $transactionData
101
    ): HeidelpayNotificationTransfer {
102
        $notificationTransfer->setTransactionSource($transactionData[static::KEY_TRANSACTION_SOURCE]);
103
        $notificationTransfer->setTransactionChannel($transactionData[static::KEY_CHANNEL]);
104
        $notificationTransfer->setTransactionResponseType($transactionData[static::KEY_RESPONSE]);
105
        $notificationTransfer->setTransactionMode($transactionData[static::KEY_MODE]);
106
107
        return $notificationTransfer;
108
    }
109
110
    /**
111
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
112
     * @param array $identificationData
113
     *
114
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
115
     */
116
    protected function addIdentificationData(
117
        HeidelpayNotificationTransfer $notificationTransfer,
118
        array $identificationData
119
    ): HeidelpayNotificationTransfer {
120
        $notificationTransfer->setTransactionId($identificationData[static::KEY_TRANSACTION_ID]);
121
        $notificationTransfer->setUniqueId($identificationData[static::KEY_UNIQUE_ID]);
122
        $notificationTransfer->setShortId($identificationData[static::KEY_SHORT_ID]);
123
        $notificationTransfer->setIdentificationSource($identificationData[static::KEY_IDENTIFICATION_SOURCE]);
124
125
        return $notificationTransfer;
126
    }
127
128
    /**
129
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
130
     * @param array $processingData
131
     *
132
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
133
     */
134
    protected function addProcessingData(
135
        HeidelpayNotificationTransfer $notificationTransfer,
136
        array $processingData
137
    ): HeidelpayNotificationTransfer {
138
        $notificationTransfer->setResultCode($processingData[static::KEY_ATTRIBUTES][static::KEY_CODE]);
139
        $notificationTransfer->setResultTimestamp($processingData[static::KEY_TIMESTAMP]);
140
        $notificationTransfer->setResult($processingData[static::KEY_RESULT]);
141
        $notificationTransfer->setResultStatus($processingData[static::KEY_STATUS]);
142
        $notificationTransfer->setResultReason($processingData[static::KEY_REASON]);
143
        $notificationTransfer->setResultReturn($processingData[static::KEY_RETURN]);
144
145
        return $notificationTransfer;
146
    }
147
148
    /**
149
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
150
     * @param array $paymentData
151
     *
152
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
153
     */
154
    protected function addPaymentData(
155
        HeidelpayNotificationTransfer $notificationTransfer,
156
        array $paymentData
157
    ): HeidelpayNotificationTransfer {
158
        $notificationTransfer->setPaymentCode($paymentData[static::KEY_ATTRIBUTES][static::KEY_CODE]);
159
        $notificationTransfer->setAmount($paymentData[static::KEY_CLEARING][static::KEY_AMOUNT]);
160
        $notificationTransfer->setCurrency($paymentData[static::KEY_CLEARING][static::KEY_CURRENCY]);
161
        $notificationTransfer->setPaymentDescriptor($paymentData[static::KEY_CLEARING][static::KEY_DESCRIPTOR]);
162
163
        return $notificationTransfer;
164
    }
165
166
    /**
167
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
168
     * @param array $accountData
169
     *
170
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
171
     */
172
    protected function addAccountData(
173
        HeidelpayNotificationTransfer $notificationTransfer,
174
        array $accountData
175
    ): HeidelpayNotificationTransfer {
176
        $notificationTransfer->setAccount(
177
            $this->utilEncodingService->encodeJson($accountData)
178
        );
179
180
        return $notificationTransfer;
181
    }
182
183
    /**
184
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
185
     * @param array $customerData
186
     *
187
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
188
     */
189
    protected function addCustomerData(
190
        HeidelpayNotificationTransfer $notificationTransfer,
191
        array $customerData
192
    ): HeidelpayNotificationTransfer {
193
        $notificationTransfer->setCustomer(
194
            $this->utilEncodingService->encodeJson($customerData)
195
        );
196
197
        return $notificationTransfer;
198
    }
199
200
    /**
201
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
202
     * @param string[][] $notificationData
203
     *
204
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
205
     */
206
    protected function executeExpanderPlugins(
207
        HeidelpayNotificationTransfer $notificationTransfer,
208
        array $notificationData
209
    ): HeidelpayNotificationTransfer {
210
        foreach ($this->notificationExpanderPlugins as $notificationExpanderPlugin) {
211
            $notificationTransfer = $notificationExpanderPlugin->expand($notificationTransfer, $notificationData);
212
        }
213
214
        return $notificationTransfer;
215
    }
216
}
217