Passed
Push — feature/eco-3623-payone-pay-u-... ( f81b95...9736bb )
by Roman
04:54
created

PayuCeeSingleResponseSaver::getPaymentStatus()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
rs 9.6111
cc 5
nc 4
nop 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\Shared\Computop\ComputopConfig as SharedComputopConfig;
13
use SprykerEco\Zed\Computop\ComputopConfig;
14
use SprykerEco\Zed\Computop\Dependency\Facade\ComputopToOmsFacadeInterface;
15
use SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface;
16
use SprykerEco\Zed\Computop\Persistence\ComputopQueryContainerInterface;
17
18
class PayuCeeSingleResponseSaver extends AbstractResponseSaver
19
{
20
    /**
21
     * @var \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface
22
     */
23
    protected $computopEntityManager;
24
25
    /**
26
     * @param \SprykerEco\Zed\Computop\Persistence\ComputopQueryContainerInterface $queryContainer
27
     * @param \SprykerEco\Zed\Computop\Dependency\Facade\ComputopToOmsFacadeInterface $omsFacade
28
     * @param \SprykerEco\Zed\Computop\ComputopConfig $config
29
     * @param \SprykerEco\Zed\Computop\Persistence\ComputopEntityManagerInterface $computopEntityManager
30
     */
31
    public function __construct(
32
        ComputopQueryContainerInterface $queryContainer,
33
        ComputopToOmsFacadeInterface $omsFacade,
34
        ComputopConfig $config,
35
        ComputopEntityManagerInterface $computopEntityManager
36
    ) {
37
        parent::__construct($queryContainer, $omsFacade, $config);
38
        $this->computopEntityManager = $computopEntityManager;
39
    }
40
41
    /**
42
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
43
     *
44
     * @return \Generated\Shared\Transfer\QuoteTransfer
45
     */
46
    public function save(QuoteTransfer $quoteTransfer): QuoteTransfer
47
    {
48
        if (
49
            !$quoteTransfer->getPayment() ||
50
            !$quoteTransfer->getPayment()->getComputopPayuCeeSingle() ||
51
            !$quoteTransfer->getPayment()->getComputopPayuCeeSingle()->getPayuCeeSingleInitResponse()
52
        ) {
53
            return $quoteTransfer;
54
        }
55
56
        $computopPayuCeeSingleInitResponse = $quoteTransfer->getPayment()->getComputopPayuCeeSingle()->getPayuCeeSingleInitResponse();
57
        if ($computopPayuCeeSingleInitResponse->getHeader()->getIsSuccess()) {
58
            $this->handleSaveTransaction($computopPayuCeeSingleInitResponse);
59
        }
60
61
        return $quoteTransfer;
62
    }
63
64
    /**
65
     * @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer
66
     *
67
     * @return void
68
     */
69
    protected function handleSaveTransaction(ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer): void
70
    {
71
        $this->getTransactionHandler()->handleTransaction(function () use ($computopPayuCeeSingleInitResponseTransfer) {
72
            $this->executeSavePaymentResponseTransaction($computopPayuCeeSingleInitResponseTransfer);
73
        });
74
    }
75
76
    /**
77
     * @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer
78
     *
79
     * @return void
80
     */
81
    protected function executeSavePaymentResponseTransaction(ComputopPayuCeeSingleInitResponseTransfer $computopPayuCeeSingleInitResponseTransfer): void
82
    {
83
        $this->computopEntityManager->saveComputopPayuCeeSingleInitResponse($computopPayuCeeSingleInitResponseTransfer);
84
    }
85
}
86