Passed
Pull Request — master (#41)
by Roman
08:34
created

PayuCeeSingleResponseSaver   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 8
eloc 16
c 3
b 0
f 1
dl 0
loc 66
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A executeSavePaymentResponseTransaction() 0 3 1
A save() 0 16 5
A handleSaveTransaction() 0 4 1
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\Computop\Business\Payment\Handler\Saver\Init;
9
10
use Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...gleInitResponseTransfer 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\QuoteTransfer;
0 ignored issues
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...
12
use SprykerEco\Zed\Computop\ComputopConfig;
13
use SprykerEco\Zed\Computop\Dependency\Facade\ComputopToOmsFacadeInterface;
14
use SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface;
15
use SprykerEco\Zed\Computop\Persistence\ComputopQueryContainerInterface;
16
17
class PayuCeeSingleResponseSaver extends AbstractResponseSaver
18
{
19
    /**
20
     * @var \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface
21
     */
22
    protected $computopEntityManager;
23
24
    /**
25
     * @param \SprykerEco\Zed\Computop\Persistence\ComputopQueryContainerInterface $queryContainer
26
     * @param \SprykerEco\Zed\Computop\Dependency\Facade\ComputopToOmsFacadeInterface $omsFacade
27
     * @param \SprykerEco\Zed\Computop\ComputopConfig $config
28
     * @param \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface $computopEntityManager
29
     */
30
    public function __construct(
31
        ComputopQueryContainerInterface $queryContainer,
32
        ComputopToOmsFacadeInterface $omsFacade,
33
        ComputopConfig $config,
34
        ComputopEntityManagerInterface $computopEntityManager
35
    ) {
36
        parent::__construct($queryContainer, $omsFacade, $config);
37
        $this->computopEntityManager = $computopEntityManager;
38
    }
39
40
    /**
41
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
42
     *
43
     * @return \Generated\Shared\Transfer\QuoteTransfer
44
     */
45
    public function save(QuoteTransfer $quoteTransfer): QuoteTransfer
46
    {
47
        if (
48
            !$quoteTransfer->getPayment() ||
49
            !$quoteTransfer->getPayment()->getComputopPayuCeeSingle() ||
50
            !$quoteTransfer->getPayment()->getComputopPayuCeeSingle()->getPayuCeeSingleInitResponse()
51
        ) {
52
            return $quoteTransfer;
53
        }
54
55
        $computopPayuCeeSingleInitResponse = $quoteTransfer->getPayment()->getComputopPayuCeeSingle()->getPayuCeeSingleInitResponse();
56
        if ($computopPayuCeeSingleInitResponse->getHeader()->getIsSuccess()) {
57
            $this->handleSaveTransaction($computopPayuCeeSingleInitResponse);
58
        }
59
60
        return $quoteTransfer;
61
    }
62
63
    /**
64
     * @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer
65
     *
66
     * @return void
67
     */
68
    protected function handleSaveTransaction(ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer): void
69
    {
70
        $this->getTransactionHandler()->handleTransaction(function () use ($computopPayuCeeSingleInitResponseTransfer) {
71
            $this->executeSavePaymentResponseTransaction($computopPayuCeeSingleInitResponseTransfer);
72
        });
73
    }
74
75
    /**
76
     * @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer
77
     *
78
     * @return void
79
     */
80
    protected function executeSavePaymentResponseTransaction(ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer): void
81
    {
82
        $this->computopEntityManager->saveComputopPayuCeeSingleInitResponse($computopPayuCeeSingleInitResponseTransfer);
83
    }
84
}
85