IsFinalizingFinishedOmsCondition   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isFinalizingSuccessful() 0 3 1
A check() 0 14 2
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\Heidelpay\Communication\Oms\Condition;
9
10
use Generated\Shared\Transfer\HeidelpayNotificationTransfer;
11
use Orm\Zed\Sales\Persistence\SpySalesOrderItem;
12
use SprykerEco\Shared\Heidelpay\HeidelpayConfig;
13
use SprykerEco\Zed\Heidelpay\Persistence\HeidelpayRepositoryInterface;
14
15
class IsFinalizingFinishedOmsCondition implements HeidelpayOmsConditionInterface
16
{
17
    protected const FINALIZE_PAYMENT_CODE = 'IV.FI';
18
19
    /**
20
     * @var \SprykerEco\Zed\Heidelpay\Persistence\HeidelpayRepositoryInterface
21
     */
22
    protected $repository;
23
24
    /**
25
     * @param \SprykerEco\Zed\Heidelpay\Persistence\HeidelpayRepositoryInterface $repository
26
     */
27
    public function __construct(HeidelpayRepositoryInterface $repository)
28
    {
29
        $this->repository = $repository;
30
    }
31
32
    /**
33
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
34
     *
35
     * @return bool
36
     */
37
    public function check(SpySalesOrderItem $orderItem): bool
38
    {
39
        $heidelpayNotificationCollection = $this->repository
40
            ->getPaymentHeidelpayNotificationCollectionByTransactionIdAndPaymentCode(
41
                (string)$orderItem->getFkSalesOrder(),
42
                static::FINALIZE_PAYMENT_CODE
43
            );
44
45
        if ($heidelpayNotificationCollection->getNotifications()->count() === 0) {
46
            return false;
47
        }
48
49
        return $this->isFinalizingSuccessful(
50
            $heidelpayNotificationCollection->getNotifications()->offsetGet(0)
51
        );
52
    }
53
54
    /**
55
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $heidelpayNotificationTransfer
56
     *
57
     * @return bool
58
     */
59
    protected function isFinalizingSuccessful(HeidelpayNotificationTransfer $heidelpayNotificationTransfer): bool
60
    {
61
        return $heidelpayNotificationTransfer->getResult() === HeidelpayConfig::NOTIFICATION_STATUS_OK;
62
    }
63
}
64