Passed
Pull Request — master (#17)
by Stanislav
10:22
created

FirstDataBusinessTester::haveFirstDataCardToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
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 SprykerEcoTest\Zed\FirstData;
9
10
use Codeception\Actor;
0 ignored issues
show
Bug introduced by
The type Codeception\Actor 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 DateTime;
12
use Generated\Shared\DataBuilder\QuoteBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\QuoteBuilder 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\DataBuilder\RestCheckoutRequestAttributesBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBui...equestAttributesBuilder 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\DataBuilder\RestPaymentBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\RestPaymentBuilder 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\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer 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\FirstDataTransactionDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...TransactionDataTransfer 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\FirstDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\FirstDataTransfer 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\PaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentTransfer 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 Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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 Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...questAttributesTransfer 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 Generated\Shared\Transfer\SaveOrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\SaveOrderTransfer 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 Generated\Shared\Transfer\StoreTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreTransfer 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\FirstData\Persistence\SpyCustomerToFirstDataCardToken;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\FirstData\Persis...merToFirstDataCardToken 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\FirstData\Persistence\SpyPaymentFirstData;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\FirstData\Persistence\SpyPaymentFirstData 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 Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataCardToken;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\FirstData\Persis...ymentFirstDataCardToken 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...
26
use Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataCardTokenQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\FirstData\Persis...FirstDataCardTokenQuery 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...
27
use Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataItem;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\FirstData\Persis...SpyPaymentFirstDataItem 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...
28
use Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataItemQuery;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\FirstData\Persis...ymentFirstDataItemQuery 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...
29
use Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataNotification;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\FirstData\Persis...ntFirstDataNotification 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...
30
use Orm\Zed\Oms\Persistence\SpyOmsOrderItemState;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Oms\Persistence\SpyOmsOrderItemState 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...
31
use Orm\Zed\Sales\Persistence\SpySalesOrder;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrder 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...
32
use Orm\Zed\Sales\Persistence\SpySalesOrderAddress;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrderAddress 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...
33
use Orm\Zed\Sales\Persistence\SpySalesOrderItem;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrderItem 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...
34
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...
35
use SprykerEco\Zed\FirstData\Business\FirstDataBusinessFactory;
36
use SprykerEco\Zed\FirstData\Business\FirstDataFacade;
37
use SprykerEco\Zed\FirstData\Business\FirstDataFacadeInterface;
38
use SprykerEco\Zed\FirstData\Communication\Plugin\Checkout\FirstDataCheckoutDoSaveOrderPlugin;
39
use SprykerEco\Zed\FirstData\FirstDataConfig;
40
41
/**
42
 * @method void wantToTest($text)
43
 * @method void wantTo($text)
44
 * @method void execute($callable)
45
 * @method void expectTo($prediction)
46
 * @method void expect($prediction)
47
 * @method void amGoingTo($argumentation)
48
 * @method void am($role)
49
 * @method void lookForwardTo($achieveValue)
50
 * @method void comment($description)
51
 * @method void pause()
52
 *
53
 * @SuppressWarnings(PHPMD)
54
 */
55
class FirstDataBusinessTester extends Actor
56
{
57
    use _generated\FirstDataBusinessTesterActions;
0 ignored issues
show
Bug introduced by
The type SprykerEcoTest\Zed\First...taBusinessTesterActions 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...
58
59
    public const ID_TRANSACTION = '84556522425';
60
    public const OID = '2bfaf81a-3435';
61
    protected const TEST_CLIENT_TOKEN = 'clientToken';
62
63
    /**
64
     * @var array
65
     */
66
    protected $clientResponse = [
67
        'clientRequestId' => '2bfaf81a-3435-4c57-b03a-e87518479ca0',
68
        'apiTraceId' => 'rrt-0ce9b27534d1d00fc-b-de-22421-79415305-3',
69
        'ipgTransactionId' => '84556522425',
70
        'orderId' => 'R-6afe8368-b538-4596-9c69-f725bc03ce51',
71
        'transactionOrigin' => 'ECOM',
72
        'paymentMethodDetails' => [
73
            'paymentCard' => [
74
                'expiryDate' => [
75
                    'month' => '10',
76
                    'year' => '2022',
77
                ],
78
                'bin' => '520474',
79
                'last4' => '1002',
80
                'brand' => 'MASTERCARD',
81
            ],
82
            'paymentMethodType' => 'PAYMENT_CARD',
83
        ],
84
        'country' => 'United Kingdom',
85
        'terminalId' => '1609839',
86
        'merchantId' => '1218419',
87
        'transactionTime' => 1613670277,
88
        'approvedAmount' => [
89
            'total' => 27710,
90
            'currency' => 'USD',
91
            'components' => [
92
                'subtotal' => 27710,
93
            ],
94
        ],
95
        'transactionStatus' => 'APPROVED',
96
        'schemeTransactionId' => '0218MCC768928',
97
        'processor' => [
98
            'referenceNumber' => '84556522403 ',
99
            'authorizationCode' => 'OK9432',
100
            'responseCode' => '00',
101
            'network' => 'MAST',
102
            'associationResponseCode' => '',
103
            'responseMessage' => 'APPROVAL',
104
            'avsResponse' => [
105
                'streetMatch' => 'NO_INPUT_DATA',
106
                'postalCodeMatch' => 'NO_INPUT_DATA',
107
            ],
108
            'transactionIntegrityClass' => 'A2',
109
        ],
110
    ];
111
112
    /**
113
     * @return \SprykerEco\Zed\FirstData\FirstDataConfig
114
     */
115
    public function createConfig(): FirstDataConfig
116
    {
117
        return new FirstDataConfig();
118
    }
119
120
    /**
121
     * @return array
122
     */
123
    public function getClientResponse(): array
124
    {
125
        return $this->clientResponse;
126
    }
127
128
    /**
129
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrderAddress
130
     */
131
    protected function createSalesOrderAddressEntity(): SpySalesOrderAddress
132
    {
133
        $salesOrderAddressEntity = new SpySalesOrderAddress();
134
        $salesOrderAddressEntity->setAddress1('1');
135
        $salesOrderAddressEntity->setAddress2('2');
136
        $salesOrderAddressEntity->setSalutation('Mr');
137
        $salesOrderAddressEntity->setCellPhone('123456789');
138
        $salesOrderAddressEntity->setCity('City');
139
        $salesOrderAddressEntity->setCreatedAt(new DateTime());
140
        $salesOrderAddressEntity->setUpdatedAt(new DateTime());
141
        $salesOrderAddressEntity->setComment('Comment');
142
        $salesOrderAddressEntity->setDescription('Description');
143
        $salesOrderAddressEntity->setCompany('Company');
144
        $salesOrderAddressEntity->setFirstName('FirstName');
145
        $salesOrderAddressEntity->setLastName('LastName');
146
        $salesOrderAddressEntity->setFkCountry(1);
147
        $salesOrderAddressEntity->setEmail('Email');
148
        $salesOrderAddressEntity->setZipCode('12345');
149
        $salesOrderAddressEntity->save();
150
151
        return $salesOrderAddressEntity;
152
    }
153
154
    /**
155
     * @return \Orm\Zed\Oms\Persistence\SpyOmsOrderItemState
156
     */
157
    protected function createOmsStateEntity(): SpyOmsOrderItemState
158
    {
159
        $omsStateEntity = new SpyOmsOrderItemState();
160
        $omsStateEntity->setName('test');
161
        $omsStateEntity->save();
162
163
        return $omsStateEntity;
164
    }
165
166
    /**
167
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrder
168
     */
169
    public function createTestSalesOrderEntity(): SpySalesOrder
170
    {
171
        $salesOrderEntity = new SpySalesOrder();
172
        $salesOrderEntity->setFkSalesOrderAddressBilling($this->createSalesOrderAddressEntity()->getIdSalesOrderAddress());
173
        $salesOrderEntity->setFkSalesOrderAddressShipping($this->createSalesOrderAddressEntity()->getIdSalesOrderAddress());
174
        $salesOrderEntity->setOrderReference('order reference');
175
        $salesOrderEntity->setCurrencyIsoCode('USD');
176
        $salesOrderEntity->save();
177
178
        return $salesOrderEntity;
179
    }
180
181
    /**
182
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $salesOrderEntity
183
     *
184
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItem
185
     */
186
    public function createTestSalesOrderItemEntity(SpySalesOrder $salesOrderEntity): SpySalesOrderItem
187
    {
188
        $salesOrderItemEntity = new SpySalesOrderItem();
189
        $salesOrderItemEntity->setFkOmsOrderItemState($this->createOmsStateEntity()->getIdOmsOrderItemState());
190
        $salesOrderItemEntity->setFkSalesOrder($salesOrderEntity->getIdSalesOrder());
191
        $salesOrderItemEntity->setGrossPrice(27710);
192
        $salesOrderItemEntity->setPriceToPayAggregation(27710);
193
        $salesOrderItemEntity->setName('name-of-order-item');
194
        $salesOrderItemEntity->setSku('sku-123-321');
195
        $salesOrderItemEntity->setRefundableAmount(27710);
196
        $salesOrderItemEntity->save();
197
198
        return $salesOrderItemEntity;
199
    }
200
201
    /**
202
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $salesOrderEntity
203
     *
204
     * @return \Orm\Zed\FirstData\Persistence\SpyPaymentFirstData
205
     */
206
    public function createTestPaymentFirstDataEntity(SpySalesOrder $salesOrderEntity): SpyPaymentFirstData
207
    {
208
        $paymentFirstDataEntity = new SpyPaymentFirstData();
209
        $paymentFirstDataEntity
210
            ->setFkSalesOrder($salesOrderEntity->getIdSalesOrder())
211
            ->setTransactionId(static::ID_TRANSACTION)
212
            ->setOrderReference($salesOrderEntity->getOrderReference())
213
            ->setOid(static::OID)
214
            ->save();
215
216
        return $paymentFirstDataEntity;
217
    }
218
219
    /**
220
     * @param \Orm\Zed\FirstData\Persistence\SpyPaymentFirstData $paymentFirstDataEntity
221
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $salesOrderItemEntity
222
     * @param string $status
223
     *
224
     * @return \Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataItem
225
     */
226
    public function createTestPaymentFirstDataItemEntity(SpyPaymentFirstData $paymentFirstDataEntity, SpySalesOrderItem $salesOrderItemEntity, string $status): SpyPaymentFirstDataItem
227
    {
228
        $paymentFirstDataItemEntity = new SpyPaymentFirstDataItem();
229
        $paymentFirstDataItemEntity
230
            ->setFkPaymentFirstData($paymentFirstDataEntity->getIdPaymentFirstData())
231
            ->setFkSalesOrderItem($salesOrderItemEntity->getIdSalesOrderItem())
232
            ->setStatus($status)
233
            ->setTransactionId(static::ID_TRANSACTION)
234
            ->save();
235
236
        return $paymentFirstDataItemEntity;
237
    }
238
239
    /**
240
     * @param \Orm\Zed\FirstData\Persistence\SpyPaymentFirstData $paymentFirstDataEntity
241
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $salesOrderItemEntity
242
     * @param string $status
243
     *
244
     * @return \Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataItem
245
     */
246
    public function findTestPaymentFirstDataItemEntity(SpyPaymentFirstData $paymentFirstDataEntity, SpySalesOrderItem $salesOrderItemEntity, string $status): SpyPaymentFirstDataItem
247
    {
248
        return (SpyPaymentFirstDataItemQuery::create())
249
            ->filterByFkPaymentFirstData($paymentFirstDataEntity->getIdPaymentFirstData())
250
            ->filterByFkSalesOrderItem($salesOrderItemEntity->getIdSalesOrderItem())
251
            ->filterByStatus($status)
252
            ->findOne();
253
    }
254
255
    /**
256
     * @param int $id
257
     *
258
     * @return \Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataItem
259
     */
260
    public function findTestPaymentFirstDataItemEntityById(int $id): SpyPaymentFirstDataItem
261
    {
262
        return (SpyPaymentFirstDataItemQuery::create())
263
            ->filterByIdPaymentFirstDataItem($id)
264
            ->findOne();
265
    }
266
267
    /**
268
     * @param \SprykerEco\Zed\FirstData\Business\FirstDataBusinessFactory $firstDataBusinessFactoryMock
269
     *
270
     * @return \SprykerEco\Zed\FirstData\Business\FirstDataFacadeInterface
271
     */
272
    public function getFirstDataFacade(FirstDataBusinessFactory $firstDataBusinessFactoryMock): FirstDataFacadeInterface
273
    {
274
        $firstDataFacade = $this->getFacade();
275
        $firstDataFacade->setFactory($firstDataBusinessFactoryMock);
276
277
        return $firstDataFacade;
278
    }
279
280
    /**
281
     * @return \SprykerEco\Zed\FirstData\Business\FirstDataFacade
282
     */
283
    public function getFacade(): FirstDataFacade
284
    {
285
        return new FirstDataFacade();
286
    }
287
288
    /**
289
     * @param string $stateMachineProcessName
290
     * @param string $transactionId
291
     * @param string $oid
292
     *
293
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItem
294
     */
295
    public function createSalesOrderItemEntityFromQuote(
296
        string $stateMachineProcessName,
297
        string $transactionId,
298
        string $oid
299
    ): SpySalesOrderItem {
300
        $storeTransfer = $this->haveStore([StoreTransfer::NAME => 'DE']);
301
302
        $quoteTransfer = (new QuoteBuilder())
303
            ->withItem()
304
            ->withTotals()
305
            ->withShippingAddress()
306
            ->withBillingAddress()
307
            ->withCurrency()
308
            ->withPayment()
309
            ->build();
310
311
        $quoteTransfer
312
            ->setCustomer($this->haveCustomer())
313
            ->setStore($storeTransfer)
314
            ->setPayment($this->createPaymentTransfer($transactionId, $oid));
315
316
        $saveOrderTransfer = $this->haveOrderFromQuote($quoteTransfer, $stateMachineProcessName, [new FirstDataCheckoutDoSaveOrderPlugin()]);
317
318
        return $this->findSalesOrderItemEntity($saveOrderTransfer);
319
    }
320
321
    /**
322
     * @param string $transactionId
323
     * @param string $oid
324
     * @param string $status
325
     *
326
     * @return \Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataNotification
327
     */
328
    public function createTestPaymentFirstDataNotificationEntity(string $transactionId, string $oid, string $status): SpyPaymentFirstDataNotification
329
    {
330
        $paymentFirstDataNotificationEntity = new SpyPaymentFirstDataNotification();
331
        $paymentFirstDataNotificationEntity
332
            ->setTransactionId($transactionId)
333
            ->setOid($oid)
334
            ->setStatus($status)
335
            ->save();
336
337
        return $paymentFirstDataNotificationEntity;
338
    }
339
340
    /**
341
     * @return \Generated\Shared\Transfer\QuoteTransfer
342
     */
343
    public function createQuoteTransfer(): QuoteTransfer
344
    {
345
        /** @var \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer */
346
        $quoteTransfer = (new QuoteBuilder())->build();
347
348
        return $quoteTransfer;
349
    }
350
351
    /**
352
     * @param string $transactionId
353
     * @param string $oid
354
     *
355
     * @return \Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer
356
     */
357
    public function createRestCheckoutRequestAttributesTransferWithSinglePayment(string $transactionId, string $oid): RestCheckoutRequestAttributesTransfer
358
    {
359
        $firstDataTransactionDataTransfer = (new FirstDataTransactionDataTransfer())
360
            ->setTransactionId($transactionId)
361
            ->setOid($oid);
362
363
        /** @var \Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer */
364
        $restCheckoutRequestAttributesTransfer = (new RestCheckoutRequestAttributesBuilder())
365
            ->withPayment($this->createRestPaymentBuilder())
366
            ->build()
367
            ->setFirstDataTransactionData($firstDataTransactionDataTransfer);
368
369
        return $restCheckoutRequestAttributesTransfer;
370
    }
371
372
    /**
373
     * @param string $clientToken
374
     *
375
     * @return \Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataCardToken
376
     */
377
    public function getFirstDataCardTokenWithUserRelationByClientToken(string $clientToken): SpyPaymentFirstDataCardToken
378
    {
379
        return SpyPaymentFirstDataCardTokenQuery::create()->filterByClientToken($clientToken)
380
            ->joinWithSpyCustomerToFirstDataCardToken()
381
            ->find()
382
            ->getFirst();
383
    }
384
385
    /**
386
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
387
     *
388
     * @return \Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataCardToken
389
     */
390
    public function haveFirstDataCustomerToken(CustomerTransfer $customerTransfer): SpyPaymentFirstDataCardToken
391
    {
392
        $paymentFirstDataCardTokenEntity = $this->haveFirstDataCardToken();
393
394
        $customerToFirstDataCardToken = (new SpyCustomerToFirstDataCardToken())
395
            ->setCustomerReference($customerTransfer->getCustomerReference())
396
            ->setFkPaymentFirstDataCardToken($paymentFirstDataCardTokenEntity->getIdPaymentFirstDataCardToken());
397
398
        $customerToFirstDataCardToken->save();
399
400
        return $paymentFirstDataCardTokenEntity;
401
    }
402
403
    /**
404
     * @return \Orm\Zed\FirstData\Persistence\SpyPaymentFirstDataCardToken
405
     */
406
    public function haveFirstDataCardToken(): SpyPaymentFirstDataCardToken
407
    {
408
        $paymentFirstDataCardTokenEntity = (new SpyPaymentFirstDataCardToken())
409
            ->setClientToken(static::TEST_CLIENT_TOKEN);
410
411
        $paymentFirstDataCardTokenEntity->save();
412
413
        return $paymentFirstDataCardTokenEntity;
414
    }
415
416
    /**
417
     * @param string $transactionId
418
     * @param string $oid
419
     *
420
     * @return \Generated\Shared\Transfer\PaymentTransfer
421
     */
422
    protected function createPaymentTransfer(string $transactionId, string $oid): PaymentTransfer
423
    {
424
        $firstDataTransfer = (new FirstDataTransfer())
425
            ->setFirstDataTransactionData((new FirstDataTransactionDataTransfer())
426
                ->setOid($oid)
427
                ->setTransactionId($transactionId));
428
429
        return (new PaymentTransfer())
430
            ->setPaymentMethod('firstDataCreditCard')
431
            ->setPaymentProvider('firstData')
432
            ->setFirstDataCreditCard($firstDataTransfer);
433
    }
434
435
    /**
436
     * @return \Generated\Shared\DataBuilder\RestPaymentBuilder
437
     */
438
    protected function createRestPaymentBuilder(): RestPaymentBuilder
439
    {
440
        return (new RestPaymentBuilder([
441
            'paymentProvider' => 'firstDataCreditCard',
442
            'paymentMethod' => 'firstData',
443
            'paymentSelection' => 'firstDataCreditCard',
444
        ]));
445
    }
446
447
    /**
448
     * @param \Generated\Shared\Transfer\SaveOrderTransfer $saveOrderTransfer
449
     *
450
     * @return \Orm\Zed\Sales\Persistence\SpySalesOrderItem
451
     */
452
    protected function findSalesOrderItemEntity(SaveOrderTransfer $saveOrderTransfer): SpySalesOrderItem
453
    {
454
        return (new SpySalesOrderItemQuery())
455
            ->joinWithOrder()
456
            ->useOrderQuery()
457
            ->filterByOrderReference($saveOrderTransfer->getOrderReference())
458
            ->endUse()
459
            ->findOne();
460
    }
461
}
462