Passed
Pull Request — feature/eco-3656/dev-paypal-ex... (#40)
by
unknown
04:55
created

updateComputopPaymentComputopOrderItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
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\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->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
            ->getPaymentComputopOrderItemQuery()
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 updateComputopPaymentDetail(
77
        ComputopPaymentComputopDetailTransfer $computopPaymentComputopDetailTransfer
78
    ): void {
79
        $computopPaymentComputopDetailEntity = $this->getFactory()
80
            ->getPaymentComputopDetailQuery()
81
            ->filterByIdPaymentComputop($computopPaymentComputopDetailTransfer->getIdPaymentComputop())
82
            ->findOne();
83
84
        if ($computopPaymentComputopDetailEntity === null) {
85
            return;
86
        }
87
88
        $computopPaymentComputopDetailEntity = $this->getFactory()
89
            ->createComputopMapper()
90
            ->mapComputopPaymentComputopDetailTransferToPaymentComputopDetailEntity(
91
                $computopPaymentComputopDetailTransfer,
92
                $computopPaymentComputopDetailEntity
93
            );
94
95
        $computopPaymentComputopDetailEntity->save();
96
    }
97
98
    /**
99
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
100
     *
101
     * @return void
102
     */
103
    public function saveComputopPayment(ComputopPaymentComputopTransfer $computopPaymentComputopTransfer): void
104
    {
105
        $computopPaymentComputopEntity = $this->getFactory()
106
            ->getPaymentComputopQuery()
107
            ->filterByTransId($computopPaymentComputopTransfer->getTransId())
108
            ->findOne();
109
110
        if ($computopPaymentComputopEntity === null) {
111
            return;
112
        }
113
114
        $computopPaymentComputopEntity = $this->getFactory()
115
            ->createComputopMapper()
116
            ->mapComputopPaymentTransferToComputopPaymentEntity(
117
                $computopPaymentComputopTransfer,
118
                $computopPaymentComputopEntity
119
            );
120
121
        $computopPaymentComputopEntity->save();
122
    }
123
124
    /**
125
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopOrderItemTransfer $computopPaymentComputopOrderItemTransfer
126
     *
127
     * @return void
128
     */
129
    public function updateComputopPaymentComputopOrderItem(
130
        ComputopPaymentComputopOrderItemTransfer $computopPaymentComputopOrderItemTransfer
131
    ): void {
132
        $paymentComputopOrderItemEntity = $this->getFactory()
133
            ->createComputopMapper()
134
            ->mapComputopPaymentComputopOrderItemTransferToPaymentComputopOrderItemEntity(
135
                $computopPaymentComputopOrderItemTransfer,
136
                new SpyPaymentComputopOrderItem(),
137
            );
138
139
        $paymentComputopOrderItemEntity->save();
140
    }
141
}
142