Passed
Push — bugfix/eco-2800-paid-notificat... ( 786e71 )
by Aleksey
08:37
created

findPaymentCrefoPayOrderItemsByCaptureId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 1
dl 0
loc 20
rs 9.8666
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\CrefoPay\Persistence;
9
10
use ArrayObject;
11
use Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...rItemCollectionTransfer 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 Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...oCrefoPayApiLogTransfer 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 Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer;
0 ignored issues
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...
14
use Generated\Shared\Transfer\PaymentCrefoPayOrderItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...efoPayOrderItemTransfer 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...
15
use Generated\Shared\Transfer\PaymentCrefoPayTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentCrefoPayTransfer 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...
16
use Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\CrefoPay\Persist...tCrefoPayOrderItemQuery 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...
17
use Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayApiLogQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\CrefoPay\Persist...emToCrefoPayApiLogQuery 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...
18
use Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayNotificationQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\CrefoPay\Persist...efoPayNotificationQuery 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...
19
use Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\CrefoPay\Persist...SpyPaymentCrefoPayQuery 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...
20
use Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery 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...
21
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
22
use SprykerEco\Zed\CrefoPay\Persistence\Mapper\CrefoPayPersistenceMapperInterface;
23
24
/**
25
 * @method \SprykerEco\Zed\CrefoPay\Persistence\CrefoPayPersistenceFactory getFactory()
26
 */
27
class CrefoPayRepository extends AbstractRepository implements CrefoPayRepositoryInterface
28
{
29
    /**
30
     * @param int $fkSalesOrder
31
     *
32
     * @return \Generated\Shared\Transfer\PaymentCrefoPayTransfer
33
     */
34
    public function findPaymentCrefoPayByFkSalesOrder(int $fkSalesOrder): PaymentCrefoPayTransfer
35
    {
36
        $paymentCrefoPayEntity = $this->getPaymentCrefoPayQuery()
37
            ->filterByFkSalesOrder($fkSalesOrder)
38
            ->findOne();
39
40
        $paymentCrefoPayTransfer = new PaymentCrefoPayTransfer();
41
42
        if ($paymentCrefoPayEntity === null) {
43
            return $paymentCrefoPayTransfer;
44
        }
45
46
        return $this->getMapper()
47
            ->mapEntityToPaymentCrefoPayTransfer($paymentCrefoPayEntity, $paymentCrefoPayTransfer);
48
    }
49
50
    /**
51
     * @param string $crefoPayOrderId
52
     *
53
     * @return \Generated\Shared\Transfer\PaymentCrefoPayTransfer
54
     */
55
    public function findPaymentCrefoPayByCrefoPayOrderId(string $crefoPayOrderId): PaymentCrefoPayTransfer
56
    {
57
        $paymentCrefoPayEntity = $this->getPaymentCrefoPayQuery()
58
            ->filterByCrefoPayOrderId($crefoPayOrderId)
59
            ->findOne();
60
61
        $paymentCrefoPayTransfer = new PaymentCrefoPayTransfer();
62
63
        if ($paymentCrefoPayEntity === null) {
64
            return $paymentCrefoPayTransfer;
65
        }
66
67
        return $this->getMapper()
68
            ->mapEntityToPaymentCrefoPayTransfer($paymentCrefoPayEntity, $paymentCrefoPayTransfer);
69
    }
70
71
    /**
72
     * @param int $idSalesOrderItem
73
     *
74
     * @return \Generated\Shared\Transfer\PaymentCrefoPayTransfer
75
     */
76
    public function findPaymentCrefoPayByIdSalesOrderItem(int $idSalesOrderItem): PaymentCrefoPayTransfer
77
    {
78
        /** @var \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPay|null $paymentCrefoPayEntity */
79
        $paymentCrefoPayEntity = $this->getPaymentCrefoPayQuery()
80
            ->useSpyPaymentCrefoPayOrderItemQuery()
81
                ->filterByFkSalesOrderItem($idSalesOrderItem)
82
            ->endUse()
83
            ->findOne();
84
85
        $paymentCrefoPayTransfer = new PaymentCrefoPayTransfer();
86
87
        if ($paymentCrefoPayEntity === null) {
88
            return $paymentCrefoPayTransfer;
89
        }
90
91
        return $this->getMapper()
92
            ->mapEntityToPaymentCrefoPayTransfer($paymentCrefoPayEntity, $paymentCrefoPayTransfer);
93
    }
94
95
    /**
96
     * @param string $crefoPayOrderId
97
     *
98
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
99
     */
100
    public function findPaymentCrefoPayOrderItemsByCrefoPayOrderId(string $crefoPayOrderId): PaymentCrefoPayOrderItemCollectionTransfer
101
    {
102
        $query = $this->getPaymentCrefoPayOrderItemQuery();
103
        $query->useSpyPaymentCrefoPayQuery()
104
                ->filterByCrefoPayOrderId($crefoPayOrderId)
105
            ->endUse();
106
107
        $paymentCrefoPayOrderItemEntities = $query->find();
108
109
        $mapper = $this->getMapper();
110
        $result = new ArrayObject();
111
112
        foreach ($paymentCrefoPayOrderItemEntities as $paymentCrefoPayOrderItemEntity) {
113
            $paymentCrefoPayOrderItemTransfer = $mapper->mapEntityToPaymentCrefoPayOrderItemTransfer(
114
                $paymentCrefoPayOrderItemEntity,
115
                new PaymentCrefoPayOrderItemTransfer()
116
            );
117
            $result->append($paymentCrefoPayOrderItemTransfer);
118
        }
119
120
        return (new PaymentCrefoPayOrderItemCollectionTransfer())
121
            ->setCrefoPayOrderItems($result);
122
    }
123
124
    /**
125
     * @param string $captureId
126
     *
127
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
128
     */
129
    public function findPaymentCrefoPayOrderItemsByCaptureId(string $captureId): PaymentCrefoPayOrderItemCollectionTransfer
130
    {
131
        $query = $this->getPaymentCrefoPayOrderItemQuery();
132
        $query->filterByCaptureId($captureId);
133
134
        $paymentCrefoPayOrderItemEntities = $query->find();
135
136
        $mapper = $this->getMapper();
137
        $result = new ArrayObject();
138
139
        foreach ($paymentCrefoPayOrderItemEntities as $paymentCrefoPayOrderItemEntity) {
140
            $paymentCrefoPayOrderItemTransfer = $mapper->mapEntityToPaymentCrefoPayOrderItemTransfer(
141
                $paymentCrefoPayOrderItemEntity,
142
                new PaymentCrefoPayOrderItemTransfer()
143
            );
144
            $result->append($paymentCrefoPayOrderItemTransfer);
145
        }
146
147
        return (new PaymentCrefoPayOrderItemCollectionTransfer())
148
            ->setCrefoPayOrderItems($result);
149
    }
150
151
    /**
152
     * @param int[] $salesOrderItemIds
153
     *
154
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemCollectionTransfer
155
     */
156
    public function findPaymentCrefoPayOrderItemsBySalesOrderItemIds(array $salesOrderItemIds): PaymentCrefoPayOrderItemCollectionTransfer
157
    {
158
        $paymentCrefoPayOrderItemEntities = $this->getPaymentCrefoPayOrderItemQuery()
159
            ->filterByFkSalesOrderItem_In($salesOrderItemIds)
160
            ->find();
161
162
        $mapper = $this->getMapper();
163
        $result = new ArrayObject();
164
165
        foreach ($paymentCrefoPayOrderItemEntities as $paymentCrefoPayOrderItemEntity) {
166
            $paymentCrefoPayOrderItemTransfer = $mapper->mapEntityToPaymentCrefoPayOrderItemTransfer(
167
                $paymentCrefoPayOrderItemEntity,
168
                new PaymentCrefoPayOrderItemTransfer()
169
            );
170
            $result->append($paymentCrefoPayOrderItemTransfer);
171
        }
172
173
        return (new PaymentCrefoPayOrderItemCollectionTransfer())
174
            ->setCrefoPayOrderItems($result);
175
    }
176
177
    /**
178
     * @param int $idSalesOrderItem
179
     * @param string $apiLogRequestType
180
     * @param int[] $resultCodes
181
     *
182
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer
183
     */
184
    public function findPaymentCrefoPayOrderItemToCrefoPayApiLogByIdSalesOrderItemAndRequestTypeAndResultCodes(
185
        int $idSalesOrderItem,
186
        string $apiLogRequestType,
187
        array $resultCodes
188
    ): PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer {
189
        $paymentCrefoPayOrderItemToCrefoPayApiLogEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayApiLogQuery()
190
            ->useSpyPaymentCrefoPayOrderItemQuery()
191
                ->filterByFkSalesOrderItem($idSalesOrderItem)
192
            ->endUse()
193
            ->useSpyPaymentCrefoPayApiLogQuery()
194
                ->filterByRequestType($apiLogRequestType)
195
                ->filterByResultCode_In($resultCodes)
196
            ->endUse()
197
            ->findOne();
198
199
        $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer = new PaymentCrefoPayOrderItemToCrefoPayApiLogTransfer();
200
201
        if ($paymentCrefoPayOrderItemToCrefoPayApiLogEntity === null) {
202
            return $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer;
203
        }
204
205
        return $this->getMapper()
206
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayApiLogTransfer(
207
                $paymentCrefoPayOrderItemToCrefoPayApiLogEntity,
208
                $paymentCrefoPayOrderItemToCrefoPayApiLogTransfer
209
            );
210
    }
211
212
    /**
213
     * @param int $idSalesOrderItem
214
     * @param string $notificationTransactionStatus
215
     *
216
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer
217
     */
218
    public function findPaymentCrefoPayOrderItemToCrefoPayNotificationByIdSalesOrderItemAndTransactionStatus(
219
        int $idSalesOrderItem,
220
        string $notificationTransactionStatus
221
    ): PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer {
222
        $paymentCrefoPayOrderItemToCrefoPayNotificationEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery()
223
            ->useSpyPaymentCrefoPayOrderItemQuery()
224
                ->filterByFkSalesOrderItem($idSalesOrderItem)
225
            ->endUse()
226
            ->useSpyPaymentCrefoPayNotificationQuery()
227
                ->filterByTransactionStatus($notificationTransactionStatus)
228
            ->endUse()
229
            ->findOne();
230
231
        $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer = new PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer();
232
233
        if ($paymentCrefoPayOrderItemToCrefoPayNotificationEntity === null) {
234
            return $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer;
235
        }
236
237
        return $this->getMapper()
238
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayNotificationTransfer(
239
                $paymentCrefoPayOrderItemToCrefoPayNotificationEntity,
240
                $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer
241
            );
242
    }
243
244
    /**
245
     * @param int $idSalesOrderItem
246
     * @param string $notificationOrderStatus
247
     *
248
     * @return \Generated\Shared\Transfer\PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer
249
     */
250
    public function findPaymentCrefoPayOrderItemToCrefoPayNotificationByIdSalesOrderItemAndOrderStatus(
251
        int $idSalesOrderItem,
252
        string $notificationOrderStatus
253
    ): PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer {
254
        $paymentCrefoPayOrderItemToCrefoPayNotificationEntity = $this->getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery()
255
            ->useSpyPaymentCrefoPayOrderItemQuery()
256
                ->filterByFkSalesOrderItem($idSalesOrderItem)
257
            ->endUse()
258
            ->useSpyPaymentCrefoPayNotificationQuery()
259
                ->filterByOrderStatus($notificationOrderStatus)
260
            ->endUse()
261
            ->findOne();
262
263
        $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer = new PaymentCrefoPayOrderItemToCrefoPayNotificationTransfer();
264
265
        if ($paymentCrefoPayOrderItemToCrefoPayNotificationEntity === null) {
266
            return $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer;
267
        }
268
269
        return $this->getMapper()
270
            ->mapEntityToPaymentCrefoPayOrderItemToCrefoPayNotificationTransfer(
271
                $paymentCrefoPayOrderItemToCrefoPayNotificationEntity,
272
                $paymentCrefoPayOrderItemToCrefoPayNotificationTransfer
273
            );
274
    }
275
276
    /**
277
     * @return \SprykerEco\Zed\CrefoPay\Persistence\Mapper\CrefoPayPersistenceMapperInterface
278
     */
279
    protected function getMapper(): CrefoPayPersistenceMapperInterface
280
    {
281
        return $this->getFactory()->createCrefoPayPersistenceMapper();
282
    }
283
284
    /**
285
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayQuery
286
     */
287
    protected function getPaymentCrefoPayQuery(): SpyPaymentCrefoPayQuery
288
    {
289
        return $this->getFactory()->createPaymentCrefoPayQuery();
290
    }
291
292
    /**
293
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemQuery
294
     */
295
    protected function getPaymentCrefoPayOrderItemQuery(): SpyPaymentCrefoPayOrderItemQuery
296
    {
297
        return $this->getFactory()->createPaymentCrefoPayOrderItemQuery();
298
    }
299
300
    /**
301
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayApiLogQuery
302
     */
303
    protected function getPaymentCrefoPayOrderItemToCrefoPayApiLogQuery(): SpyPaymentCrefoPayOrderItemToCrefoPayApiLogQuery
304
    {
305
        return $this->getFactory()->createPaymentCrefoPayOrderItemToCrefoPayApiLogQuery();
306
    }
307
308
    /**
309
     * @return \Orm\Zed\CrefoPay\Persistence\SpyPaymentCrefoPayOrderItemToCrefoPayNotificationQuery
310
     */
311
    protected function getPaymentCrefoPayOrderItemToCrefoPayNotificationQuery(): SpyPaymentCrefoPayOrderItemToCrefoPayNotificationQuery
312
    {
313
        return $this->getFactory()->createPaymentCrefoPayOrderItemToCrefoPayNotificationQuery();
314
    }
315
316
    /**
317
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItemQuery
318
     */
319
    protected function getSalesOrderItemQuery(): SpySalesOrderItemQuery
320
    {
321
        return $this->getFactory()->createSpySalesOrderItemQuery();
322
    }
323
}
324