Passed
Pull Request — master (#365)
by Dmitry
21:01
created

CheckoutApiTester   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 543
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 33
eloc 185
dl 0
loc 543
c 1
b 0
f 0
rs 9.76

30 Methods

Rating   Name   Duplication   Size   Complexity  
A buildCheckoutDataUrl() 0 6 1
A getAddressRequestPayload() 0 16 1
A havePersistentQuoteWithItems() 0 19 1
A mapProductConcreteTransfersToQuoteTransferItems() 0 16 2
A havePaymentMethodWithStore() 0 21 1
A getCartFacade() 0 3 1
A getCustomerRequestPayload() 0 7 1
A assertCheckoutDataResponseResourceHasCorrectData() 0 11 1
A authorizeCustomerToGlue() 0 4 1
A assertCheckoutResponseResourceHasCorrectData() 0 21 1
A assertShipmentExpensesHaveCorrectPrice() 0 19 1
A haveProductWithStock() 0 22 1
A mapProductConcreteTransfersToQuoteTransferItemsWithItemLevelShipment() 0 22 2
A getSplitShipmentRequestPayload() 0 7 1
A getOverrideShipmentDataFromOverrideItemData() 0 3 1
A createCustomerTransfer() 0 3 1
A haveEmptyPersistentQuote() 0 5 1
A getCustomerFacade() 0 5 1
A getShipmentRequestPayload() 0 4 1
A createGuestCustomerReference() 0 3 1
A getQuoteItemOverrideData() 0 11 1
A getStoreFacade() 0 5 1
A buildCheckoutUrl() 0 6 1
A haveCustomerWithPersistentAddress() 0 5 1
A haveAddressForCustomer() 0 12 1
A getProductConcreteTransferFromOverrideItemData() 0 3 1
A getQuoteItemQuantityFromOverrideItemData() 0 3 1
A getPaymentRequestPayload() 0 8 1
A formatQueryInclude() 0 7 2
A havePersistentQuoteWithItemsAndItemLevelShipment() 0 14 1
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
namespace PyzTest\Glue\Checkout;
9
10
use DateTime;
11
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...
12
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...
13
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...
14
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...
15
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...
16
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...
17
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...
18
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...
19
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...
20
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...
21
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...
22
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...
23
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...
24
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...
25
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...
26
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...
27
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...
28
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...
29
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...
30
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...
31
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...
32
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...
33
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...
34
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...
35
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...
36
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...
37
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...
38
use Spryker\Glue\CheckoutRestApi\CheckoutRestApiConfig;
39
use Spryker\Glue\GlueApplication\Rest\RequestConstantsInterface;
40
use Spryker\Glue\OrdersRestApi\OrdersRestApiConfig;
41
use Spryker\Shared\Price\PriceConfig;
42
use Spryker\Shared\Shipment\ShipmentConfig;
43
use Spryker\Zed\Cart\Business\CartFacadeInterface;
44
use Spryker\Zed\Customer\Business\CustomerFacadeInterface;
45
use Spryker\Zed\Store\Business\StoreFacadeInterface;
46
use SprykerTest\Glue\Testify\Tester\ApiEndToEndTester;
47
48
/**
49
 * Inherited Methods
50
 *
51
 * @method void wantToTest($text)
52
 * @method void wantTo($text)
53
 * @method void execute($callable)
54
 * @method void expectTo($prediction)
55
 * @method void expect($prediction)
56
 * @method void amGoingTo($argumentation)
57
 * @method void am($role)
58
 * @method void lookForwardTo($achieveValue)
59
 * @method void comment($description)
60
 * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
61
 *
62
 * @SuppressWarnings(\PyzTest\Glue\Checkout\PHPMD)
63
 */
64
class CheckoutApiTester extends ApiEndToEndTester
65
{
66
    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...
67
68
    /**
69
     * @var string
70
     */
71
    protected const REQUEST_PARAM_PAYMENT_METHOD_NAME_INVOICE = 'Invoice';
72
73
    /**
74
     * @var string
75
     */
76
    protected const REQUEST_PARAM_PAYMENT_PROVIDER_NAME_DUMMY_PAYMENT = 'DummyPayment';
77
78
    /**
79
     * @var string
80
     */
81
    protected const QUOTE_ITEM_OVERRIDE_DATA_PRODUCT = 'product';
82
83
    /**
84
     * @var string
85
     */
86
    protected const QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT = 'shipment';
87
88
    /**
89
     * @var string
90
     */
91
    protected const QUOTE_ITEM_OVERRIDE_DATA_QUANTITY = 'quantity';
92
93
    /**
94
     * @var int
95
     */
96
    protected const DEFAULT_QUOTE_ITEM_QUANTITY = 10;
97
98
    /**
99
     * @return void
100
     */
101
    public function assertCheckoutResponseResourceHasCorrectData(): void
102
    {
103
        $this->amSure('The returned resource id should be null')
104
            ->whenI()
105
            ->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

105
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo('');
Loading history...
106
107
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
108
109
        $this->assertNotEmpty(
110
            $attributes[RestCheckoutResponseTransfer::ORDER_REFERENCE],
111
            'The returned resource attributes order reference should not be empty',
112
        );
113
        $this->assertArrayHasKey(
114
            RestCheckoutResponseTransfer::IS_EXTERNAL_REDIRECT,
115
            $attributes,
116
            'The returned resource attributes should have an external redirect key',
117
        );
118
        $this->assertArrayHasKey(
119
            RestCheckoutResponseTransfer::REDIRECT_URL,
120
            $attributes,
121
            'The returned resource attributes should have a redirect URL key',
122
        );
123
    }
124
125
    /**
126
     * @return void
127
     */
128
    public function assertCheckoutDataResponseResourceHasCorrectData(): void
129
    {
130
        $this->amSure('The returned resource id should be null')
131
            ->whenI()
132
            ->seeSingleResourceIdEqualTo('');
133
134
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
135
136
        $this->assertEmpty(
137
            $attributes[RestCheckoutDataTransfer::ADDRESSES],
138
            'The returned resource attributes addresses should be an empty array',
139
        );
140
    }
141
142
    /**
143
     * @param int $price
144
     *
145
     * @return void
146
     */
147
    public function assertShipmentExpensesHaveCorrectPrice(int $price): void
148
    {
149
        $this->amSure('The returned resource should have included orders resource')
150
            ->whenI()
151
            ->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

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