Passed
Pull Request — master (#57)
by Anton
07:51
created

createOrderPriceDistributor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\Payone\Business;
9
10
use Generated\Shared\Transfer\PayoneTransactionStatusUpdateTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ionStatusUpdateTransfer 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 Spryker\Shared\Kernel\Store;
12
use Spryker\Zed\Kernel\Business\AbstractBusinessFactory;
13
use SprykerEco\Shared\Payone\PayoneApiConstants;
14
use SprykerEco\Zed\Payone\Business\Api\Adapter\Http\Guzzle;
15
use SprykerEco\Zed\Payone\Business\Api\Log\ApiCallLogWriter;
16
use SprykerEco\Zed\Payone\Business\Api\TransactionStatus\TransactionStatusRequest;
17
use SprykerEco\Zed\Payone\Business\ApiLog\ApiLogFinder;
18
use SprykerEco\Zed\Payone\Business\Distributor\OrderPriceDistributor;
19
use SprykerEco\Zed\Payone\Business\Distributor\OrderPriceDistributorInterface;
20
use SprykerEco\Zed\Payone\Business\Key\HashGenerator;
21
use SprykerEco\Zed\Payone\Business\Key\HashProvider;
22
use SprykerEco\Zed\Payone\Business\Key\UrlHmacGenerator;
23
use SprykerEco\Zed\Payone\Business\Mode\ModeDetector;
24
use SprykerEco\Zed\Payone\Business\Order\OrderManager;
25
use SprykerEco\Zed\Payone\Business\Order\OrderManagerInterface;
26
use SprykerEco\Zed\Payone\Business\Order\PayoneOrderItemStatusFinder;
27
use SprykerEco\Zed\Payone\Business\Order\PayoneOrderItemStatusFinderInterface;
28
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CashOnDelivery;
29
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CreditCardPseudo;
30
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit;
31
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\EWallet;
32
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\GenericPayment;
33
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice;
34
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\OnlineBankTransfer;
35
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Prepayment;
36
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\SecurityInvoice;
37
use SprykerEco\Zed\Payone\Business\Payment\PaymentManager;
38
use SprykerEco\Zed\Payone\Business\Payment\PaymentManagerInterface;
39
use SprykerEco\Zed\Payone\Business\Payment\PaymentMethodFilter;
40
use SprykerEco\Zed\Payone\Business\Payment\PaymentMethodFilterInterface;
41
use SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface;
42
use SprykerEco\Zed\Payone\Business\RiskManager\Factory\RiskCheckFactory;
43
use SprykerEco\Zed\Payone\Business\RiskManager\Factory\RiskCheckFactoryInterface;
44
use SprykerEco\Zed\Payone\Business\RiskManager\Mapper\RiskCheckMapper;
45
use SprykerEco\Zed\Payone\Business\RiskManager\Mapper\RiskCheckMapperInterface;
46
use SprykerEco\Zed\Payone\Business\RiskManager\RiskCheckManager;
47
use SprykerEco\Zed\Payone\Business\RiskManager\RiskCheckManagerInterface;
48
use SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProvider;
49
use SprykerEco\Zed\Payone\Business\TransactionStatus\TransactionStatusUpdateManager;
50
use SprykerEco\Zed\Payone\Dependency\Facade\PayoneToGlossaryFacadeInterface;
51
use SprykerEco\Zed\Payone\PayoneDependencyProvider;
52
53
/**
54
 * @method \SprykerEco\Zed\Payone\PayoneConfig getConfig()
55
 * @method \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface getQueryContainer()
56
 * @method \SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface getRepository()
57
 * @method \SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface getEntityManager()
58
 */
59
class PayoneBusinessFactory extends AbstractBusinessFactory
60
{
61
    /**
62
     * @var \Generated\Shared\Transfer\PayoneStandardParameterTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...andardParameterTransfer 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...
63
     */
64
    private $standardParameter;
65
66
    /**
67
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentManagerInterface
68
     */
69
    public function createPaymentManager(): PaymentManagerInterface
70
    {
71
        $paymentManager = new PaymentManager(
72
            $this->createExecutionAdapter(),
73
            $this->getQueryContainer(),
74
            $this->getStandardParameter(),
75
            $this->createKeyHashGenerator(),
76
            $this->createSequenceNumberProvider(),
77
            $this->createModeDetector(),
78
            $this->createUrlHmacGenerator(),
79
            $this->getRepository(),
80
            $this->getEntityManager(),
81
            $this->createOrderPriceDistributor()
82
        );
83
84
        foreach ($this->getAvailablePaymentMethods() as $paymentMethod) {
85
            $paymentManager->registerPaymentMethodMapper($paymentMethod);
86
        }
87
88
        return $paymentManager;
89
    }
90
91
    /**
92
     * @return \SprykerEco\Zed\Payone\Business\Order\OrderManagerInterface
93
     */
94
    public function createOrderManager(): OrderManagerInterface
95
    {
96
        return new OrderManager($this->getConfig(), $this->getEntityManager());
97
    }
98
99
    /**
100
     * @return \SprykerEco\Zed\Payone\Business\TransactionStatus\TransactionStatusUpdateManagerInterface
101
     */
102
    public function createTransactionStatusManager()
103
    {
104
        return new TransactionStatusUpdateManager(
105
            $this->getQueryContainer(),
106
            $this->getStandardParameter(),
107
            $this->createKeyHashGenerator()
108
        );
109
    }
110
111
    /**
112
     * @return \SprykerEco\Zed\Payone\Business\ApiLog\ApiLogFinderInterface
113
     */
114
    public function createApiLogFinder()
115
    {
116
        return new ApiLogFinder(
117
            $this->getQueryContainer()
118
        );
119
    }
120
121
    /**
122
     * @return \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface
123
     */
124
    protected function createExecutionAdapter()
125
    {
126
        return new Guzzle(
127
            $this->getStandardParameter()->getPaymentGatewayUrl(),
128
            $this->createApiCallLogWriter()
129
        );
130
    }
131
132
    /**
133
     * @return \SprykerEco\Zed\Payone\Business\Api\Log\ApiCallLogWriter
134
     */
135
    protected function createApiCallLogWriter()
136
    {
137
        return new ApiCallLogWriter(
138
            $this->getQueryContainer()
139
        );
140
    }
141
142
    /**
143
     * @return \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface
144
     */
145
    protected function createSequenceNumberProvider()
146
    {
147
        $defaultEmptySequenceNumber = $this->getConfig()->getEmptySequenceNumber();
148
149
        return new SequenceNumberProvider(
150
            $this->getQueryContainer(),
151
            $defaultEmptySequenceNumber
0 ignored issues
show
Bug introduced by
$defaultEmptySequenceNumber of type string is incompatible with the type integer expected by parameter $defaultEmptySequenceNumber of SprykerEco\Zed\Payone\Bu...Provider::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

151
            /** @scrutinizer ignore-type */ $defaultEmptySequenceNumber
Loading history...
152
        );
153
    }
154
155
    /**
156
     * @return \SprykerEco\Shared\Payone\Dependency\HashInterface
157
     */
158
    protected function createKeyHashProvider()
159
    {
160
        $hashProvider = new HashProvider();
161
162
        return $hashProvider;
163
    }
164
165
    /**
166
     * @return \SprykerEco\Zed\Payone\Business\Key\HashGenerator
167
     */
168
    protected function createKeyHashGenerator()
169
    {
170
        return new HashGenerator(
171
            $this->createHashProvider()
172
        );
173
    }
174
175
    /**
176
     * @return \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface
177
     */
178
    protected function createUrlHmacGenerator()
179
    {
180
        return new UrlHmacGenerator();
181
    }
182
183
    /**
184
     * @return \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface
185
     */
186
    protected function createModeDetector()
187
    {
188
        $modeDetector = new ModeDetector($this->getConfig());
189
190
        return $modeDetector;
191
    }
192
193
    /**
194
     * @param \Generated\Shared\Transfer\PayoneTransactionStatusUpdateTransfer $transactionStatusUpdateTransfer
195
     *
196
     * @return \SprykerEco\Zed\Payone\Business\Api\TransactionStatus\TransactionStatusRequest
197
     */
198
    public function createTransactionStatusUpdateRequest(PayoneTransactionStatusUpdateTransfer $transactionStatusUpdateTransfer)
199
    {
200
        return new TransactionStatusRequest($transactionStatusUpdateTransfer->toArray());
201
    }
202
203
    /**
204
     * @return array
205
     */
206
    protected function getAvailablePaymentMethods()
207
    {
208
        $storeConfig = $this->getProvidedDependency(PayoneDependencyProvider::STORE_CONFIG);
209
210
        return [
211
            PayoneApiConstants::PAYMENT_METHOD_CREDITCARD_PSEUDO => $this->createCreditCardPseudo($storeConfig),
212
            PayoneApiConstants::PAYMENT_METHOD_INVOICE => $this->createInvoice($storeConfig),
213
            PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE => $this->createSecurityInvoice($storeConfig),
214
            PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER => $this->createOnlineBankTransfer($storeConfig),
215
            PayoneApiConstants::PAYMENT_METHOD_E_WALLET => $this->createEWallet($storeConfig),
216
            PayoneApiConstants::PAYMENT_METHOD_PREPAYMENT => $this->createPrepayment($storeConfig),
217
            PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT => $this->createDirectDebit($storeConfig),
218
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT => $this->createGenericPayment($storeConfig),
219
            PayoneApiConstants::PAYMENT_METHOD_CASH_ON_DELIVERY => $this->createCashOnDelivery($storeConfig, $this->getGlossaryFacade()),
220
        ];
221
    }
222
223
    /**
224
     * @return \Generated\Shared\Transfer\PayoneStandardParameterTransfer
225
     */
226
    protected function getStandardParameter()
227
    {
228
        if ($this->standardParameter === null) {
229
            $this->standardParameter = $this->getConfig()->getRequestStandardParameter();
230
        }
231
232
        return $this->standardParameter;
233
    }
234
235
    /**
236
     * @return \SprykerEco\Zed\Payone\Business\Key\HashProvider
237
     */
238
    protected function createHashProvider()
239
    {
240
        $hashProvider = new HashProvider();
241
242
        return $hashProvider;
243
    }
244
245
    /**
246
     * @param \Spryker\Shared\Kernel\Store $storeConfig
247
     *
248
     * @return \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CreditCardPseudo
249
     */
250
    protected function createCreditCardPseudo($storeConfig)
251
    {
252
        $creditCardPseudo = new CreditCardPseudo($storeConfig);
253
254
        return $creditCardPseudo;
255
    }
256
257
    /**
258
     * @param \Spryker\Shared\Kernel\Store $storeConfig
259
     *
260
     * @return \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit
261
     */
262
    protected function createDirectDebit($storeConfig)
263
    {
264
        $creditCardPseudo = new DirectDebit($storeConfig);
265
266
        return $creditCardPseudo;
267
    }
268
269
    /**
270
     * @param \Spryker\Shared\Kernel\Store $storeConfig
271
     *
272
     * @return \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice
273
     */
274
    protected function createInvoice($storeConfig)
275
    {
276
        $invoice = new Invoice($storeConfig);
277
278
        return $invoice;
279
    }
280
281
    /**
282
     * @param \Spryker\Shared\Kernel\Store $storeConfig
283
     *
284
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
285
     */
286
    protected function createSecurityInvoice($storeConfig): PaymentMethodMapperInterface
287
    {
288
        $invoice = new SecurityInvoice($storeConfig, $this->getConfig());
289
290
        return $invoice;
291
    }
292
293
    /**
294
     * @param \Spryker\Shared\Kernel\Store $storeConfig
295
     *
296
     * @return \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\OnlineBankTransfer
297
     */
298
    protected function createOnlineBankTransfer($storeConfig)
299
    {
300
        $onlineBankTransfer = new OnlineBankTransfer($storeConfig);
301
302
        return $onlineBankTransfer;
303
    }
304
305
    /**
306
     * @param \Spryker\Shared\Kernel\Store $storeConfig
307
     *
308
     * @return \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\EWallet
309
     */
310
    protected function createEWallet($storeConfig)
311
    {
312
        $EWallet = new EWallet($storeConfig);
313
314
        return $EWallet;
315
    }
316
317
    /**
318
     * @param \Spryker\Shared\Kernel\Store $storeConfig
319
     * @param \SprykerEco\Zed\Payone\Dependency\Facade\PayoneToGlossaryFacadeInterface $glossary
320
     *
321
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
322
     */
323
    protected function createCashOnDelivery(Store $storeConfig, PayoneToGlossaryFacadeInterface $glossary): PaymentMethodMapperInterface
324
    {
325
        return new CashOnDelivery($storeConfig, $glossary);
326
    }
327
328
    /**
329
     * @param \Spryker\Shared\Kernel\Store $storeConfig
330
     *
331
     * @return \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Prepayment
332
     */
333
    protected function createPrepayment($storeConfig)
334
    {
335
        $prepayment = new Prepayment($storeConfig);
336
337
        return $prepayment;
338
    }
339
340
    /**
341
     * @return \SprykerEco\Zed\Payone\Dependency\Facade\PayoneToGlossaryFacadeInterface
342
     */
343
    protected function getGlossaryFacade()
344
    {
345
        return $this->getProvidedDependency(PayoneDependencyProvider::FACADE_GLOSSARY);
346
    }
347
348
    /**
349
     * @param \Spryker\Shared\Kernel\Store $store
350
     *
351
     * @return \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\GenericPayment
352
     */
353
    protected function createGenericPayment(Store $store)
354
    {
355
        $genericPayment = new GenericPayment($store);
356
357
        return $genericPayment;
358
    }
359
360
    /**
361
     * @return \SprykerEco\Zed\Payone\Business\RiskManager\RiskCheckManagerInterface
362
     */
363
    public function createRiskCheckManager(): RiskCheckManagerInterface
364
    {
365
        return new RiskCheckManager(
366
            $this->createRiskCheckMapper(),
367
            $this->createExecutionAdapter(),
368
            $this->createRiskCheckFactory()
369
        );
370
    }
371
372
    /**
373
     * @return \SprykerEco\Zed\Payone\Business\RiskManager\Mapper\RiskCheckMapperInterface
374
     */
375
    protected function createRiskCheckMapper(): RiskCheckMapperInterface
376
    {
377
        return new RiskCheckMapper(
378
            $this->createRiskCheckFactory(),
379
            $this->getStandardParameter(),
380
            $this->createModeDetector(),
381
            $this->getConfig()
382
        );
383
    }
384
385
    /**
386
     * @return \SprykerEco\Zed\Payone\Business\RiskManager\Factory\RiskCheckFactoryInterface
387
     */
388
    protected function createRiskCheckFactory(): RiskCheckFactoryInterface
389
    {
390
        return new RiskCheckFactory();
391
    }
392
393
    /**
394
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodFilterInterface
395
     */
396
    public function createPaymentMethodFilter(): PaymentMethodFilterInterface
397
    {
398
        return new PaymentMethodFilter($this->getConfig());
399
    }
400
401
    /**
402
     * @return \SprykerEco\Zed\Payone\Business\Order\PayoneOrderItemStatusFinderInterface
403
     */
404
    public function createPayoneOrderItemStatusFinder(): PayoneOrderItemStatusFinderInterface
405
    {
406
        return new PayoneOrderItemStatusFinder($this->getRepository());
407
    }
408
409
    /**
410
     * @return \SprykerEco\Zed\Payone\Business\Distributor\OrderPriceDistributorInterface
411
     */
412
    public function createOrderPriceDistributor(): OrderPriceDistributorInterface
413
    {
414
        return new OrderPriceDistributor();
415
    }
416
}
417