Passed
Push — feature/eco-574/eco-2266-check... ( 7e1004...8cf5ab )
by Aleksey
04:15
created

IsCancellationCompletedPlugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 3 1
A isCancelTransactionSuccessful() 0 8 2
A isTransactionSuccessful() 0 3 1
A getCancelTransactionLogEntry() 0 5 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\AfterPay\Communication\Plugin\Oms\Condition;
9
10
use Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayTransactionLog;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\AfterPay\Persist...tAfterPayTransactionLog 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;
0 ignored issues
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 Spryker\Zed\Kernel\Communication\AbstractPlugin;
13
use Spryker\Zed\Oms\Dependency\Plugin\Condition\ConditionInterface;
14
use SprykerEco\Shared\AfterPay\AfterPayConfig;
15
16
/**
17
 * @method \SprykerEco\Zed\AfterPay\Business\AfterPayFacadeInterface getFacade()
18
 * @method \SprykerEco\Zed\AfterPay\Persistence\AfterPayQueryContainer getQueryContainer()
19
 * @method \SprykerEco\Zed\AfterPay\Communication\AfterPayCommunicationFactory getFactory()
20
 * @method \SprykerEco\Zed\AfterPay\AfterPayConfig getConfig()
21
 */
22
class IsCancellationCompletedPlugin extends AbstractPlugin implements ConditionInterface
23
{
24
    public const CANCEL_TRANSACTION_ACCEPTED = AfterPayConfig::API_TRANSACTION_OUTCOME_ACCEPTED;
25
26
    /**
27
     * @api
28
     *
29
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
30
     *
31
     * @return bool
32
     */
33
    public function check(SpySalesOrderItem $orderItem): bool
34
    {
35
        return $this->isCancelTransactionSuccessful($orderItem->getFkSalesOrder());
36
    }
37
38
    /**
39
     * @param int $idSalesOrder
40
     *
41
     * @return bool
42
     */
43
    protected function isCancelTransactionSuccessful(int $idSalesOrder): bool
44
    {
45
        $fullCancelTransactionLog = $this->getCancelTransactionLogEntry($idSalesOrder);
46
        if ($fullCancelTransactionLog === null) {
47
            return false;
48
        }
49
50
        return $this->isTransactionSuccessful($fullCancelTransactionLog);
51
    }
52
53
    /**
54
     * @param int $idSalesOrder
55
     *
56
     * @return \Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayTransactionLog|null
57
     */
58
    protected function getCancelTransactionLogEntry(int $idSalesOrder): ?SpyPaymentAfterPayTransactionLog
59
    {
60
        $transactionLogQuery = $this->getQueryContainer()->queryCancelTransactionLog($idSalesOrder);
61
62
        return $transactionLogQuery->findOne();
63
    }
64
65
    /**
66
     * @param \Orm\Zed\AfterPay\Persistence\SpyPaymentAfterPayTransactionLog $fullCancelTransactionLog
67
     *
68
     * @return bool
69
     */
70
    protected function isTransactionSuccessful(SpyPaymentAfterPayTransactionLog $fullCancelTransactionLog): bool
71
    {
72
        return $fullCancelTransactionLog->getOutcome() === static::CANCEL_TRANSACTION_ACCEPTED;
73
    }
74
}
75