Passed
Pull Request — master (#38)
by Ruslan
05:12
created

PayoneBusinessFactory::createCashOnDelivery()   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
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Payment\MethodMapper\CashOnDelivery;
26
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CreditCardPseudo;
27
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit;
28
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\EWallet;
29
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\GenericPayment;
30
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice;
31
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\OnlineBankTransfer;
32
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Prepayment;
33
use SprykerEco\Zed\Payone\Business\Payment\MethodMapper\SecurityInvoice;
34
use SprykerEco\Zed\Payone\Business\Payment\PaymentManager;
35
use SprykerEco\Zed\Payone\Business\Payment\PaymentMethodFilter;
36
use SprykerEco\Zed\Payone\Business\Payment\PaymentMethodFilterInterface;
37
use SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface;
38
use SprykerEco\Zed\Payone\Business\RiskManager\Factory\RiskCheckFactory;
39
use SprykerEco\Zed\Payone\Business\RiskManager\Factory\RiskCheckFactoryInterface;
40
use SprykerEco\Zed\Payone\Business\RiskManager\Mapper\RiskCheckMapper;
41
use SprykerEco\Zed\Payone\Business\RiskManager\Mapper\RiskCheckMapperInterface;
42
use SprykerEco\Zed\Payone\Business\RiskManager\RiskCheckManager;
43
use SprykerEco\Zed\Payone\Business\RiskManager\RiskCheckManagerInterface;
44
use SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProvider;
45
use SprykerEco\Zed\Payone\Business\TransactionStatus\TransactionStatusUpdateManager;
46
use SprykerEco\Zed\Payone\Dependency\Facade\PayoneToGlossaryInterface;
47
use SprykerEco\Zed\Payone\PayoneDependencyProvider;
48
49
/**
50
 * @method \SprykerEco\Zed\Payone\PayoneConfig getConfig()
51
 * @method \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface getQueryContainer()
52
 */
53
class PayoneBusinessFactory extends AbstractBusinessFactory
54
{
55
    /**
56
     * @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...
57
     */
58
    private $standardParameter;
59
60
    /**
61
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentManagerInterface
62
     */
63
    public function createPaymentManager()
64
    {
65
        $paymentManager = new PaymentManager(
66
            $this->createExecutionAdapter(),
67
            $this->getQueryContainer(),
68
            $this->getStandardParameter(),
69
            $this->createKeyHashGenerator(),
70
            $this->createSequenceNumberProvider(),
71
            $this->createModeDetector(),
72
            $this->createUrlHmacGenerator()
73
        );
74
75
        foreach ($this->getAvailablePaymentMethods() as $paymentMethod) {
76
            $paymentManager->registerPaymentMethodMapper($paymentMethod);
77
        }
78
79
        return $paymentManager;
80
    }
81
82
    /**
83
     * @return \SprykerEco\Zed\Payone\Business\Order\OrderManagerInterface
84
     */
85
    public function createOrderManager()
86
    {
87
        $orderManager = new OrderManager($this->getConfig());
88
89
        return $orderManager;
90
    }
91
92
    /**
93
     * @return \SprykerEco\Zed\Payone\Business\TransactionStatus\TransactionStatusUpdateManagerInterface
94
     */
95
    public function createTransactionStatusManager()
96
    {
97
        return new TransactionStatusUpdateManager(
98
            $this->getQueryContainer(),
99
            $this->getStandardParameter(),
100
            $this->createKeyHashGenerator()
101
        );
102
    }
103
104
    /**
105
     * @return \SprykerEco\Zed\Payone\Business\ApiLog\ApiLogFinderInterface
106
     */
107
    public function createApiLogFinder()
108
    {
109
        return new ApiLogFinder(
110
            $this->getQueryContainer()
111
        );
112
    }
113
114
    /**
115
     * @return \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface
116
     */
117
    protected function createExecutionAdapter()
118
    {
119
        return new Guzzle(
120
            $this->getStandardParameter()->getPaymentGatewayUrl(),
121
            $this->createApiCallLogWriter()
122
        );
123
    }
124
125
    /**
126
     * @return \SprykerEco\Zed\Payone\Business\Api\Log\ApiCallLogWriter
127
     */
128
    protected function createApiCallLogWriter()
129
    {
130
        return new ApiCallLogWriter(
131
            $this->getQueryContainer()
132
        );
133
    }
134
135
    /**
136
     * @return \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface
137
     */
138
    protected function createSequenceNumberProvider()
139
    {
140
        $defaultEmptySequenceNumber = $this->getConfig()->getEmptySequenceNumber();
141
142
        return new SequenceNumberProvider(
143
            $this->getQueryContainer(),
144
            $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

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