Passed
Push — feature/eco-3047/eco-3049-invo... ( f43a85...77480f )
by Aleksey
06:55
created

HeidelpayClient::processNotification()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
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\Client\Heidelpay;
9
10
use Generated\Shared\Transfer\HeidelpayCreditCardPaymentOptionsTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...dPaymentOptionsTransfer 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 Generated\Shared\Transfer\HeidelpayCreditCardRegistrationTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...ardRegistrationTransfer 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 Generated\Shared\Transfer\HeidelpayExternalPaymentRequestTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...lPaymentRequestTransfer 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 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...
14
use Generated\Shared\Transfer\HeidelpayPaymentProcessingResponseTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...cessingResponseTransfer 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...
15
use Generated\Shared\Transfer\HeidelpayRegistrationByIdAndQuoteRequestTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...AndQuoteRequestTransfer 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...
16
use Generated\Shared\Transfer\HeidelpayRegistrationRequestTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...strationRequestTransfer 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...
17
use Generated\Shared\Transfer\HeidelpayRegistrationSaveResponseTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...ionSaveResponseTransfer 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...
18
use Generated\Shared\Transfer\HeidelpayResponseTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...idelpayResponseTransfer 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...
19
use Generated\Shared\Transfer\HeidelpayTransactionLogTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...yTransactionLogTransfer 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...
20
use Generated\Shared\Transfer\QuoteTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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...
21
use Spryker\Client\Kernel\AbstractClient;
22
23
/**
24
 * @method \SprykerEco\Client\Heidelpay\HeidelpayFactory getFactory()
25
 */
26
class HeidelpayClient extends AbstractClient implements HeidelpayClientInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * @api
32
     *
33
     * @param string $errorCode
34
     *
35
     * @return string
36
     */
37
    public function translateErrorMessageByCode(string $errorCode): string
38
    {
39
        $currentLocale = $this->getCurrentLocale();
40
41
        return $this->getFactory()
42
            ->createHeidelpayApiAdapter()
43
            ->getTranslatedMessageByCode($errorCode, $currentLocale);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     *
49
     * @api
50
     *
51
     * @param string $orderReference
52
     *
53
     * @return \Generated\Shared\Transfer\HeidelpayTransactionLogTransfer
54
     */
55
    public function getAuthorizeTransactionLogForOrder(string $orderReference): HeidelpayTransactionLogTransfer
56
    {
57
        return $this->getFactory()
58
            ->createZedStub()
59
            ->getAuthorizeTransactionLogByOrderReference($orderReference);
60
    }
61
62
    /**
63
     * @deprecated Use `getQuote()` instead.
64
     *
65
     * {@inheritdoc}
66
     *
67
     * @api
68
     *
69
     * @return \Generated\Shared\Transfer\QuoteTransfer
70
     */
71
    public function getQuoteFromSession(): QuoteTransfer
72
    {
73
        return $this->getFactory()
74
            ->getQuoteClient()
75
            ->getQuote();
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     *
81
     * @api
82
     *
83
     * @return \Generated\Shared\Transfer\QuoteTransfer
84
     */
85
    public function getQuote(): QuoteTransfer
86
    {
87
        return $this->getFactory()
88
            ->getQuoteClient()
89
            ->getQuote();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     *
95
     * @api
96
     *
97
     * @param array $externalResponse
98
     *
99
     * @return \Generated\Shared\Transfer\HeidelpayRegistrationRequestTransfer
100
     */
101
    public function parseExternalResponse(array $externalResponse): HeidelpayRegistrationRequestTransfer
102
    {
103
        return $this->getFactory()
104
            ->createExternalResponseValidator()
105
            ->parseExternalResponse($externalResponse);
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     *
111
     * @api
112
     *
113
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
114
     *
115
     * @return \Generated\Shared\Transfer\HeidelpayResponseTransfer
116
     */
117
    public function sendHeidelpayEasycreditInitializeRequest(QuoteTransfer $quoteTransfer): HeidelpayResponseTransfer
118
    {
119
        return $this->getFactory()
120
            ->createZedStub()
121
            ->sendEasycreditInitializeRequest($quoteTransfer);
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     *
127
     * @api
128
     *
129
     * @param array $externalResponse
130
     *
131
     * @return \Generated\Shared\Transfer\HeidelpayPaymentProcessingResponseTransfer
132
     */
133
    public function processExternalPaymentResponse(array $externalResponse): HeidelpayPaymentProcessingResponseTransfer
134
    {
135
        $externalResponseTransfer = $this->buildTransferFromExternalResponseArray($externalResponse);
136
137
        return $this->getFactory()
138
            ->createZedStub()
139
            ->processExternalPaymentResponse($externalResponseTransfer);
140
    }
141
142
    /**
143
     * {@inheritdoc}
144
     *
145
     * @api
146
     *
147
     * @param array $externalResponse
148
     *
149
     * @return \Generated\Shared\Transfer\HeidelpayPaymentProcessingResponseTransfer
150
     */
151
    public function processExternalEasyCreditPaymentResponse(
152
        array $externalResponse
153
    ): HeidelpayPaymentProcessingResponseTransfer {
154
        $externalResponseTransfer = $this->buildTransferFromExternalResponseArray($externalResponse);
155
156
        return $this->getFactory()
157
            ->createZedStub()
158
            ->processExternalEasyCreditPaymentResponse($externalResponseTransfer);
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     *
164
     * @api
165
     *
166
     * @param \Generated\Shared\Transfer\HeidelpayRegistrationRequestTransfer $registrationRequestTransfer
167
     *
168
     * @return \Generated\Shared\Transfer\HeidelpayRegistrationSaveResponseTransfer
169
     */
170
    public function saveCreditCardRegistration(
171
        HeidelpayRegistrationRequestTransfer $registrationRequestTransfer
172
    ): HeidelpayRegistrationSaveResponseTransfer {
173
        return $this->getFactory()
174
            ->createZedStub()
175
            ->saveCreditCardRegistration($registrationRequestTransfer);
176
    }
177
178
    /**
179
     * {@inheritdoc}
180
     *
181
     * @api
182
     *
183
     * @param int $idRegistration
184
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
185
     *
186
     * @return \Generated\Shared\Transfer\HeidelpayCreditCardRegistrationTransfer|null
187
     */
188
    public function findRegistrationByIdAndQuote(
189
        int $idRegistration,
190
        QuoteTransfer $quoteTransfer
191
    ): ?HeidelpayCreditCardRegistrationTransfer {
192
        $findRegistrationRequestTransfer = $this->buildFindRegistrationRequestTransfer($idRegistration, $quoteTransfer);
193
194
        return $this->getFactory()
195
            ->createZedStub()
196
            ->findCreditCardRegistrationByIdAndQuote($findRegistrationRequestTransfer);
197
    }
198
199
    /**
200
     * {@inheritdoc}
201
     *
202
     * @api
203
     *
204
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
205
     *
206
     * @return \Generated\Shared\Transfer\HeidelpayCreditCardPaymentOptionsTransfer
207
     */
208
    public function getCreditCardPaymentOptions(QuoteTransfer $quoteTransfer): HeidelpayCreditCardPaymentOptionsTransfer
209
    {
210
        return $this->getFactory()
211
            ->createZedStub()
212
            ->getCreditCardPaymentOptions($quoteTransfer);
213
    }
214
215
    /**
216
     * Specification:
217
     *  - Saves notification.
218
     *  - Updates order items status depends on notification processing result.
219
     *
220
     * @api
221
     *
222
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $notificationTransfer
223
     *
224
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer
225
     */
226
    public function processNotification(HeidelpayNotificationTransfer $notificationTransfer): HeidelpayNotificationTransfer
227
    {
228
        return $this->getFactory()
229
            ->createZedStub()
230
            ->processNotification($notificationTransfer);
231
    }
232
233
    /**
234
     * {@inheritdoc}
235
     *
236
     * @api
237
     *
238
     * @param array $responseArray
239
     *
240
     * @return array
241
     */
242
    public function filterResponseParameters(array $responseArray): array
243
    {
244
        return array_filter($responseArray, function ($key) {
245
            return !preg_match('/^paymentForm+|^lang+/', $key);
246
        }, ARRAY_FILTER_USE_KEY);
247
    }
248
249
    /**
250
     * @return string
251
     */
252
    protected function getCurrentLocale(): string
253
    {
254
        return $this->getFactory()
255
            ->getLocaleClient()
256
            ->getCurrentLocale();
257
    }
258
259
    /**
260
     * @param array $externalResponse
261
     *
262
     * @return \Generated\Shared\Transfer\HeidelpayExternalPaymentRequestTransfer
263
     */
264
    protected function buildTransferFromExternalResponseArray(
265
        array $externalResponse
266
    ): HeidelpayExternalPaymentRequestTransfer {
267
        return (new HeidelpayExternalPaymentRequestTransfer())
268
            ->setBody($externalResponse);
269
    }
270
271
    /**
272
     * @param int $idRegistration
273
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
274
     *
275
     * @return \Generated\Shared\Transfer\HeidelpayRegistrationByIdAndQuoteRequestTransfer
276
     */
277
    protected function buildFindRegistrationRequestTransfer(
278
        int $idRegistration,
279
        QuoteTransfer $quoteTransfer
280
    ): HeidelpayRegistrationByIdAndQuoteRequestTransfer {
281
        return (new HeidelpayRegistrationByIdAndQuoteRequestTransfer())
282
            ->setIdRegistration($idRegistration)
283
            ->setQuote($quoteTransfer);
284
    }
285
}
286