ApiLogFinder::isRefundApproved()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Business\ApiLog;
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 Orm\Zed\Payone\Persistence\SpyPaymentPayone;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayone 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 Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog 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...
13
use SprykerEco\Shared\Payone\PayoneApiConstants;
14
use SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface;
15
16
class ApiLogFinder implements ApiLogFinderInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface
20
     */
21
    private $queryContainer;
22
23
    /**
24
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface $queryContainer
25
     */
26
    public function __construct(PayoneQueryContainerInterface $queryContainer)
27
    {
28
        $this->queryContainer = $queryContainer;
29
    }
30
31
    /**
32
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
33
     *
34
     * @return bool
35
     */
36
    public function isPreAuthorizationApproved(OrderTransfer $orderTransfer): bool
37
    {
38
        return $this->hasApiLogStatus(
39
            $orderTransfer,
40
            PayoneApiConstants::REQUEST_TYPE_PREAUTHORIZATION,
41
            PayoneApiConstants::RESPONSE_TYPE_APPROVED
42
        );
43
    }
44
45
    /**
46
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
47
     *
48
     * @return bool
49
     */
50
    public function isPreAuthorizationRedirect(OrderTransfer $orderTransfer): bool
51
    {
52
        return $this->hasApiLogStatus(
53
            $orderTransfer,
54
            PayoneApiConstants::REQUEST_TYPE_PREAUTHORIZATION,
55
            PayoneApiConstants::RESPONSE_TYPE_REDIRECT
56
        );
57
    }
58
59
    /**
60
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
61
     *
62
     * @return bool
63
     */
64
    public function isPreAuthorizationError(OrderTransfer $orderTransfer): bool
65
    {
66
        return $this->hasApiLogStatus(
67
            $orderTransfer,
68
            PayoneApiConstants::REQUEST_TYPE_PREAUTHORIZATION,
69
            PayoneApiConstants::RESPONSE_TYPE_ERROR
70
        ) || $this->hasApiLogStatus(
71
            $orderTransfer,
72
            PayoneApiConstants::REQUEST_TYPE_PREAUTHORIZATION,
73
            PayoneApiConstants::RESPONSE_TYPE_TIMEOUT
74
        );
75
    }
76
77
    /**
78
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
79
     *
80
     * @return bool
81
     */
82
    public function isAuthorizationApproved(OrderTransfer $orderTransfer): bool
83
    {
84
        return $this->hasApiLogStatus(
85
            $orderTransfer,
86
            PayoneApiConstants::REQUEST_TYPE_AUTHORIZATION,
87
            PayoneApiConstants::RESPONSE_TYPE_APPROVED
88
        );
89
    }
90
91
    /**
92
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
93
     *
94
     * @return bool
95
     */
96
    public function isAuthorizationRedirect(OrderTransfer $orderTransfer): bool
97
    {
98
        return $this->hasApiLogStatus(
99
            $orderTransfer,
100
            PayoneApiConstants::REQUEST_TYPE_AUTHORIZATION,
101
            PayoneApiConstants::RESPONSE_TYPE_REDIRECT
102
        );
103
    }
104
105
    /**
106
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
107
     *
108
     * @return bool
109
     */
110
    public function isAuthorizationError(OrderTransfer $orderTransfer): bool
111
    {
112
        return $this->hasApiLogStatus(
113
            $orderTransfer,
114
            PayoneApiConstants::REQUEST_TYPE_AUTHORIZATION,
115
            PayoneApiConstants::RESPONSE_TYPE_ERROR
116
        );
117
    }
118
119
    /**
120
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
121
     *
122
     * @return bool
123
     */
124
    public function isCaptureApproved(OrderTransfer $orderTransfer): bool
125
    {
126
        return $this->hasApiLogStatus(
127
            $orderTransfer,
128
            PayoneApiConstants::REQUEST_TYPE_CAPTURE,
129
            PayoneApiConstants::RESPONSE_TYPE_APPROVED
130
        );
131
    }
132
133
    /**
134
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
135
     *
136
     * @return bool
137
     */
138
    public function isCaptureError(OrderTransfer $orderTransfer): bool
139
    {
140
        return $this->hasApiLogStatus(
141
            $orderTransfer,
142
            PayoneApiConstants::REQUEST_TYPE_CAPTURE,
143
            PayoneApiConstants::RESPONSE_TYPE_ERROR
144
        );
145
    }
146
147
    /**
148
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
149
     *
150
     * @return bool
151
     */
152
    public function isRefundApproved(OrderTransfer $orderTransfer): bool
153
    {
154
        return $this->hasApiLogStatus(
155
            $orderTransfer,
156
            PayoneApiConstants::REQUEST_TYPE_REFUND,
157
            PayoneApiConstants::RESPONSE_TYPE_APPROVED
158
        );
159
    }
160
161
    /**
162
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
163
     *
164
     * @return bool
165
     */
166
    public function isRefundError(OrderTransfer $orderTransfer): bool
167
    {
168
        return $this->hasApiLogStatus(
169
            $orderTransfer,
170
            PayoneApiConstants::REQUEST_TYPE_REFUND,
171
            PayoneApiConstants::RESPONSE_TYPE_ERROR
172
        );
173
    }
174
175
    /**
176
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
177
     * @param string $request Relevant request
178
     * @param string $status Expected status
179
     *
180
     * @return bool
181
     */
182
    protected function hasApiLogStatus(OrderTransfer $orderTransfer, string $request, string $status): bool
183
    {
184
        $idSalesOrder = $orderTransfer->getIdSalesOrder();
185
        $apiLog = $this->queryContainer->createApiLogsByOrderIdAndRequest($idSalesOrder, $request)->filterByStatus($status)->findOne();
186
187
        if ($apiLog === null) {
188
            return false;
189
        }
190
191
        return $apiLog->getStatus() === $status;
192
    }
193
194
    /**
195
     * @param int $transactionId
196
     *
197
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
198
     */
199
    protected function findPaymentByTransactionId(int $transactionId): SpyPaymentPayone
200
    {
201
        return $this->queryContainer->createPaymentByTransactionIdQuery($transactionId)->findOne();
202
    }
203
204
    /**
205
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
206
     *
207
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
208
     */
209
    protected function findPaymentByOrder(OrderTransfer $orderTransfer): SpyPaymentPayone
210
    {
211
        return $this->queryContainer->createPaymentByOrderId($orderTransfer->getIdSalesOrder())->findOne();
212
    }
213
214
    /**
215
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $payment
216
     * @param string $authorizationType
217
     *
218
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog
219
     */
220
    protected function findApiLog(SpyPaymentPayone $payment, string $authorizationType): SpyPaymentPayoneApiLog
221
    {
222
        return $this->queryContainer->createApiLogByPaymentAndRequestTypeQuery(
223
            $payment->getPrimaryKey(),
224
            $authorizationType
225
        )->findOne();
226
    }
227
}
228