CheckoutApiTester::havePaymentMethodWithStore()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace PyzTest\Glue\Checkout;
11
12
use DateTime;
13
use Generated\Shared\DataBuilder\AddressBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\AddressBuilder 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\CustomerBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\CustomerBuilder 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\DataBuilder\ItemBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\ItemBuilder 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\DataBuilder\ShipmentBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\ShipmentBuilder 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\DataBuilder\StoreRelationBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\StoreRelationBuilder 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\AddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AddressTransfer 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\CompanyUnitAddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...panyUnitAddressTransfer 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\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...
21
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer 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\MoneyValueTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\MoneyValueTransfer 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 Generated\Shared\Transfer\PaymentMethodTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentMethodTransfer 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 Generated\Shared\Transfer\PriceProductTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PriceProductTransfer 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 Generated\Shared\Transfer\ProductConcreteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ProductConcreteTransfer 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 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...
27
use Generated\Shared\Transfer\RestAddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestAddressTransfer 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 Generated\Shared\Transfer\RestCheckoutDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestCheckoutDataTransfer 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 Generated\Shared\Transfer\RestCheckoutResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...heckoutResponseTransfer 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 Generated\Shared\Transfer\RestCustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestCustomerTransfer 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 Generated\Shared\Transfer\RestOrderDetailsAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...tailsAttributesTransfer 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 Generated\Shared\Transfer\RestPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestPaymentTransfer 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 Generated\Shared\Transfer\RestShipmentsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestShipmentsTransfer 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 Generated\Shared\Transfer\RestShipmentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestShipmentTransfer 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 Generated\Shared\Transfer\ShipmentMethodTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ShipmentMethodTransfer 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...
36
use Generated\Shared\Transfer\ShipmentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ShipmentTransfer 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...
37
use Generated\Shared\Transfer\StockProductTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StockProductTransfer 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...
38
use Generated\Shared\Transfer\StoreRelationTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreRelationTransfer 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...
39
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...
40
use Generated\Shared\Transfer\TotalsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\TotalsTransfer 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...
41
use Spryker\Glue\CheckoutRestApi\CheckoutRestApiConfig;
42
use Spryker\Glue\GlueApplication\Rest\RequestConstantsInterface;
43
use Spryker\Glue\OrdersRestApi\OrdersRestApiConfig;
44
use Spryker\Shared\Price\PriceConfig;
45
use Spryker\Shared\Shipment\ShipmentConfig;
46
use Spryker\Zed\Cart\Business\CartFacadeInterface;
47
use Spryker\Zed\Customer\Business\CustomerFacadeInterface;
48
use Spryker\Zed\Store\Business\StoreFacadeInterface;
49
use SprykerTest\Glue\Testify\Tester\ApiEndToEndTester;
50
51
/**
52
 * Inherited Methods
53
 *
54
 * @method void wantToTest($text)
55
 * @method void wantTo($text)
56
 * @method void execute($callable)
57
 * @method void expectTo($prediction)
58
 * @method void expect($prediction)
59
 * @method void amGoingTo($argumentation)
60
 * @method void am($role)
61
 * @method void lookForwardTo($achieveValue)
62
 * @method void comment($description)
63
 * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
64
 *
65
 * @SuppressWarnings(\PyzTest\Glue\Checkout\PHPMD)
66
 */
67
class CheckoutApiTester extends ApiEndToEndTester
68
{
69
    use _generated\CheckoutApiTesterActions;
0 ignored issues
show
Bug introduced by
The type PyzTest\Glue\Checkout\_g...heckoutApiTesterActions 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...
70
71
    /**
72
     * @var string
73
     */
74
    protected const REQUEST_PARAM_PAYMENT_METHOD_NAME_INVOICE = 'Invoice';
75
76
    /**
77
     * @var string
78
     */
79
    protected const REQUEST_PARAM_PAYMENT_PROVIDER_NAME_DUMMY_PAYMENT = 'DummyPayment';
80
81
    /**
82
     * @var string
83
     */
84
    protected const QUOTE_ITEM_OVERRIDE_DATA_PRODUCT = 'product';
85
86
    /**
87
     * @var string
88
     */
89
    protected const QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT = 'shipment';
90
91
    /**
92
     * @var string
93
     */
94
    protected const QUOTE_ITEM_OVERRIDE_DATA_QUANTITY = 'quantity';
95
96
    /**
97
     * @var int
98
     */
99
    protected const DEFAULT_QUOTE_ITEM_QUANTITY = 10;
100
101
    /**
102
     * @return void
103
     */
104
    public function assertCheckoutResponseResourceHasCorrectData(): void
105
    {
106
        $this->amSure('The returned resource id should be null')
107
            ->whenI()
108
            ->seeSingleResourceIdEqualTo('');
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceIdEqualTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

108
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo('');
Loading history...
109
110
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
111
112
        $this->assertNotEmpty(
113
            $attributes[RestCheckoutResponseTransfer::ORDER_REFERENCE],
114
            'The returned resource attributes order reference should not be empty',
115
        );
116
        $this->assertArrayHasKey(
117
            RestCheckoutResponseTransfer::IS_EXTERNAL_REDIRECT,
118
            $attributes,
119
            'The returned resource attributes should have an external redirect key',
120
        );
121
        $this->assertArrayHasKey(
122
            RestCheckoutResponseTransfer::REDIRECT_URL,
123
            $attributes,
124
            'The returned resource attributes should have a redirect URL key',
125
        );
126
    }
127
128
    /**
129
     * @return void
130
     */
131
    public function assertCheckoutDataResponseResourceHasCorrectData(): void
132
    {
133
        $this->amSure('The returned resource id should be null')
134
            ->whenI()
135
            ->seeSingleResourceIdEqualTo('');
136
137
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
138
139
        $this->assertEmpty(
140
            $attributes[RestCheckoutDataTransfer::ADDRESSES],
141
            'The returned resource attributes addresses should be an empty array',
142
        );
143
    }
144
145
    /**
146
     * @param int $price
147
     *
148
     * @return void
149
     */
150
    public function assertShipmentExpensesHaveCorrectPrice(int $price): void
151
    {
152
        $this->amSure('The returned resource should have included orders resource')
153
            ->whenI()
154
            ->seeIncludesContainResourceOfType(OrdersRestApiConfig::RESOURCE_ORDERS);
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainResourceOfType() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

154
            ->/** @scrutinizer ignore-call */ seeIncludesContainResourceOfType(OrdersRestApiConfig::RESOURCE_ORDERS);
Loading history...
155
156
        $ordersAttributes = $this->getDataFromResponseByJsonPath(
157
            sprintf('$.included[?(@.type == %1$s)].attributes', json_encode(OrdersRestApiConfig::RESOURCE_ORDERS)),
158
        );
159
160
        $this->assertNotNull($ordersAttributes);
161
        $this->assertCount(1, $ordersAttributes);
162
        $restOrdersDetailsAttributesTransfer = (new RestOrderDetailsAttributesTransfer())->fromArray($ordersAttributes[0], true);
163
        $this->assertCount(1, $restOrdersDetailsAttributesTransfer->getExpenses());
164
165
        /** @var \Generated\Shared\Transfer\RestOrderExpensesAttributesTransfer $restOrderExpensesAttributesTransfer */
166
        $restOrderExpensesAttributesTransfer = $restOrdersDetailsAttributesTransfer->getExpenses()->getIterator()->current();
167
        $this->assertSame(ShipmentConfig::SHIPMENT_EXPENSE_TYPE, $restOrderExpensesAttributesTransfer->getType());
168
        $this->assertSame($price, $restOrderExpensesAttributesTransfer->getSumPrice());
169
    }
170
171
    /**
172
     * @param array<string> $includes
173
     *
174
     * @return string
175
     */
176
    public function buildCheckoutUrl(array $includes = []): string
177
    {
178
        return $this->formatFullUrl(
179
            '{resourceCheckout}' . $this->formatQueryInclude($includes),
180
            [
181
                'resourceCheckout' => CheckoutRestApiConfig::RESOURCE_CHECKOUT,
182
            ],
183
        );
184
    }
185
186
    /**
187
     * @param array<string> $includes
188
     *
189
     * @return string
190
     */
191
    public function buildCheckoutDataUrl(array $includes = []): string
192
    {
193
        return $this->formatFullUrl(
194
            '{resourceCheckoutData}' . $this->formatQueryInclude($includes),
195
            [
196
                'resourceCheckoutData' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
197
            ],
198
        );
199
    }
200
201
    /**
202
     * @return \Spryker\Zed\Store\Business\StoreFacadeInterface
203
     */
204
    public function getStoreFacade(): StoreFacadeInterface
205
    {
206
        return $this->getLocator()
207
            ->store()
208
            ->facade();
209
    }
210
211
    /**
212
     * @return \Spryker\Zed\Customer\Business\CustomerFacadeInterface
213
     */
214
    public function getCustomerFacade(): CustomerFacadeInterface
215
    {
216
        return $this->getLocator()
217
            ->customer()
218
            ->facade();
219
    }
220
221
    /**
222
     * @return \Spryker\Zed\Cart\Business\CartFacadeInterface
223
     */
224
    public function getCartFacade(): CartFacadeInterface
225
    {
226
        return $this->getLocator()->cart()->facade();
227
    }
228
229
    /**
230
     * @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
231
     *
232
     * @return array
233
     */
234
    public function getAddressRequestPayload(AddressTransfer $addressTransfer): array
235
    {
236
        return [
237
            RestAddressTransfer::SALUTATION => $addressTransfer->getSalutation(),
238
            RestAddressTransfer::FIRST_NAME => $addressTransfer->getFirstName(),
239
            RestAddressTransfer::LAST_NAME => $addressTransfer->getLastName(),
240
            RestAddressTransfer::ADDRESS1 => $addressTransfer->getAddress1(),
241
            RestAddressTransfer::ADDRESS2 => $addressTransfer->getAddress2(),
242
            RestAddressTransfer::ADDRESS3 => $addressTransfer->getAddress3(),
243
            RestAddressTransfer::ZIP_CODE => $addressTransfer->getZipCode(),
244
            RestAddressTransfer::CITY => $addressTransfer->getCity(),
245
            RestAddressTransfer::ISO2_CODE => $addressTransfer->getIso2Code(),
246
            RestAddressTransfer::PHONE => $addressTransfer->getPhone(),
247
            RestCustomerTransfer::EMAIL => $addressTransfer->getEmail(),
248
            RestAddressTransfer::IS_DEFAULT_BILLING => $addressTransfer->getIsDefaultBilling(),
249
            RestAddressTransfer::IS_DEFAULT_SHIPPING => $addressTransfer->getIsDefaultShipping(),
250
        ];
251
    }
252
253
    /**
254
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
255
     *
256
     * @return array
257
     */
258
    public function getCustomerRequestPayload(CustomerTransfer $customerTransfer): array
259
    {
260
        return [
261
            RestCustomerTransfer::SALUTATION => $customerTransfer->getSalutation(),
262
            RestCustomerTransfer::FIRST_NAME => $customerTransfer->getFirstName(),
263
            RestCustomerTransfer::LAST_NAME => $customerTransfer->getLastName(),
264
            RestCustomerTransfer::EMAIL => $customerTransfer->getEmail(),
265
        ];
266
    }
267
268
    /**
269
     * @param string $paymentMethodName
270
     * @param string $paymentProviderName
271
     *
272
     * @return array
273
     */
274
    public function getPaymentRequestPayload(
275
        string $paymentMethodName = self::REQUEST_PARAM_PAYMENT_METHOD_NAME_INVOICE,
276
        string $paymentProviderName = self::REQUEST_PARAM_PAYMENT_PROVIDER_NAME_DUMMY_PAYMENT,
277
    ): array {
278
        return [
279
            [
280
                RestPaymentTransfer::PAYMENT_METHOD_NAME => $paymentMethodName,
281
                RestPaymentTransfer::PAYMENT_PROVIDER_NAME => $paymentProviderName,
282
            ],
283
        ];
284
    }
285
286
    /**
287
     * @param int $idShipmentMethod
288
     *
289
     * @return array
290
     */
291
    public function getShipmentRequestPayload(int $idShipmentMethod): array
292
    {
293
        return [
294
            RestShipmentTransfer::ID_SHIPMENT_METHOD => $idShipmentMethod,
295
        ];
296
    }
297
298
    /**
299
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
300
     * @param \Generated\Shared\Transfer\AddressTransfer|null $addressTransfer
301
     *
302
     * @return array<string, mixed>
303
     */
304
    public function getSplitShipmentRequestPayload(ItemTransfer $itemTransfer, ?AddressTransfer $addressTransfer = null): array
305
    {
306
        $shippingAddressPayload = $addressTransfer
307
            ? [RestAddressTransfer::ID => $addressTransfer->getUuidOrFail()]
308
            : $this->getAddressRequestPayload($itemTransfer->getShipmentOrFail()->getShippingAddressOrFail());
309
310
        return [
311
            RestShipmentsTransfer::ID_SHIPMENT_METHOD => $itemTransfer->getShipmentOrFail()->getMethodOrFail()->getIdShipmentMethodOrFail(),
312
            RestShipmentsTransfer::ITEMS => [$itemTransfer->getGroupKeyOrFail()],
313
            RestShipmentsTransfer::SHIPPING_ADDRESS => $shippingAddressPayload,
314
            RestShipmentsTransfer::REQUESTED_DELIVERY_DATE => (new DateTime('tomorrow'))->format('Y-m-d'),
315
        ];
316
    }
317
318
    /**
319
     * @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer
320
     * @param \Generated\Shared\Transfer\ShipmentMethodTransfer $shipmentMethodTransfer
321
     * @param int $quantity
322
     *
323
     * @return array
324
     */
325
    public function getQuoteItemOverrideData(
326
        ProductConcreteTransfer $productConcreteTransfer,
327
        ShipmentMethodTransfer $shipmentMethodTransfer,
328
        int $quantity = self::DEFAULT_QUOTE_ITEM_QUANTITY,
329
    ): array {
330
        return [
331
            static::QUOTE_ITEM_OVERRIDE_DATA_PRODUCT => $productConcreteTransfer,
332
            static::QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT => [
333
                ShipmentTransfer::METHOD => $shipmentMethodTransfer,
334
            ],
335
            static::QUOTE_ITEM_OVERRIDE_DATA_QUANTITY => $quantity,
336
        ];
337
    }
338
339
    /**
340
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
341
     *
342
     * @return void
343
     */
344
    public function authorizeCustomerToGlue(CustomerTransfer $customerTransfer): void
345
    {
346
        $oauthResponseTransfer = $this->haveAuthorizationToGlue($customerTransfer);
347
        $this->amBearerAuthenticated($oauthResponseTransfer->getAccessToken());
348
    }
349
350
    /**
351
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
352
     * @param array $overrideItems
353
     * @param string $priceMode
354
     *
355
     * @return \Generated\Shared\Transfer\QuoteTransfer
356
     */
357
    public function havePersistentQuoteWithItemsAndItemLevelShipment(
358
        CustomerTransfer $customerTransfer,
359
        array $overrideItems = [],
360
        string $priceMode = PriceConfig::PRICE_MODE_GROSS,
361
    ): QuoteTransfer {
362
        return $this->havePersistentQuote([
363
            QuoteTransfer::CUSTOMER => $customerTransfer,
364
            QuoteTransfer::TOTALS => (new TotalsTransfer())
365
                ->setSubtotal(random_int(1000, 10000))
366
                ->setPriceToPay(random_int(1000, 10000)),
367
            QuoteTransfer::ITEMS => $this->mapProductConcreteTransfersToQuoteTransferItemsWithItemLevelShipment($overrideItems),
368
            QuoteTransfer::STORE => [StoreTransfer::NAME => 'DE'],
369
            QuoteTransfer::PRICE_MODE => $priceMode,
370
            QuoteTransfer::BILLING_ADDRESS => (new AddressBuilder())->build(),
371
        ]);
372
    }
373
374
    /**
375
     * @param array $overrideCustomer
376
     *
377
     * @return \Generated\Shared\Transfer\QuoteTransfer
378
     */
379
    public function haveEmptyPersistentQuote(array $overrideCustomer = []): QuoteTransfer
380
    {
381
        return $this->havePersistentQuote([
382
            QuoteTransfer::CUSTOMER => (new CustomerBuilder($overrideCustomer))->build(),
383
            QuoteTransfer::BILLING_ADDRESS => (new AddressBuilder())->build(),
384
        ]);
385
    }
386
387
    /**
388
     * @return \Generated\Shared\Transfer\ProductConcreteTransfer
389
     */
390
    public function haveProductWithStock(): ProductConcreteTransfer
391
    {
392
        $productConcreteTransfer = $this->haveFullProduct();
393
394
        $this->haveProductInStockForStore($this->getStoreFacade()->getCurrentStore(), [
395
            StockProductTransfer::SKU => $productConcreteTransfer->getSku(),
396
            StockProductTransfer::IS_NEVER_OUT_OF_STOCK => 1,
397
        ]);
398
399
        $priceProductOverride = [
400
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
401
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
402
            PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
403
            PriceProductTransfer::PRICE_TYPE_NAME => 'DEFAULT',
404
            PriceProductTransfer::MONEY_VALUE => [
405
                MoneyValueTransfer::NET_AMOUNT => 770,
406
                MoneyValueTransfer::GROSS_AMOUNT => 880,
407
            ],
408
        ];
409
        $this->havePriceProduct($priceProductOverride);
410
411
        return $productConcreteTransfer;
412
    }
413
414
    /**
415
     * @param array $override
416
     *
417
     * @return \Generated\Shared\Transfer\CustomerTransfer
418
     */
419
    public function createCustomerTransfer(array $override = []): CustomerTransfer
420
    {
421
        return (new CustomerBuilder($override))->build();
422
    }
423
424
    /**
425
     * @param array $override
426
     *
427
     * @return \Generated\Shared\Transfer\CustomerTransfer
428
     */
429
    public function haveCustomerWithPersistentAddress(array $override = []): CustomerTransfer
430
    {
431
        $customerTransfer = $this->haveCustomer($override);
432
433
        return $this->haveAddressForCustomer($customerTransfer);
434
    }
435
436
    /**
437
     * @param array $paymentMethodOverrideData
438
     * @param array $storeOverrideData
439
     *
440
     * @return \Generated\Shared\Transfer\PaymentMethodTransfer
441
     */
442
    public function havePaymentMethodWithStore(
443
        array $paymentMethodOverrideData = [],
444
        array $storeOverrideData = [
445
            StoreTransfer::NAME => 'DE',
446
            StoreTransfer::DEFAULT_CURRENCY_ISO_CODE => 'EUR',
447
            StoreTransfer::AVAILABLE_CURRENCY_ISO_CODES => ['EUR'],
448
        ],
449
    ): PaymentMethodTransfer {
450
        $storeTransfer = $this->haveStore($storeOverrideData);
451
        $storeRelationTransfer = (new StoreRelationBuilder())->seed([
452
            StoreRelationTransfer::ID_STORES => [
453
                $storeTransfer->getIdStore(),
454
            ],
455
            StoreRelationTransfer::STORES => [
456
                $storeTransfer,
457
            ],
458
        ])->build();
459
460
        $paymentMethodOverrideData = array_merge($paymentMethodOverrideData, [PaymentMethodTransfer::STORE_RELATION => $storeRelationTransfer]);
461
462
        return $this->havePaymentMethod($paymentMethodOverrideData);
463
    }
464
465
    /**
466
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
467
     * @param \Generated\Shared\Transfer\CompanyUnitAddressTransfer $companyUnitAddressTransfer
468
     *
469
     * @return array<string, mixed>
470
     */
471
    public function getSplitShipmentRequestPayloadWithCompanyBusinessUnitAddress(
472
        ItemTransfer $itemTransfer,
473
        CompanyUnitAddressTransfer $companyUnitAddressTransfer,
474
    ): array {
475
        return [
476
            RestShipmentsTransfer::ID_SHIPMENT_METHOD => $itemTransfer->getShipmentOrFail()->getMethodOrFail()->getIdShipmentMethodOrFail(),
477
            RestShipmentsTransfer::ITEMS => [$itemTransfer->getGroupKeyOrFail()],
478
            RestShipmentsTransfer::SHIPPING_ADDRESS => [
479
                RestAddressTransfer::ID_COMPANY_BUSINESS_UNIT_ADDRESS => $companyUnitAddressTransfer->getUuidOrFail(),
480
            ],
481
            RestShipmentsTransfer::REQUESTED_DELIVERY_DATE => (new DateTime('tomorrow'))->format('Y-m-d'),
482
        ];
483
    }
484
485
    /**
486
     * @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
487
     *
488
     * @return void
489
     */
490
    public function assertCustomerBillingAddressInOrders(AddressTransfer $addressTransfer): void
491
    {
492
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'orders');
493
        $billingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['billingAddress'];
494
495
        $this->assertSame($addressTransfer->getAddress1(), $billingAddress['address1']);
496
        $this->assertSame($addressTransfer->getAddress2(), $billingAddress['address2']);
497
        $this->assertSame($addressTransfer->getAddress3(), $billingAddress['address3']);
498
        $this->assertSame($addressTransfer->getCompany(), $billingAddress['company']);
499
        $this->assertSame($addressTransfer->getCity(), $billingAddress['city']);
500
        $this->assertSame($addressTransfer->getZipCode(), $billingAddress['zipCode']);
501
        $this->assertSame($addressTransfer->getIso2Code(), $billingAddress['iso2Code']);
502
    }
503
504
    /**
505
     * @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
506
     *
507
     * @return void
508
     */
509
    public function assertCustomerShippingAddressInOrderShipments(
510
        AddressTransfer $addressTransfer,
511
    ): void {
512
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'order-shipments');
513
        $shippingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['shippingAddress'];
514
515
        $this->assertSame($addressTransfer->getAddress1(), $shippingAddress['address1']);
516
        $this->assertSame($addressTransfer->getAddress2(), $shippingAddress['address2']);
517
        $this->assertSame($addressTransfer->getAddress3(), $shippingAddress['address3']);
518
        $this->assertSame($addressTransfer->getCompany(), $shippingAddress['company']);
519
        $this->assertSame($addressTransfer->getCity(), $shippingAddress['city']);
520
        $this->assertSame($addressTransfer->getZipCode(), $shippingAddress['zipCode']);
521
        $this->assertSame($addressTransfer->getIso2Code(), $shippingAddress['iso2Code']);
522
    }
523
524
    /**
525
     * @param \Generated\Shared\Transfer\CompanyUnitAddressTransfer $companyUnitAddressTransfer
526
     *
527
     * @return void
528
     */
529
    public function assertCompanyBusinessUnitBillingAddressInOrders(
530
        CompanyUnitAddressTransfer $companyUnitAddressTransfer,
531
    ): void {
532
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'orders');
533
        $billingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['billingAddress'];
534
535
        $this->assertSame($companyUnitAddressTransfer->getAddress1(), $billingAddress['address1']);
536
        $this->assertSame($companyUnitAddressTransfer->getAddress2(), $billingAddress['address2']);
537
        $this->assertSame($companyUnitAddressTransfer->getAddress3(), $billingAddress['address3']);
538
        $this->assertSame($companyUnitAddressTransfer->getCompany()->getName(), $billingAddress['company']);
539
        $this->assertSame($companyUnitAddressTransfer->getCity(), $billingAddress['city']);
540
        $this->assertSame($companyUnitAddressTransfer->getZipCode(), $billingAddress['zipCode']);
541
        $this->assertSame($companyUnitAddressTransfer->getIso2Code(), $billingAddress['iso2Code']);
542
    }
543
544
    /**
545
     * @param \Generated\Shared\Transfer\CompanyUnitAddressTransfer $companyUnitAddressTransfer
546
     *
547
     * @return void
548
     */
549
    public function assertCompanyBusinessUnitShippingAddressInOrderShipments(
550
        CompanyUnitAddressTransfer $companyUnitAddressTransfer,
551
    ): void {
552
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'order-shipments');
553
        $shippingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['shippingAddress'];
554
555
        $this->assertSame($companyUnitAddressTransfer->getAddress1(), $shippingAddress['address1']);
556
        $this->assertSame($companyUnitAddressTransfer->getAddress2(), $shippingAddress['address2']);
557
        $this->assertSame($companyUnitAddressTransfer->getAddress3(), $shippingAddress['address3']);
558
        $this->assertSame($companyUnitAddressTransfer->getCompany()->getName(), $shippingAddress['company']);
559
        $this->assertSame($companyUnitAddressTransfer->getCity(), $shippingAddress['city']);
560
        $this->assertSame($companyUnitAddressTransfer->getZipCode(), $shippingAddress['zipCode']);
561
        $this->assertSame($companyUnitAddressTransfer->getIso2Code(), $shippingAddress['iso2Code']);
562
    }
563
564
    /**
565
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
566
     *
567
     * @return \Generated\Shared\Transfer\CustomerTransfer
568
     */
569
    protected function haveAddressForCustomer(CustomerTransfer $customerTransfer): CustomerTransfer
570
    {
571
        $addressTransfer = (new AddressBuilder([
572
            AddressTransfer::EMAIL => $customerTransfer->getEmail(),
573
            AddressTransfer::FK_CUSTOMER => $customerTransfer->getIdCustomer(),
574
            AddressTransfer::FIRST_NAME => $customerTransfer->getFirstName(),
575
            AddressTransfer::LAST_NAME => $customerTransfer->getLastName(),
576
        ]))->build();
577
        $customerFacade = $this->getCustomerFacade();
578
        $customerFacade->createAddress($addressTransfer);
579
580
        return $customerFacade->getCustomer($customerTransfer);
581
    }
582
583
    /**
584
     * @param array $overrideItems
585
     *
586
     * @return array
587
     */
588
    protected function mapProductConcreteTransfersToQuoteTransferItemsWithItemLevelShipment(array $overrideItems = []): array
589
    {
590
        $quoteTransferItems = [];
591
592
        foreach ($overrideItems as $overrideItem) {
593
            $productConcreteTransfer = $this->getProductConcreteTransferFromOverrideItemData($overrideItem);
594
            $overrideShipment = $this->getOverrideShipmentDataFromOverrideItemData($overrideItem);
595
596
            $quoteTransferItems[] = (new ItemBuilder([
597
                ItemTransfer::SKU => $productConcreteTransfer->getSku(),
598
                ItemTransfer::GROUP_KEY => $productConcreteTransfer->getSku(),
599
                ItemTransfer::ABSTRACT_SKU => $productConcreteTransfer->getAbstractSku(),
600
                ItemTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
601
                ItemTransfer::QUANTITY => $this->getQuoteItemQuantityFromOverrideItemData($overrideItem),
602
            ]))->withShipment((new ShipmentBuilder($overrideShipment))
603
                ->withMethod()
604
                ->withShippingAddress())
605
                ->build()
606
                ->modifiedToArray();
607
        }
608
609
        return $quoteTransferItems;
610
    }
611
612
    /**
613
     * @param array $overrideItem
614
     *
615
     * @return \Generated\Shared\Transfer\ProductConcreteTransfer
616
     */
617
    protected function getProductConcreteTransferFromOverrideItemData(array $overrideItem): ProductConcreteTransfer
618
    {
619
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_PRODUCT];
620
    }
621
622
    /**
623
     * @param array $overrideItem
624
     *
625
     * @return array
626
     */
627
    protected function getOverrideShipmentDataFromOverrideItemData(array $overrideItem): array
628
    {
629
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT];
630
    }
631
632
    /**
633
     * @param array $overrideItem
634
     *
635
     * @return int
636
     */
637
    protected function getQuoteItemQuantityFromOverrideItemData(array $overrideItem): int
638
    {
639
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_QUANTITY] ?? static::DEFAULT_QUOTE_ITEM_QUANTITY;
640
    }
641
642
    /**
643
     * @param array<string> $includes
644
     *
645
     * @return string
646
     */
647
    protected function formatQueryInclude(array $includes = []): string
648
    {
649
        if (!$includes) {
650
            return '';
651
        }
652
653
        return sprintf('?%s=%s', RequestConstantsInterface::QUERY_INCLUDE, implode(',', $includes));
654
    }
655
}
656