Passed
Push — bugfix/supesc-213-is-capture-a... ( b6d348...db0ba1 )
by Anton
16:04
created

SalesOrderChecker::isCaptureApproved()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 1
b 1
f 0
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\Business\Checker;
9
10
use SprykerEco\Shared\Heidelpay\HeidelpayConfig;
11
use SprykerEco\Zed\Heidelpay\Persistence\HeidelpayRepositoryInterface;
12
13
class SalesOrderChecker implements SalesOrderCheckerInterface
14
{
15
    /**
16
     * @var \SprykerEco\Zed\Heidelpay\Persistence\HeidelpayRepositoryInterface
17
     */
18
    protected $heidelpayRepository;
19
20
    /**
21
     * @param \SprykerEco\Zed\Heidelpay\Persistence\HeidelpayRepositoryInterface $heidelpayRepository
22
     */
23
    public function __construct(HeidelpayRepositoryInterface $heidelpayRepository)
24
    {
25
        $this->heidelpayRepository = $heidelpayRepository;
26
    }
27
28
    /**
29
     * @param int $idSalesOrder
30
     *
31
     * @return bool
32
     */
33
    public function isCaptureApproved(int $idSalesOrder): bool
34
    {
35
        $heidelpayTransactionLogTransfer = $this->heidelpayRepository
36
            ->findHeidelpayTransactionLogByIdSalesOrderAndTransactionTypeAndResponseCode(
37
                $idSalesOrder,
38
                HeidelpayConfig::TRANSACTION_TYPE_CAPTURE,
39
                HeidelpayConfig::CAPTURE_TRANSACTION_STATUS_OK
40
            );
41
42
        if (!$heidelpayTransactionLogTransfer) {
43
            return false;
44
        }
45
46
        return true;
47
    }
48
49
    /**
50
     * @param int $idSalesOrder
51
     *
52
     * @return bool
53
     */
54
    public function isRefunded(int $idSalesOrder): bool
55
    {
56
        $heidelpayTransactionLogTransfer = $this->heidelpayRepository
57
            ->findHeidelpayTransactionLogByIdSalesOrderAndTransactionTypeAndResponseCode(
58
                $idSalesOrder,
59
                HeidelpayConfig::TRANSACTION_TYPE_REFUND,
60
                HeidelpayConfig::REFUND_TRANSACTION_STATUS_OK
61
            );
62
63
        if (!$heidelpayTransactionLogTransfer) {
64
            return false;
65
        }
66
67
        return true;
68
    }
69
70
    /**
71
     * @param int $idSalesOrder
72
     *
73
     * @return bool
74
     */
75
    public function isDebitOnRegistrationCompleted(int $idSalesOrder): bool
76
    {
77
        $heidelpayTransactionLogTransfer = $this->heidelpayRepository
78
            ->findHeidelpayTransactionLogByIdSalesOrderAndTransactionTypeAndResponseCode(
79
                $idSalesOrder,
80
                HeidelpayConfig::TRANSACTION_TYPE_EXTERNAL_RESPONSE,
81
                HeidelpayConfig::EXTERNAL_RESPONSE_TRANSACTION_STATUS_OK
82
            );
83
84
        if (!$heidelpayTransactionLogTransfer) {
85
            return false;
86
        }
87
88
        return true;
89
    }
90
}
91