Passed
Push — feature/eco-3047/eco-3049-invo... ( f3405c...b52d71 )
by Aleksey
03:49
created

IsFinalizingFinishedOmsCondition::check()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 13
c 1
b 0
f 0
rs 10
cc 2
nc 2
nop 1
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;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...payNotificationTransfer 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\Sales\Persistence\SpySalesOrderItem;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrderItem 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 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
        $heidelpayNotificationTransfer = $this->repository
40
            ->findPaymentHeidelpayNotificationByTransactionIdAndPaymentCode(
41
                (string)$orderItem->getFkSalesOrder(),
42
                static::FINALIZE_PAYMENT_CODE
43
            );
44
45
        if ($heidelpayNotificationTransfer === null) {
46
            return false;
47
        }
48
49
        return $this->isNotificationSuccessful($heidelpayNotificationTransfer);
50
    }
51
52
    /**
53
     * @param \Generated\Shared\Transfer\HeidelpayNotificationTransfer $heidelpayNotificationTransfer
54
     *
55
     * @return bool
56
     */
57
    protected function isNotificationSuccessful(HeidelpayNotificationTransfer $heidelpayNotificationTransfer): bool
58
    {
59
        return $heidelpayNotificationTransfer->getResult() === HeidelpayConfig::NOTIFICATION_STATUS_OK;
60
    }
61
}
62