Passed
Push — feature/eco-3656/eco-3658-enab... ( c68c7e...4d2e5e )
by
unknown
20:30
created

updateComputopPaymentDetail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 15
rs 10
cc 1
nc 1
nop 2
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\Persistence;
9
10
use Generated\Shared\Transfer\ComputopNotificationTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...topNotificationTransfer 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\ComputopPaymentComputopDetailTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...tComputopDetailTransfer 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 Generated\Shared\Transfer\ComputopPaymentComputopOrderItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...mputopOrderItemTransfer 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...
13
use Generated\Shared\Transfer\ComputopPaymentComputopTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PaymentComputopTransfer 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...
14
use Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Computop\Persist...aymentComputopOrderItem 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...
15
use Spryker\Zed\Kernel\Persistence\AbstractEntityManager;
16
17
/**
18
 * @method \SprykerEco\Zed\Computop\Persistence\ComputopPersistenceFactory getFactory()
19
 */
20
class ComputopEntityManager extends AbstractEntityManager implements ComputopEntityManagerInterface
21
{
22
    /**
23
     * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer
24
     *
25
     * @return void
26
     */
27
    public function savePaymentComputopNotification(ComputopNotificationTransfer $computopNotificationTransfer): void
28
    {
29
        $paymentComputopNotificationEntity = $this->getFactory()
30
            ->createPaymentComputopNotificationQuery()
31
            ->filterByPayId($computopNotificationTransfer->getPayId())
32
            ->filterByTransId($computopNotificationTransfer->getTransId())
33
            ->filterByXId($computopNotificationTransfer->getXId())
34
            ->findOneOrCreate();
35
36
        $paymentComputopNotificationEntity->fromArray(
37
            $computopNotificationTransfer->modifiedToArray()
38
        );
39
        $paymentComputopNotificationEntity->save();
40
    }
41
42
    /**
43
     * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer
44
     *
45
     * @return bool
46
     */
47
    public function updatePaymentComputopOrderItemPaymentConfirmation(
48
        ComputopNotificationTransfer $computopNotificationTransfer
49
    ): bool {
50
        $paymentComputopOrderItemEntities = $this->getFactory()
51
            ->createPaymentComputopOrderItemQuery()
52
            ->useSpyPaymentComputopQuery()
53
            ->filterByTransId($computopNotificationTransfer->getTransId())
54
            ->filterByPayId($computopNotificationTransfer->getPayId())
55
            ->endUse()
56
            ->find();
57
58
        if (!$paymentComputopOrderItemEntities->count()) {
59
            return false;
60
        }
61
62
        foreach ($paymentComputopOrderItemEntities as $paymentComputopOrderItemEntity) {
63
            /** @var \Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem $paymentComputopOrderItemEntity */
64
            $paymentComputopOrderItemEntity->setIsPaymentConfirmed($computopNotificationTransfer->getIsSuccess());
65
            $paymentComputopOrderItemEntity->save();
66
        }
67
68
        return true;
69
    }
70
71
    /**
72
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopDetailTransfer $computopPaymentComputopDetailTransfer
73
     *
74
     * @return void
75
     */
76
    public function saveComputopPaymentDetail(
77
        ComputopPaymentComputopDetailTransfer $computopPaymentComputopDetailTransfer
78
    ): void {
79
        $computopPaymentComputopDetailEntity = $this->getFactory()
80
            ->createPaymentComputopDetailQuery()
81
            ->filterByIdPaymentComputop($computopPaymentComputopDetailTransfer->getIdPaymentComputop())
82
            ->findOne();
83
84
        $computopPaymentComputopDetailEntity = $this->getFactory()
85
            ->createComputopEntityMapper()
86
            ->mapComputopPaymentComputopDetailTransferToPaymentComputopDetailEntity(
87
                $computopPaymentComputopDetailTransfer,
88
                $computopPaymentComputopDetailEntity
89
            );
90
91
        $computopPaymentComputopDetailEntity->save();
92
    }
93
94
    /**
95
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
96
     *
97
     * @return void
98
     */
99
    public function saveComputopPayment(ComputopPaymentComputopTransfer $computopPaymentComputopTransfer): void
100
    {
101
        $computopPaymentComputopEntity = $this->getFactory()
102
            ->createPaymentComputopQuery()
103
            ->filterByTransId($computopPaymentComputopTransfer->getTransId())->findOne();
104
105
        $computopPaymentComputopEntity = $this->getFactory()
106
            ->createComputopEntityMapper()
107
            ->mapComputopPaymentTransferToComputopPaymentEntity(
108
                $computopPaymentComputopTransfer,
109
                $computopPaymentComputopEntity
110
            );
111
112
        $computopPaymentComputopEntity->save();
113
    }
114
115
    /**
116
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopOrderItemTransfer $computopPaymentComputopOrderItemTransfer
117
     *
118
     * @return void
119
     */
120
    public function updateComputopPaymentComputopOrderItem(
121
        ComputopPaymentComputopOrderItemTransfer $computopPaymentComputopOrderItemTransfer
122
    ): void {
123
        $paymentComputopOrderItemEntity = $this->getFactory()
124
            ->createComputopEntityMapper()
125
            ->mapComputopPaymentComputopOrderItemTransferToPaymentComputopOrderItemEntity(
126
                $computopPaymentComputopOrderItemTransfer,
127
                new SpyPaymentComputopOrderItem(),
128
            );
129
130
        $paymentComputopOrderItemEntity->save();
131
    }
132
}
133