Passed
Push — feature/eco-3623-payone-pay-u-... ( 0a3f73...4fb100 )
by Roman
03:15
created

DetailEntityByComputopApiResponseHeaderTransfer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
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
            ->getPaymentComputopNotificationQuery()
31
            ->filterByPayId($computopNotificationTransfer->getPayId())
32
            ->filterByTransId($computopNotificationTransfer->getTransId())
33
            ->filterByXId($computopNotificationTransfer->getXId())
34
            ->findOneOrCreate();
35
36
        $paymentComputopNotificationEntity
37
            ->fromArray($computopNotificationTransfer->modifiedToArray())
38
            ->save();
39
    }
40
41
    /**
42
     * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer
43
     * @param string|null $orderItemsStatus
44
     *
45
     * @return bool
46
     */
47
    public function updatePaymentComputopOrderItemPaymentConfirmation(
48
        ComputopNotificationTransfer $computopNotificationTransfer,
49
        ?string $orderItemsStatus = null
50
    ): bool {
51
        /** @var \Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem[]|\Propel\Runtime\Collection\ObjectCollection $paymentComputopOrderItemEntities */
52
        $paymentComputopOrderItemEntities = $this->getFactory()
53
            ->getPaymentComputopOrderItemQuery()
54
            ->useSpyPaymentComputopQuery()
55
                ->filterByTransId($computopNotificationTransfer->getTransId())
56
                ->filterByPayId($computopNotificationTransfer->getPayId())
57
            ->endUse()
58
            ->find();
59
60
        if (!$paymentComputopOrderItemEntities->count()) {
61
            return false;
62
        }
63
64
        foreach ($paymentComputopOrderItemEntities as $paymentComputopOrderItemEntity) {
65
            $paymentComputopOrderItemEntity
66
                ->setIsPaymentConfirmed((bool)$computopNotificationTransfer->getIsSuccess())
67
                ->setStatus($orderItemsStatus ?? $paymentComputopOrderItemEntity->getStatus())
68
                ->save();
69
        }
70
71
        return true;
72
    }
73
74
    /**
75
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopDetailTransfer $computopPaymentComputopDetailTransfer
76
     *
77
     * @return void
78
     */
79
    public function updateComputopPaymentDetail(
80
        ComputopPaymentComputopDetailTransfer $computopPaymentComputopDetailTransfer
81
    ): void {
82
        $computopPaymentComputopDetailEntity = $this->getFactory()
83
            ->getPaymentComputopDetailQuery()
84
            ->filterByIdPaymentComputop($computopPaymentComputopDetailTransfer->getIdPaymentComputop())
85
            ->findOne();
86
87
        if ($computopPaymentComputopDetailEntity === null) {
88
            return;
89
        }
90
91
        $computopPaymentComputopDetailEntity = $this->getFactory()
92
            ->createComputopMapper()
93
            ->mapComputopPaymentComputopDetailTransferToPaymentComputopDetailEntity(
94
                $computopPaymentComputopDetailTransfer,
95
                $computopPaymentComputopDetailEntity
96
            );
97
98
        $computopPaymentComputopDetailEntity->save();
99
    }
100
101
    /**
102
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
103
     *
104
     * @return void
105
     */
106
    public function saveComputopPayment(ComputopPaymentComputopTransfer $computopPaymentComputopTransfer): void
107
    {
108
        $computopPaymentComputopEntity = $this->getFactory()
109
            ->getPaymentComputopQuery()
110
            ->filterByTransId($computopPaymentComputopTransfer->getTransId())
111
            ->findOne();
112
113
        if ($computopPaymentComputopEntity === null) {
114
            return;
115
        }
116
117
        $computopPaymentComputopEntity = $this->getFactory()
118
            ->createComputopMapper()
119
            ->mapComputopPaymentTransferToComputopPaymentEntity(
120
                $computopPaymentComputopTransfer,
121
                $computopPaymentComputopEntity
122
            );
123
124
        $computopPaymentComputopEntity->save();
125
    }
126
127
    /**
128
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopOrderItemTransfer $computopPaymentComputopOrderItemTransfer
129
     *
130
     * @return void
131
     */
132
    public function updateComputopPaymentComputopOrderItem(
133
        ComputopPaymentComputopOrderItemTransfer $computopPaymentComputopOrderItemTransfer
134
    ): void {
135
        $paymentComputopOrderItemEntity = $this->getFactory()
136
            ->createComputopMapper()
137
            ->mapComputopPaymentComputopOrderItemTransferToPaymentComputopOrderItemEntity(
138
                $computopPaymentComputopOrderItemTransfer,
139
                new SpyPaymentComputopOrderItem(),
140
            );
141
142
        $paymentComputopOrderItemEntity->save();
143
    }
144
}
145