Passed
Pull Request — master (#74)
by oleksandr
04:18
created

createTransactionStatusLogsByOrderIds()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 15
rs 9.9666
cc 2
nc 2
nop 1
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\Persistence;
9
10
use ArrayObject;
11
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...
12
use Generated\Shared\Transfer\PaymentDetailTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentDetailTransfer 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\PaymentPayoneOrderItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PayoneOrderItemTransfer 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\PayoneApiLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneApiLogTransfer 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\PayoneOrderItemFilterTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...OrderItemFilterTransfer 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 Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ntLogCollectionTransfer 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 Generated\Shared\Transfer\PayonePaymentLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayonePaymentLogTransfer 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 Generated\Shared\Transfer\PayonePaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayonePaymentTransfer 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\Payone\Persistence\SpyPaymentPayoneApiCallLogQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persisten...ntPayoneApiCallLogQuery 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\Payone\Persistence\SpyPaymentPayoneApiLogQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persisten...aymentPayoneApiLogQuery 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 Orm\Zed\Payone\Persistence\SpyPaymentPayoneOrderItemQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persisten...entPayoneOrderItemQuery 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...
22
use Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery 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...
23
use Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogOrderItemQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persisten...StatusLogOrderItemQuery 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...
24
use Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persisten...ansactionStatusLogQuery 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...
25
use Propel\Runtime\ActiveQuery\Criteria;
26
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
27
use SprykerEco\Shared\Payone\PayoneApiConstants;
28
29
/**
30
 * @method \SprykerEco\Zed\Payone\Persistence\PayonePersistenceFactory getFactory()
31
 */
32
class PayoneRepository extends AbstractRepository implements PayoneRepositoryInterface
33
{
34
    /**
35
     * @var string
36
     */
37
    protected const LOG_TYPE_API_LOG = 'SpyPaymentPayoneApiLog';
38
39
    /**
40
     * @var string
41
     */
42
    protected const LOG_TYPE_TRANSACTION_STATUS_LOG = 'SpyPaymentPayoneTransactionStatusLog';
43
44
    /**
45
     * @param \Generated\Shared\Transfer\PayoneOrderItemFilterTransfer $payoneOrderItemFilerTransfer
46
     *
47
     * @return array<\Generated\Shared\Transfer\PaymentPayoneOrderItemTransfer>
48
     */
49
    public function findPaymentPayoneOrderItemByFilter(PayoneOrderItemFilterTransfer $payoneOrderItemFilerTransfer): array
50
    {
51
        $paymentPayoneOrderItemQuery = $this->getFactory()->createPaymentPayoneOrderItemQuery();
52
        $paymentPayoneOrderItemQuery = $this->setPayoneOrderItemFilters(
53
            $paymentPayoneOrderItemQuery,
54
            $payoneOrderItemFilerTransfer,
55
        );
56
57
        $paymentPayoneOrderItemEntities = $paymentPayoneOrderItemQuery->find();
58
        $paymentPayoneOrderItemTransfers = [];
59
60
        foreach ($paymentPayoneOrderItemEntities as $paymentPayoneOrderItemEntity) {
61
            $paymentPayoneOrderItemTransfers[] = $this->getFactory()
62
                ->createPayonePersistenceMapper()
63
                ->mapEntityToPaymentPayoneOrderItemTransfer($paymentPayoneOrderItemEntity, new PaymentPayoneOrderItemTransfer());
64
        }
65
66
        return $paymentPayoneOrderItemTransfers;
67
    }
68
69
    /**
70
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
71
     *
72
     * @return \Generated\Shared\Transfer\PayonePaymentTransfer
73
     */
74
    public function getPayonePaymentByOrder(OrderTransfer $orderTransfer): PayonePaymentTransfer
75
    {
76
        $paymentPayoneEntity = $this->createPaymentPayoneQueryByOrderId($orderTransfer->getIdSalesOrderOrFail())->findOne();
77
78
        return $this
79
            ->getFactory()
80
            ->createPayonePersistenceMapper()
81
            ->mapPaymentPayoneEntityToPayonePaymentTransfer($paymentPayoneEntity, new PayonePaymentTransfer());
82
    }
83
84
    /**
85
     * @param int $idOrder
86
     *
87
     * @return \Generated\Shared\Transfer\PaymentDetailTransfer
88
     */
89
    public function getPaymentDetail(int $idOrder): PaymentDetailTransfer
90
    {
91
        $paymentPayoneEntity = $this->createPaymentPayoneQueryByOrderId($idOrder)->findOne();
92
        $paymentPayoneDetailEntity = $paymentPayoneEntity->getSpyPaymentPayoneDetail();
93
94
        return $this->getFactory()->createPayonePersistenceMapper()->mapPaymentPayoneDetailToPaymentDetailTransfer($paymentPayoneDetailEntity);
95
    }
96
97
    /**
98
     * Gets payment logs (both api and transaction status) for specific orders in chronological order.
99
     *
100
     * @param \ArrayObject<array-key, \Generated\Shared\Transfer\OrderTransfer> $orderTransfers
101
     *
102
     * @return \Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer
103
     */
104
    public function getPaymentLogs(ArrayObject $orderTransfers): PayonePaymentLogCollectionTransfer
105
    {
106
        $paymentPayoneApiLogEntityCollection = $this->createPaymentPayoneApiLogQueryByOrderIds($orderTransfers)->find()->getData();
107
108
        $paymentPayoneTransactionStatusLogEntityCollection = $this->createPaymentPayoneTransactionStatusLogQueryByOrderIds($orderTransfers)->find()->getData();
109
110
        $payonePaymentLogTransferList = [];
111
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $paymentPayoneApiLogEntity */
112
        foreach ($paymentPayoneApiLogEntityCollection as $paymentPayoneApiLogEntity) {
113
            /** @var \DateTime $apiLogCreatedAtDateTime */
114
            $apiLogCreatedAtDateTime = $paymentPayoneApiLogEntity->getCreatedAt();
115
            $key = $apiLogCreatedAtDateTime->format('Y-m-d\TH:i:s\Z') . 'a' . $paymentPayoneApiLogEntity->getIdPaymentPayoneApiLog();
116
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
117
            $payonePaymentLogTransfer->fromArray($paymentPayoneApiLogEntity->toArray(), true);
118
            $payonePaymentLogTransfer->setLogType(static::LOG_TYPE_API_LOG);
119
            $payonePaymentLogTransferList[$key] = $payonePaymentLogTransfer;
120
        }
121
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLog $paymentPayoneTransactionStatusLogEntity */
122
        foreach ($paymentPayoneTransactionStatusLogEntityCollection as $paymentPayoneTransactionStatusLogEntity) {
123
            /** @var \DateTime $transactionStatusLogDateTime */
124
            $transactionStatusLogDateTime = $paymentPayoneTransactionStatusLogEntity->getCreatedAt();
125
            $key = $transactionStatusLogDateTime->format('Y-m-d\TH:i:s\Z') . 't' . $paymentPayoneTransactionStatusLogEntity->getIdPaymentPayoneTransactionStatusLog();
126
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
127
            $payonePaymentLogTransfer->fromArray($paymentPayoneTransactionStatusLogEntity->toArray(), true);
128
            $payonePaymentLogTransfer->setLogType(static::LOG_TYPE_TRANSACTION_STATUS_LOG);
129
            $payonePaymentLogTransferList[$key] = $payonePaymentLogTransfer;
130
        }
131
132
        ksort($payonePaymentLogTransferList);
133
134
        $payonePaymentLogCollectionTransfer = new PayonePaymentLogCollectionTransfer();
135
136
        foreach ($payonePaymentLogTransferList as $payonePaymentLogTransfer) {
137
            $payonePaymentLogCollectionTransfer->addPaymentLog($payonePaymentLogTransfer);
138
        }
139
140
        return $payonePaymentLogCollectionTransfer;
141
    }
142
143
    /**
144
     * @param int $idSalesOrder
145
     *
146
     * @return \Generated\Shared\Transfer\PayoneApiLogTransfer|null
147
     */
148
    public function findLastApiLogByOrderId(int $idSalesOrder): ?PayoneApiLogTransfer
149
    {
150
        $paymentPayoneApiLogEntity = $this->getFactory()->createPaymentPayoneApiLogQuery()
151
            ->useSpyPaymentPayoneQuery()
152
                ->filterByFkSalesOrder($idSalesOrder)
153
            ->endUse()
154
            ->orderByCreatedAt(Criteria::DESC)
155
            ->orderByIdPaymentPayoneApiLog(Criteria::DESC)
156
            ->findOne();
157
158
        if (!$paymentPayoneApiLogEntity) {
159
            return null;
160
        }
161
162
        $apiLogTransfer = new PayoneApiLogTransfer();
163
        $apiLogTransfer->fromArray($paymentPayoneApiLogEntity->toArray(), true);
164
165
        return $apiLogTransfer;
166
    }
167
168
    /**
169
     * @param int $idOrder
170
     *
171
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
172
     */
173
    public function createPaymentPayoneQueryByOrderId(int $idOrder): SpyPaymentPayoneQuery
174
    {
175
        $query = $this->getFactory()->createPaymentPayoneQuery();
176
        $query->findByFkSalesOrder($idOrder);
177
178
        return $query;
179
    }
180
181
    /**
182
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneOrderItemQuery $paymentPayoneOrderItemQuery
183
     * @param \Generated\Shared\Transfer\PayoneOrderItemFilterTransfer $payoneOrderItemFilerTransfer
184
     *
185
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneOrderItemQuery
186
     */
187
    protected function setPayoneOrderItemFilters(
188
        SpyPaymentPayoneOrderItemQuery $paymentPayoneOrderItemQuery,
189
        PayoneOrderItemFilterTransfer $payoneOrderItemFilerTransfer
190
    ): SpyPaymentPayoneOrderItemQuery {
191
        if ($payoneOrderItemFilerTransfer->getIdSalesOrder()) {
192
            $paymentPayoneOrderItemQuery
193
                ->useSpyPaymentPayoneQuery()
194
                    ->filterByFkSalesOrder($payoneOrderItemFilerTransfer->getIdSalesOrder())
195
                ->endUse();
196
        }
197
198
        if (count($payoneOrderItemFilerTransfer->getSalesOrderItemIds())) {
199
            $paymentPayoneOrderItemQuery->filterByFkSalesOrderItem_In(
200
                $payoneOrderItemFilerTransfer->getSalesOrderItemIds(),
201
            );
202
        }
203
204
        return $paymentPayoneOrderItemQuery;
205
    }
206
207
    /**
208
     * @param \ArrayObject<array-key, \Generated\Shared\Transfer\OrderTransfer> $orderTransfers
209
     *
210
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLogQuery
211
     */
212
    protected function createPaymentPayoneApiLogQueryByOrderIds($orderTransfers): SpyPaymentPayoneApiLogQuery
213
    {
214
        $ids = [];
215
        foreach ($orderTransfers as $orderTransfer) {
216
            $ids[] = $orderTransfer->getIdSalesOrder();
217
        }
218
219
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLogQuery $query */
220
        $query = $this->getFactory()->createPaymentPayoneApiLogQuery()
221
            ->useSpyPaymentPayoneQuery()
222
                ->filterByFkSalesOrder($ids, Criteria::IN)
223
            ->endUse()
224
            ->orderByCreatedAt();
225
226
        return $query;
227
    }
228
229
    /**
230
     * @param \ArrayObject<array-key, \Generated\Shared\Transfer\OrderTransfer> $orderTransfers
231
     *
232
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogQuery
233
     */
234
    protected function createPaymentPayoneTransactionStatusLogQueryByOrderIds(ArrayObject $orderTransfers): SpyPaymentPayoneTransactionStatusLogQuery
235
    {
236
        $ids = [];
237
        foreach ($orderTransfers as $orderTransfer) {
238
            $ids[] = $orderTransfer->getIdSalesOrder();
239
        }
240
241
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogQuery $query */
242
        $query = $this->getFactory()->createPaymentPayoneTransactionStatusLogQuery()
243
            ->useSpyPaymentPayoneQuery()
244
                ->filterByFkSalesOrder($ids, Criteria::IN)
245
            ->endUse()
246
            ->orderByCreatedAt();
247
248
        return $query;
249
    }
250
251
    /**
252
     * @param int $transactionId
253
     *
254
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLogQuery
255
     */
256
    public function createCurrentSequenceNumberQuery(int $transactionId): SpyPaymentPayoneApiLogQuery
257
    {
258
        $query = $this->getFactory()->createPaymentPayoneApiLogQuery();
259
        $query->filterByTransactionId($transactionId)
260
            ->orderBySequenceNumber(Criteria::DESC);
261
262
        return $query;
263
    }
264
265
    /**
266
     * @param int $transactionId
267
     *
268
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
269
     */
270
    public function createPaymentByTransactionIdQuery($transactionId): SpyPaymentPayoneQuery
271
    {
272
        $query = $this->getFactory()->createPaymentPayoneQuery();
273
        $query->filterByTransactionId($transactionId);
274
275
        return $query;
276
    }
277
278
    /**
279
     * @param string|null $invoiceTitle
280
     * @param int|null $customerId
281
     *
282
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
283
     */
284
    public function createPaymentByInvoiceTitleAndCustomerIdQuery($invoiceTitle, $customerId): SpyPaymentPayoneQuery
285
    {
286
        $query = $this->getFactory()->createPaymentPayoneQuery();
287
        $query->useSpySalesOrderQuery()
288
            ->filterByFkCustomer($customerId)
289
            ->endUse()
290
            ->useSpyPaymentPayoneDetailQuery()
291
            ->filterByInvoiceTitle($invoiceTitle)
292
            ->endUse()
293
            ->useSpyPaymentPayoneApiLogQuery()
294
            ->filterByStatus(PayoneApiConstants::RESPONSE_TYPE_APPROVED)
295
            ->endUse();
296
297
        return $query;
298
    }
299
300
    /**
301
     * @param string|null $fileReference
302
     * @param int|null $customerId
303
     *
304
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
305
     */
306
    public function createPaymentByFileReferenceAndCustomerIdQuery($fileReference, $customerId): SpyPaymentPayoneQuery
307
    {
308
        $query = $this->getFactory()->createPaymentPayoneQuery();
309
        $query->useSpySalesOrderQuery()
310
            ->filterByFkCustomer($customerId)
311
            ->endUse()
312
            ->useSpyPaymentPayoneDetailQuery()
313
            ->filterByMandateIdentification($fileReference)
314
            ->endUse()
315
            ->useSpyPaymentPayoneApiLogQuery()
316
            ->filterByStatus(PayoneApiConstants::RESPONSE_TYPE_APPROVED)
317
            ->endUse();
318
319
        return $query;
320
    }
321
322
    /**
323
     * @param int $fkPayment
324
     * @param string $requestType
325
     *
326
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLogQuery
327
     */
328
    public function createApiLogByPaymentAndRequestTypeQuery($fkPayment, $requestType): SpyPaymentPayoneApiLogQuery
329
    {
330
        $query = $this->getFactory()->createPaymentPayoneApiLogQuery();
331
        $query->filterByFkPaymentPayone($fkPayment)
332
            ->filterByRequest($requestType);
333
334
        return $query;
335
    }
336
337
    /**
338
     * @param int $idOrder
339
     *
340
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
341
     */
342
    public function createPaymentByOrderId($idOrder): SpyPaymentPayoneQuery
343
    {
344
        $query = $this->getFactory()->createPaymentPayoneQuery();
345
        $query->findByFkSalesOrder($idOrder);
346
347
        return $query;
348
    }
349
350
    /**
351
     * @param int $idOrder
352
     * @param string $request
353
     *
354
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLogQuery
355
     */
356
    public function createApiLogsByOrderIdAndRequest($idOrder, $request): SpyPaymentPayoneApiLogQuery
357
    {
358
        $query = $this->getFactory()->createPaymentPayoneApiLogQuery()
359
            ->useSpyPaymentPayoneQuery()
360
            ->filterByFkSalesOrder($idOrder)
361
            ->endUse()
362
            ->filterByRequest($request)
363
            ->orderByCreatedAt(Criteria::DESC) //TODO: Index?
364
            ->orderByIdPaymentPayoneApiLog(Criteria::DESC);
365
366
        return $query;
367
    }
368
369
    /**
370
     * @param int $orderId
371
     *
372
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
373
     */
374
    public function createPaymentById($orderId): SpyPaymentPayoneQuery
375
    {
376
        $query = $this->getFactory()->createPaymentPayoneQuery();
377
        $query->findByFkSalesOrder($orderId);
378
379
        return $query;
380
    }
381
382
    /**
383
     * @param int $idSalesOrder
384
     *
385
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogQuery
386
     */
387
    public function createTransactionStatusLogsBySalesOrder($idSalesOrder): SpyPaymentPayoneTransactionStatusLogQuery
388
    {
389
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogQuery $query */
390
        $query = $this->getFactory()->createPaymentPayoneTransactionStatusLogQuery()
391
            ->useSpyPaymentPayoneQuery()
392
            ->filterByFkSalesOrder($idSalesOrder)
393
            ->endUse()
394
            ->orderByCreatedAt();
395
396
        return $query;
397
    }
398
399
    /**
400
     * @param int $idSalesOrderItem
401
     * @param array $ids
402
     *
403
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogOrderItemQuery
404
     */
405
    public function createTransactionStatusLogOrderItemsByLogIds($idSalesOrderItem, $ids): SpyPaymentPayoneTransactionStatusLogOrderItemQuery
406
    {
407
        $relations = $this->getFactory()->createPaymentPayoneTransactionStatusLogOrderItemQuery()
408
            ->filterByIdPaymentPayoneTransactionStatusLog($ids, Criteria::IN)
409
            ->filterByIdSalesOrderItem($idSalesOrderItem);
410
411
        return $relations;
412
    }
413
414
    /**
415
     * @param int $idSalesOrder
416
     *
417
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLogQuery
418
     */
419
    public function createLastApiLogsByOrderId($idSalesOrder): SpyPaymentPayoneApiLogQuery
420
    {
421
        $query = $this->getFactory()->createPaymentPayoneApiLogQuery()
422
            ->useSpyPaymentPayoneQuery()
423
            ->filterByFkSalesOrder($idSalesOrder)
424
            ->endUse()
425
            ->orderByCreatedAt(Criteria::DESC)
426
            ->orderByIdPaymentPayoneApiLog(Criteria::DESC);
427
428
        return $query;
429
    }
430
431
    /**
432
     * @param \Propel\Runtime\Collection\ObjectCollection $orders
433
     *
434
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLogQuery
435
     */
436
    public function createApiLogsByOrderIds($orders): SpyPaymentPayoneApiLogQuery
437
    {
438
        $ids = [];
439
        /** @var \Orm\Zed\Sales\Persistence\SpySalesOrder $order */
440
        foreach ($orders as $order) {
441
            $ids[] = $order->getIdSalesOrder();
442
        }
443
444
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLogQuery $query */
445
        $query = $this->getFactory()->createPaymentPayoneApiLogQuery()
446
            ->useSpyPaymentPayoneQuery()
447
            ->filterByFkSalesOrder($ids, Criteria::IN)
448
            ->endUse()
449
            ->orderByCreatedAt();
450
451
        return $query;
452
    }
453
454
    /**
455
     * @param array<\Orm\Zed\Sales\Persistence\SpySalesOrder> $orders
456
     *
457
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogQuery
458
     */
459
    public function createTransactionStatusLogsByOrderIds($orders): SpyPaymentPayoneTransactionStatusLogQuery
460
    {
461
        $ids = [];
462
        foreach ($orders as $order) {
463
            $ids[] = $order->getIdSalesOrder();
464
        }
465
466
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLogQuery $query */
467
        $query = $this->getFactory()->createPaymentPayoneTransactionStatusLogQuery()
468
            ->useSpyPaymentPayoneQuery()
469
            ->filterByFkSalesOrder($ids, Criteria::IN)
470
            ->endUse()
471
            ->orderByCreatedAt();
472
473
        return $query;
474
    }
475
476
    /**
477
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiCallLogQuery
478
     */
479
    public function createApiCallLog(): SpyPaymentPayoneApiCallLogQuery
480
    {
481
        return $this->getFactory()->createPaymentPayoneApiCallLogQuery();
482
    }
483
}
484