Completed
Push — feature/eco-1539-heidelpay-eas... ( 47d643...8d0432 )
by Ruslan
27s queued 21s
created

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