Passed
Pull Request — master (#57)
by Roman
08:36 queued 17s
created

PayoneBusinessFactory::createPriceDistributor()   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 Psr\Log\LoggerInterface as MessengerInterface;
12
use Spryker\Shared\Kernel\Store;
13
use Spryker\Zed\Kernel\Business\AbstractBusinessFactory;
14
use SprykerEco\Shared\Payone\PayoneApiConstants;
15
use SprykerEco\Zed\Payone\Business\Api\Adapter\Http\Guzzle;
16
use SprykerEco\Zed\Payone\Business\Api\Log\ApiCallLogWriter;
17
use SprykerEco\Zed\Payone\Business\Api\TransactionStatus\TransactionStatusRequest;
18
use SprykerEco\Zed\Payone\Business\ApiLog\ApiLogFinder;
19
use SprykerEco\Zed\Payone\Business\Internal\Installer;
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\Distributor\PriceDistributor;
43
use SprykerEco\Zed\Payone\Business\Distributor\PriceDistributorInterface;
44
use SprykerEco\Zed\Payone\Business\RiskManager\Factory\RiskCheckFactory;
45
use SprykerEco\Zed\Payone\Business\RiskManager\Factory\RiskCheckFactoryInterface;
46
use SprykerEco\Zed\Payone\Business\RiskManager\Mapper\RiskCheckMapper;
47
use SprykerEco\Zed\Payone\Business\RiskManager\Mapper\RiskCheckMapperInterface;
48
use SprykerEco\Zed\Payone\Business\RiskManager\RiskCheckManager;
49
use SprykerEco\Zed\Payone\Business\RiskManager\RiskCheckManagerInterface;
50
use SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProvider;
51
use SprykerEco\Zed\Payone\Business\TransactionStatus\TransactionStatusUpdateManager;
52
use SprykerEco\Zed\Payone\Dependency\Facade\PayoneToGlossaryFacadeInterface;
53
use SprykerEco\Zed\Payone\Dependency\Facade\PayoneToSalesInterface;
54
use SprykerEco\Zed\Payone\PayoneDependencyProvider;
55
56
/**
57
 * @method \SprykerEco\Zed\Payone\PayoneConfig getConfig()
58
 * @method \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface getQueryContainer()
59
 * @method \SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface getRepository()
60
 * @method \SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface getEntityManager()
61
 */
62
class PayoneBusinessFactory extends AbstractBusinessFactory
63
{
64
    /**
65
     * @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...
66
     */
67
    private $standardParameter;
68
69
    /**
70
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentManagerInterface
71
     */
72
    public function createPaymentManager(): PaymentManagerInterface
73
    {
74
        $paymentManager = new PaymentManager(
75
            $this->createExecutionAdapter(),
76
            $this->getQueryContainer(),
77
            $this->getStandardParameter(),
78
            $this->createKeyHashGenerator(),
79
            $this->createSequenceNumberProvider(),
80
            $this->createModeDetector(),
81
            $this->createUrlHmacGenerator(),
82
            $this->getRepository(),
83
            $this->getEntityManager()
84
        );
85
86
        foreach ($this->getAvailablePaymentMethods() as $paymentMethod) {
87
            $paymentManager->registerPaymentMethodMapper($paymentMethod);
88
        }
89
90
        return $paymentManager;
91
    }
92
93
    /**
94
     * @return \SprykerEco\Zed\Payone\Business\Order\OrderManagerInterface
95
     */
96
    public function createOrderManager(): OrderManagerInterface
97
    {
98
        return new OrderManager($this->getConfig(), $this->getEntityManager());
99
    }
100
101
    /**
102
     * @return \SprykerEco\Zed\Payone\Business\TransactionStatus\TransactionStatusUpdateManagerInterface
103
     */
104
    public function createTransactionStatusManager()
105
    {
106
        return new TransactionStatusUpdateManager(
107
            $this->getQueryContainer(),
108
            $this->getStandardParameter(),
109
            $this->createKeyHashGenerator()
110
        );
111
    }
112
113
    /**
114
     * @return \SprykerEco\Zed\Payone\Business\ApiLog\ApiLogFinderInterface
115
     */
116
    public function createApiLogFinder()
117
    {
118
        return new ApiLogFinder(
119
            $this->getQueryContainer()
120
        );
121
    }
122
123
    /**
124
     * @return \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface
125
     */
126
    protected function createExecutionAdapter()
127
    {
128
        return new Guzzle(
129
            $this->getStandardParameter()->getPaymentGatewayUrl(),
130
            $this->createApiCallLogWriter()
131
        );
132
    }
133
134
    /**
135
     * @return \SprykerEco\Zed\Payone\Business\Api\Log\ApiCallLogWriter
136
     */
137
    protected function createApiCallLogWriter()
138
    {
139
        return new ApiCallLogWriter(
140
            $this->getQueryContainer()
141
        );
142
    }
143
144
    /**
145
     * @return \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface
146
     */
147
    protected function createSequenceNumberProvider()
148
    {
149
        $defaultEmptySequenceNumber = $this->getConfig()->getEmptySequenceNumber();
150
151
        return new SequenceNumberProvider(
152
            $this->getQueryContainer(),
153
            $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

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