Passed
Push — feature/eco-3656/eco-3658-enab... ( b8179e...c68c7e )
by
unknown
05:37
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\ComputopApiPayPalExpressCompleteResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ompleteResponseTransfer 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\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...
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\SpyPaymentComputop;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Computop\Persistence\SpyPaymentComputop 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 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...
16
use Spryker\Zed\Kernel\Persistence\AbstractEntityManager;
17
18
/**
19
 * @method \SprykerEco\Zed\Computop\Persistence\ComputopPersistenceFactory getFactory()
20
 */
21
class ComputopEntityManager extends AbstractEntityManager implements ComputopEntityManagerInterface
22
{
23
    /**
24
     * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer
25
     *
26
     * @return void
27
     */
28
    public function savePaymentComputopNotification(ComputopNotificationTransfer $computopNotificationTransfer): void
29
    {
30
        $paymentComputopNotificationEntity = $this->getFactory()
31
            ->createPaymentComputopNotificationQuery()
32
            ->filterByPayId($computopNotificationTransfer->getPayId())
33
            ->filterByTransId($computopNotificationTransfer->getTransId())
34
            ->filterByXId($computopNotificationTransfer->getXId())
35
            ->findOneOrCreate();
36
37
        $paymentComputopNotificationEntity->fromArray(
38
            $computopNotificationTransfer->modifiedToArray()
39
        );
40
        $paymentComputopNotificationEntity->save();
41
    }
42
43
    /**
44
     * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer
45
     *
46
     * @return bool
47
     */
48
    public function updatePaymentComputopOrderItemPaymentConfirmation(
49
        ComputopNotificationTransfer $computopNotificationTransfer
50
    ): bool {
51
        $paymentComputopOrderItemEntities = $this->getFactory()
52
            ->createPaymentComputopOrderItemQuery()
53
            ->useSpyPaymentComputopQuery()
54
            ->filterByTransId($computopNotificationTransfer->getTransId())
55
            ->filterByPayId($computopNotificationTransfer->getPayId())
56
            ->endUse()
57
            ->find();
58
59
        if (!$paymentComputopOrderItemEntities->count()) {
60
            return false;
61
        }
62
63
        foreach ($paymentComputopOrderItemEntities as $paymentComputopOrderItemEntity) {
64
            /** @var \Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem $paymentComputopOrderItemEntity */
65
            $paymentComputopOrderItemEntity->setIsPaymentConfirmed($computopNotificationTransfer->getIsSuccess());
66
            $paymentComputopOrderItemEntity->save();
67
        }
68
69
        return true;
70
    }
71
72
    /**
73
     * @param \Generated\Shared\Transfer\ComputopApiPayPalExpressCompleteResponseTransfer $computopApiPayPalExpressCompleteResponseTransfer
74
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
75
     *
76
     * @return void
77
     */
78
    public function updateComputopPaymentDetail(
79
        ComputopApiPayPalExpressCompleteResponseTransfer $computopApiPayPalExpressCompleteResponseTransfer,
80
        ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
81
    ): void {
82
        $computopPaymentComputopEntity = $this->getFactory()
83
            ->createComputopEntityMapper()
84
            ->mapComputopPaymentTransferToComputopPaymentEntity(
85
                $computopPaymentComputopTransfer,
86
                new SpyPaymentComputop()
87
            );
88
89
        $spyPaymentEntityDetails = $computopPaymentComputopEntity->getSpyPaymentComputopDetail();
90
        $spyPaymentEntityDetails->fromArray($computopApiPayPalExpressCompleteResponseTransfer->toArray());
91
92
        $spyPaymentEntityDetails->save();
93
    }
94
95
    /**
96
     * @param \Generated\Shared\Transfer\ComputopApiPayPalExpressCompleteResponseTransfer $computopApiPayPalExpressCompleteResponseTransfer
97
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
98
     *
99
     * @return void
100
     */
101
    public function updateComputopPayment(
102
        ComputopApiPayPalExpressCompleteResponseTransfer $computopApiPayPalExpressCompleteResponseTransfer,
103
        ComputopPaymentComputopTransfer $computopPaymentComputopTransfer
104
    ): void {
105
        $computopPaymentComputopEntity = $this->getFactory()
106
            ->createComputopEntityMapper()
107
            ->mapComputopPaymentTransferToComputopPaymentEntity(
108
                $computopPaymentComputopTransfer,
109
                new SpyPaymentComputop()
110
            );
111
112
        $computopPaymentComputopEntity->setPayId($computopApiPayPalExpressCompleteResponseTransfer->getHeader()->getPayId());
113
        $computopPaymentComputopEntity->setXId($computopApiPayPalExpressCompleteResponseTransfer->getHeader()->getXId());
114
115
        $computopPaymentComputopEntity->save();
116
    }
117
118
    /**
119
     * @param \Generated\Shared\Transfer\ComputopPaymentComputopOrderItemTransfer $computopPaymentComputopOrderItemTransfer
120
     *
121
     * @return void
122
     */
123
    public function updateComputopPaymentComputopOrderItem(
124
        ComputopPaymentComputopOrderItemTransfer $computopPaymentComputopOrderItemTransfer
125
    ): void {
126
        $paymentComputopOrderItemEntity = $this->getFactory()
127
            ->createComputopEntityMapper()
128
            ->mapComputopPaymentComputopOrderItemTransferToPaymentComputopOrderItemEntity(
129
                $computopPaymentComputopOrderItemTransfer,
130
                new SpyPaymentComputopOrderItem(),
131
            );
132
133
        $paymentComputopOrderItemEntity->save();
134
    }
135
}
136