Passed
Push — feature/eco-3653-handle-callba... ( a04ef8...b78799 )
by
unknown
05:21
created

ComputopEntityManager::savePaymentResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 21
rs 9.7666
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 Orm\Zed\Computop\Persistence\SpyPaymentComputopDetail;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Computop\Persist...pyPaymentComputopDetail 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 Propel\Runtime\Collection\ObjectCollection;
13
use Spryker\Shared\Kernel\Transfer\TransferInterface;
14
use Spryker\Zed\Kernel\Persistence\AbstractEntityManager;
15
16
/**
17
 * @method \SprykerEco\Zed\Computop\Persistence\ComputopPersistenceFactory getFactory()
18
 */
19
class ComputopEntityManager extends AbstractEntityManager implements ComputopEntityManagerInterface
20
{
21
    /**
22
     * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer
23
     *
24
     * @return void
25
     */
26
    public function savePaymentComputopNotification(ComputopNotificationTransfer $computopNotificationTransfer): void
27
    {
28
        $paymentComputopNotificationEntity = $this->getFactory()
29
            ->createPaymentComputopNotificationQuery()
30
            ->filterByPayId($computopNotificationTransfer->getPayId())
31
            ->filterByTransId($computopNotificationTransfer->getTransId())
32
            ->filterByXId($computopNotificationTransfer->getXId())
33
            ->findOneOrCreate();
34
35
        $paymentComputopNotificationEntity->fromArray(
36
            $computopNotificationTransfer->modifiedToArray()
37
        );
38
        $paymentComputopNotificationEntity->save();
39
    }
40
41
    /**
42
     * @param \Generated\Shared\Transfer\ComputopNotificationTransfer $computopNotificationTransfer
43
     *
44
     * @return bool
45
     */
46
    public function updatePaymentComputopOrderItemPaymentConfirmation(
47
        ComputopNotificationTransfer $computopNotificationTransfer
48
    ): bool {
49
        /** @var \Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem[]|\Propel\Runtime\Collection\ObjectCollection $paymentComputopOrderItemEntities */
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
            $paymentComputopOrderItemEntity->setIsPaymentConfirmed((bool)$computopNotificationTransfer->getIsSuccess());
64
            $paymentComputopOrderItemEntity->save();
65
        }
66
67
        return true;
68
    }
69
70
    /**
71
     * @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $responseTransfer
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...
72
     *
73
     * @return void
74
     */
75
    public function savePaymentResponse(TransferInterface $responseTransfer): void
76
    {
77
        $header = $responseTransfer->requireHeader()->getHeader();
0 ignored issues
show
Bug introduced by
The method requireHeader() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
        $header = $responseTransfer->/** @scrutinizer ignore-call */ requireHeader()->getHeader();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
        $header
79
            ->requireTransId()
80
            ->requirePayId()
81
            ->requireXid();
82
83
        $paymentEntity = $this->getFactory()
84
            ->createPaymentComputopQuery()
85
            ->filterByTransId($header->getTransId())
86
            ->findOne();
87
88
        $paymentEntity
89
            ->setPayId($header->getPayId())
90
            ->setXId($header->getXId())
91
            ->save();
92
93
        $this->savePaymentDetailEntity($paymentEntity->getSpyPaymentComputopDetail(), $responseTransfer);
94
95
        $this->saveAuthorizedPaymentOrderItems($paymentEntity->getSpyPaymentComputopOrderItems());
96
    }
97
98
    /**
99
     * @param \Orm\Zed\Computop\Persistence\SpyPaymentComputopDetail $paymentEntityDetails
100
     * @param \Generated\Shared\Transfer\ComputopPayuCeeSingleInitResponseTransfer $responseTransfer
101
     *
102
     * @return void
103
     */
104
    public function savePaymentDetailEntity(
105
        SpyPaymentComputopDetail $paymentEntityDetails,
106
        TransferInterface $responseTransfer
107
    ): void {
108
        $paymentEntityDetails->fromArray($responseTransfer->toArray());
109
        $paymentEntityDetails->setCustomerTransactionId($responseTransfer->getCustomerTransactionId());
0 ignored issues
show
Bug introduced by
The method getCustomerTransactionId() does not exist on Spryker\Shared\Kernel\Transfer\TransferInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
        $paymentEntityDetails->setCustomerTransactionId($responseTransfer->/** @scrutinizer ignore-call */ getCustomerTransactionId());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
        $paymentEntityDetails->save();
111
    }
112
113
    /**
114
     * @param \Orm\Zed\Computop\Persistence\SpyPaymentComputopOrderItem[]|\Propel\Runtime\Collection\ObjectCollection $paymentComputopOrderItems
115
     *
116
     * @return void
117
     */
118
    public function saveAuthorizedPaymentOrderItems(ObjectCollection $paymentComputopOrderItems): void
119
    {
120
        $authorizedStatus = $this->getFactory()->getConfig()->getOmsStatusAuthorized();
121
        foreach ($paymentComputopOrderItems as $paymentComputopOrderItem) {
122
            $paymentComputopOrderItem->setStatus($authorizedStatus);
123
            $paymentComputopOrderItem->save();
124
        }
125
    }
126
}
127