TransactionStatusLog::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Braintree\Business\Log;
9
10
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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 SprykerEco\Zed\Braintree\Business\Payment\Method\ApiConstants;
12
use SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface;
13
14
class TransactionStatusLog implements TransactionStatusLogInterface
15
{
16
    /**
17
     * @var \SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface
18
     */
19
    protected $repository;
20
21
    /**
22
     * @param \SprykerEco\Zed\Braintree\Persistence\BraintreeRepositoryInterface $repository
23
     */
24
    public function __construct(BraintreeRepositoryInterface $repository)
25
    {
26
        $this->repository = $repository;
27
    }
28
29
    /**
30
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
31
     *
32
     * @return bool
33
     */
34
    public function isAuthorizationApproved(OrderTransfer $orderTransfer)
35
    {
36
        return $this->hasTransactionStatusLog(
37
            $orderTransfer,
38
            ApiConstants::TRANSACTION_CODE_AUTHORIZE,
39
            ApiConstants::STATUS_CODE_AUTHORIZE
40
        );
41
    }
42
43
    /**
44
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
45
     *
46
     * @return bool
47
     */
48
    public function isReversalApproved(OrderTransfer $orderTransfer)
49
    {
50
        return $this->hasTransactionStatusLog(
51
            $orderTransfer,
52
            ApiConstants::TRANSACTION_CODE_REVERSAL,
53
            ApiConstants::STATUS_CODE_REVERSAL
54
        );
55
    }
56
57
    /**
58
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
59
     *
60
     * @return bool
61
     */
62
    public function isCaptureApproved(OrderTransfer $orderTransfer)
63
    {
64
        if ($this->hasTransactionStatusLog(
65
            $orderTransfer,
66
            ApiConstants::TRANSACTION_CODE_CAPTURE,
67
            ApiConstants::STATUS_CODE_CAPTURE
68
        )) {
69
            return true;
70
        }
71
72
        return $this->hasTransactionStatusLog(
73
            $orderTransfer,
74
            ApiConstants::TRANSACTION_CODE_CAPTURE,
75
            ApiConstants::STATUS_CODE_CAPTURE_SUBMITTED
76
        );
77
    }
78
79
    /**
80
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
81
     *
82
     * @return bool
83
     */
84
    public function isRefundApproved(OrderTransfer $orderTransfer)
85
    {
86
        return $this->hasTransactionStatusLog(
87
            $orderTransfer,
88
            ApiConstants::TRANSACTION_CODE_REFUND,
89
            [ApiConstants::STATUS_CODE_REVERSAL, ApiConstants::STATUS_CODE_REFUND]
90
        );
91
    }
92
93
    /**
94
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
95
     * @param string $transactionCode
96
     * @param string|array $statusCode
97
     *
98
     * @return bool
99
     */
100
    protected function hasTransactionStatusLog(OrderTransfer $orderTransfer, $transactionCode, $statusCode): bool
101
    {
102
        $idSalesOrder = $orderTransfer->getIdSalesOrder();
103
104
        return $this->repository
105
            ->isSucceededPaymentBraintreeTransactionStatusLogQueryExistBySalesOrderIdAndTransactionCode(
106
                $idSalesOrder,
107
                $transactionCode,
108
                $statusCode
109
            );
110
    }
111
}
112