HeidelpayRepository::getPaymentHeidelpayQuery()   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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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\Heidelpay\Persistence;
9
10
use Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer;
11
use Generated\Shared\Transfer\HeidelpayNotificationCollectionTransfer;
12
use Generated\Shared\Transfer\HeidelpayNotificationTransfer;
13
use Generated\Shared\Transfer\HeidelpayPaymentTransfer;
14
use Generated\Shared\Transfer\HeidelpayTransactionLogTransfer;
15
use Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayDirectDebitRegistrationQuery;
16
use Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayNotificationQuery;
17
use Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayQuery;
18
use Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayTransactionLogQuery;
19
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
20
use Spryker\Zed\PropelOrm\Business\Runtime\ActiveQuery\Criteria;
21
use SprykerEco\Zed\Heidelpay\Persistence\Propel\Mapper\HeidelpayPersistenceMapper;
22
23
/**
24
 * @method \SprykerEco\Zed\Heidelpay\Persistence\HeidelpayPersistenceFactory getFactory()
25
 */
26
class HeidelpayRepository extends AbstractRepository implements HeidelpayRepositoryInterface
27
{
28
    /**
29
     * @param int $idSalesOrder
30
     *
31
     * @return \Generated\Shared\Transfer\HeidelpayPaymentTransfer|null
32
     */
33
    public function findHeidelpayPaymentByIdSalesOrder(int $idSalesOrder): ?HeidelpayPaymentTransfer
34
    {
35
        $paymentHeidelpayEntity = $this->getPaymentHeidelpayQuery()
36
            ->filterByFkSalesOrder($idSalesOrder)
37
            ->findOne();
38
39
        if ($paymentHeidelpayEntity === null) {
40
            return null;
41
        }
42
43
        return $this->getMapper()
44
            ->mapEntityToHeidelpayPaymentTransfer(
45
                $paymentHeidelpayEntity,
46
                new HeidelpayPaymentTransfer()
47
            );
48
    }
49
50
    /**
51
     * @param string $uniqueId
52
     *
53
     * @return \Generated\Shared\Transfer\HeidelpayNotificationTransfer|null
54
     */
55
    public function findPaymentHeidelpayNotificationByUniqueId(string $uniqueId): ?HeidelpayNotificationTransfer
56
    {
57
        $paymentHeidelpayNotification = $this->getPaymentHeidelpayNotificationQuery()
58
            ->filterByUniqueId($uniqueId)
59
            ->findOne();
60
61
        if ($paymentHeidelpayNotification === null) {
62
            return null;
63
        }
64
65
        return $this->getMapper()
66
            ->mapEntityToHeidelpayNotificationTransfer(
67
                $paymentHeidelpayNotification,
68
                new HeidelpayNotificationTransfer()
69
            );
70
    }
71
72
    /**
73
     * @param string $transactionId
74
     * @param string $paymentCode
75
     *
76
     * @return \Generated\Shared\Transfer\HeidelpayNotificationCollectionTransfer
77
     */
78
    public function getPaymentHeidelpayNotificationCollectionByTransactionIdAndPaymentCode(
79
        string $transactionId,
80
        string $paymentCode
81
    ): HeidelpayNotificationCollectionTransfer {
82
        $paymentHeidelpayNotification = $this->getPaymentHeidelpayNotificationQuery()
83
            ->filterByTransactionId($transactionId)
84
            ->filterByPaymentCode($paymentCode)
85
            ->find();
86
87
        return $this->getMapper()
88
            ->mapNotificationEntitiesToHeidelpayNotificationCollection(
89
                $paymentHeidelpayNotification,
90
                new HeidelpayNotificationCollectionTransfer()
91
            );
92
    }
93
94
    /**
95
     * @param string $registrationUniqueId
96
     *
97
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer|null
98
     */
99
    public function findHeidelpayDirectDebitRegistrationByRegistrationUniqueId(
100
        string $registrationUniqueId
101
    ): ?HeidelpayDirectDebitRegistrationTransfer {
102
        $paymentHeidelpayDirectDebitRegistrationEntity = $this->getPaymentHeidelpayDirectDebitRegistrationQuery()
103
            ->filterByRegistrationUniqueId($registrationUniqueId)
104
            ->findOne();
105
106
        if ($paymentHeidelpayDirectDebitRegistrationEntity === null) {
107
            return null;
108
        }
109
110
        return $this->getMapper()
111
            ->mapEntityToHeidelpayDirectDebitRegistrationTransfer(
112
                $paymentHeidelpayDirectDebitRegistrationEntity,
113
                new HeidelpayDirectDebitRegistrationTransfer()
114
            );
115
    }
116
117
    /**
118
     * @param int $idCustomerAddress
119
     *
120
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer|null
121
     */
122
    public function findLastHeidelpayDirectDebitRegistrationByIdCustomerAddress(
123
        int $idCustomerAddress
124
    ): ?HeidelpayDirectDebitRegistrationTransfer {
125
        $paymentHeidelpayDirectDebitRegistrationEntity = $this->getPaymentHeidelpayDirectDebitRegistrationQuery()
126
            ->filterByFkCustomerAddress($idCustomerAddress)
127
            ->orderByIdDirectDebitRegistration(Criteria::DESC)
128
            ->findOne();
129
130
        if ($paymentHeidelpayDirectDebitRegistrationEntity === null) {
131
            return null;
132
        }
133
134
        return $this->getMapper()
135
            ->mapEntityToHeidelpayDirectDebitRegistrationTransfer(
136
                $paymentHeidelpayDirectDebitRegistrationEntity,
137
                new HeidelpayDirectDebitRegistrationTransfer()
138
            );
139
    }
140
141
    /**
142
     * @param int $idRegistration
143
     * @param string $transactionId
144
     *
145
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitRegistrationTransfer|null
146
     */
147
    public function findHeidelpayDirectDebitRegistrationByIdAndTransactionId(
148
        int $idRegistration,
149
        string $transactionId
150
    ): ?HeidelpayDirectDebitRegistrationTransfer {
151
        $paymentHeidelpayDirectDebitRegistrationEntity = $this->getPaymentHeidelpayDirectDebitRegistrationQuery()
152
            ->filterByIdDirectDebitRegistration($idRegistration)
153
            ->filterByTransactionId($transactionId)
154
            ->findOne();
155
156
        if ($paymentHeidelpayDirectDebitRegistrationEntity === null) {
157
            return null;
158
        }
159
160
        return $this->getMapper()
161
            ->mapEntityToHeidelpayDirectDebitRegistrationTransfer(
162
                $paymentHeidelpayDirectDebitRegistrationEntity,
163
                new HeidelpayDirectDebitRegistrationTransfer()
164
            );
165
    }
166
167
    /**
168
     * @param int $idSalesOrder
169
     * @param string $transactionType
170
     *
171
     * @return \Generated\Shared\Transfer\HeidelpayTransactionLogTransfer|null
172
     */
173
    public function findHeidelpayTransactionLogByIdSalesOrderAndTransactionType(
174
        int $idSalesOrder,
175
        string $transactionType
176
    ): ?HeidelpayTransactionLogTransfer {
177
        $paymentHeidelpayTransactionLogEntity = $this->getPaymentHeidelpayTransactionLogQuery()
178
            ->filterByFkSalesOrder($idSalesOrder)
179
            ->filterByTransactionType($transactionType)
180
            ->findOne();
181
182
        if ($paymentHeidelpayTransactionLogEntity === null) {
183
            return null;
184
        }
185
186
        return $this->getMapper()
187
            ->mapEntityToHeidelpayTransactionLogTransfer(
188
                $paymentHeidelpayTransactionLogEntity,
189
                new HeidelpayTransactionLogTransfer()
190
            );
191
    }
192
193
    /**
194
     * @return \SprykerEco\Zed\Heidelpay\Persistence\Propel\Mapper\HeidelpayPersistenceMapper
195
     */
196
    protected function getMapper(): HeidelpayPersistenceMapper
197
    {
198
        return $this->getFactory()->createHeidelpayPersistenceMapper();
199
    }
200
201
    /**
202
     * @return \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayQuery
203
     */
204
    protected function getPaymentHeidelpayQuery(): SpyPaymentHeidelpayQuery
205
    {
206
        return $this->getFactory()->createPaymentHeidelpayQuery();
207
    }
208
209
    /**
210
     * @return \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayNotificationQuery
211
     */
212
    protected function getPaymentHeidelpayNotificationQuery(): SpyPaymentHeidelpayNotificationQuery
213
    {
214
        return $this->getFactory()->createPaymentHeidelpayNotificationQuery();
215
    }
216
217
    /**
218
     * @return \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayDirectDebitRegistrationQuery
219
     */
220
    protected function getPaymentHeidelpayDirectDebitRegistrationQuery(): SpyPaymentHeidelpayDirectDebitRegistrationQuery
221
    {
222
        return $this->getFactory()->createPaymentHeidelpayDirectDebitRegistrationQuery();
223
    }
224
225
    /**
226
     * @return \Orm\Zed\Heidelpay\Persistence\SpyPaymentHeidelpayTransactionLogQuery
227
     */
228
    protected function getPaymentHeidelpayTransactionLogQuery(): SpyPaymentHeidelpayTransactionLogQuery
229
    {
230
        return $this->getFactory()->createPaymentHeidelpayTransactionLogQuery();
231
    }
232
}
233