Merge pull request #7500 from lchrusciel/refactor-api-checkout

[API] [Checkout] Remove email from address type
This commit is contained in:
Paweł Jędrzejewski 2017-02-14 14:45:16 +01:00 committed by GitHub
commit 3cf394017f
17 changed files with 378 additions and 314 deletions

View file

@ -0,0 +1,64 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\ApiBundle\Form\Type;
use Sylius\Bundle\AddressingBundle\Form\Type\AddressType as SyliusAddressType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Validator\Constraints\Valid;
/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
final class AddressType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('shippingAddress', SyliusAddressType::class, [
'shippable' => true,
'constraints' => [new Valid()],
])
->add('billingAddress', SyliusAddressType::class, [
'constraints' => [new Valid()],
])
->add('differentBillingAddress', CheckboxType::class, [
'mapped' => false,
'required' => false,
'label' => 'sylius.form.checkout.addressing.different_billing_address',
])
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
$orderData = $event->getData();
if (isset($orderData['shippingAddress']) && (!isset($orderData['differentBillingAddress']) || false === $orderData['differentBillingAddress'])) {
$orderData['billingAddress'] = $orderData['shippingAddress'];
$event->setData($orderData);
}
})
;
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'sylius_api_checkout_address';
}
}

View file

@ -17,7 +17,7 @@ sylius_api_checkout_addressing:
_controller: sylius.controller.order:updateAction
_sylius:
serialization_version: $version
form: Sylius\Bundle\CoreBundle\Form\Type\Checkout\AddressType
form: Sylius\Bundle\ApiBundle\Form\Type\AddressType
repository:
method: find
arguments: [$orderId]

View file

@ -52,6 +52,11 @@
<service id="sylius.form.type.api_product_variant" class="Sylius\Bundle\ApiBundle\Form\Type\ProductVariantType">
<tag name="form.type" />
</service>
<service id="sylius.form.type.api_checkout_address" class="Sylius\Bundle\ApiBundle\Form\Type\AddressType">
<tag name="form.type" />
</service>
<service id="sylius.form.extension.type.api_order_item" class="Sylius\Bundle\ApiBundle\Form\Type\OrderItemType">
<argument type="service" id="sylius.repository.product_variant" />
<tag name="form.type" />

View file

@ -45,45 +45,25 @@ final class CheckoutAddressingApiTest extends CheckoutApiTestCase
$this->assertResponseCode($response, Response::HTTP_NOT_FOUND);
}
/**
* @test
*/
public function it_does_not_allow_to_address_order_without_specifying_customer_email()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/addressing_invalid_customer', Response::HTTP_BAD_REQUEST);
}
/**
* @test
*/
public function it_does_not_allow_to_address_order_without_specifying_shipping_address()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$data =
<<<EOT
{
"different_billing_address": false,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": false
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/addressing_validation_failed_shipping_address', Response::HTTP_BAD_REQUEST);
@ -96,10 +76,10 @@ EOT;
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$data =
<<<EOT
@ -112,14 +92,11 @@ EOT;
"city": "s-Hertogenbosch",
"postcode": "99-999"
},
"different_billing_address": false,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": false
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
@ -133,10 +110,10 @@ EOT;
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$this->loadFixturesFromFile('resources/customers.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$data =
<<<EOT
@ -149,14 +126,11 @@ EOT;
"city": "s-Hertogenbosch",
"postcode": "99-999"
},
"different_billing_address": true,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": true
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/addressing_validation_failed_billing_address', Response::HTTP_BAD_REQUEST);
@ -169,10 +143,10 @@ EOT;
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$data =
<<<EOT
@ -193,19 +167,16 @@ EOT;
"city": "Groot Zundert",
"postcode": "88-888"
},
"different_billing_address": true,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": true
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
$this->client->request('GET', $this->getCheckoutSummaryUrl($cart), [], [], static::$authorizedHeaderWithAccept);
$this->client->request('GET', $this->getCheckoutSummaryUrl($cartId), [], [], static::$authorizedHeaderWithAccept);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/addressed_order_response');
@ -218,10 +189,10 @@ EOT;
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$data =
<<<EOT
@ -234,14 +205,11 @@ EOT;
"city": "Groot Zundert",
"postcode": "88-888"
},
"different_billing_address": false,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": false
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$newData =
<<<EOT
@ -254,14 +222,11 @@ EOT;
"city": "s-Hertogenbosch",
"postcode": "99-999"
},
"different_billing_address": false,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": false
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $newData);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $newData);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
@ -274,10 +239,10 @@ EOT;
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$addressData =
<<<EOT
@ -290,16 +255,13 @@ EOT;
"city": "Groot Zundert",
"postcode": "88-888"
},
"different_billing_address": false,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": false
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $addressData);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $addressData);
$this->selectOrderShippingMethod($cart);
$this->selectOrderShippingMethod($cartId);
$newAddressData =
<<<EOT
@ -312,14 +274,11 @@ EOT;
"city": "s-Hertogenbosch",
"postcode": "99-999"
},
"different_billing_address": false,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": false
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $newAddressData);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $newAddressData);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
@ -332,10 +291,10 @@ EOT;
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/countries.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$addressData =
<<<EOT
@ -348,17 +307,14 @@ EOT;
"city": "Groot Zundert",
"postcode": "88-888"
},
"different_billing_address": false,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": false
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $addressData);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $addressData);
$this->selectOrderShippingMethod($cart);
$this->selectOrderPaymentMethod($cart);
$this->selectOrderShippingMethod($cartId);
$this->selectOrderPaymentMethod($cartId);
$newAddressData =
<<<EOT
@ -371,26 +327,23 @@ EOT;
"city": "s-Hertogenbosch",
"postcode": "99-999"
},
"different_billing_address": false,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": false
}
EOT;
$this->client->request('PUT', $this->getAddressingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $newAddressData);
$this->client->request('PUT', $this->getAddressingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $newAddressData);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
}
/**
* @param OrderInterface $cart
* @param mixed $cartId
*
* @return string
*/
private function getAddressingUrl(OrderInterface $cart)
private function getAddressingUrl($cartId)
{
return sprintf('/api/v1/checkouts/addressing/%d', $cart->getId());
return sprintf('/api/v1/checkouts/addressing/%d', $cartId);
}
}

View file

@ -38,9 +38,49 @@ class CheckoutApiTestCase extends JsonApiTestCase
];
/**
* @param OrderInterface $order
* @return mixed
*/
protected function addressOrder(OrderInterface $order)
protected function createCart()
{
$data =
<<<EOT
{
"customer": "oliver.queen@star-city.com",
"channel": "CHANNEL",
"locale_code": "en_US"
}
EOT;
$this->client->request('POST', '/api/v1/carts/', [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$rawResponse = json_decode($response->getContent(), true);
return $rawResponse['id'];
}
/**
* @param mixed $cartId
*/
protected function addItemToCart($cartId)
{
$url = sprintf('/api/v1/carts/%d/items/', $cartId);
$data =
<<<EOT
{
"variant": "MUG_SW",
"quantity": 1
}
EOT;
$this->client->request('POST', $url, [], [], static::$authorizedHeaderWithContentType, $data);
}
/**
* @param mixed $cartId
*/
protected function addressOrder($cartId)
{
$this->loadFixturesFromFile('resources/countries.yml');
@ -63,23 +103,20 @@ class CheckoutApiTestCase extends JsonApiTestCase
"city": "Groot Zundert",
"postcode": "88-888"
},
"different_billing_address": true,
"customer": {
"email": "john@doe.com"
}
"different_billing_address": true
}
EOT;
$url = sprintf('/api/v1/checkouts/addressing/%d', $order->getId());
$url = sprintf('/api/v1/checkouts/addressing/%d', $cartId);
$this->client->request('PUT', $url, [], [], static::$authorizedHeaderWithContentType, $data);
}
/**
* @param OrderInterface $order
* @param mixed $cartId
*/
protected function selectOrderShippingMethod(OrderInterface $order)
protected function selectOrderShippingMethod($cartId)
{
$url = sprintf('/api/v1/checkouts/select-shipping/%d', $order->getId());
$url = sprintf('/api/v1/checkouts/select-shipping/%d', $cartId);
$this->client->request('GET', $url, [], [], static::$authorizedHeaderWithContentType);
@ -101,11 +138,11 @@ EOT;
}
/**
* @param OrderInterface $order
* @param mixed $cartId
*/
protected function selectOrderPaymentMethod(OrderInterface $order)
protected function selectOrderPaymentMethod($cartId)
{
$url = sprintf('/api/v1/checkouts/select-payment/%d', $order->getId());
$url = sprintf('/api/v1/checkouts/select-payment/%d', $cartId);
$this->client->request('GET', $url, [], [], static::$authorizedHeaderWithContentType);
@ -127,12 +164,12 @@ EOT;
}
/**
* @param OrderInterface $cart
* @param mixed $cartId
*
* @return string
*/
protected function getCheckoutSummaryUrl(OrderInterface $cart)
protected function getCheckoutSummaryUrl($cartId)
{
return sprintf('/api/v1/checkouts/%d', $cart->getId());
return sprintf('/api/v1/checkouts/%d', $cartId);
}
}

View file

@ -51,15 +51,14 @@ final class CheckoutCompleteApiTest extends CheckoutApiTestCase
public function it_does_not_allow_to_complete_order_that_is_not_addressed_and_has_no_shipping_and_payment_method_selected()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->selectOrderShippingMethod($cartId);
$this->addressOrder($cart);
$this->selectOrderShippingMethod($cart);
$this->client->request('PUT', $this->getCheckoutCompleteUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('PUT', $this->getCheckoutCompleteUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/complete_invalid_order_state', Response::HTTP_INTERNAL_SERVER_ERROR);
@ -71,33 +70,32 @@ final class CheckoutCompleteApiTest extends CheckoutApiTestCase
public function it_allows_to_complete_order_that_is_addressed_and_has_shipping_and_payment_method_selected()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->selectOrderShippingMethod($cartId);
$this->selectOrderPaymentMethod($cartId);
$this->addressOrder($cart);
$this->selectOrderShippingMethod($cart);
$this->selectOrderPaymentMethod($cart);
$this->client->request('PUT', $this->getCheckoutCompleteUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('PUT', $this->getCheckoutCompleteUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
$this->client->request('GET', $this->getCheckoutSummaryUrl($cart), [], [], static::$authorizedHeaderWithAccept);
$this->client->request('GET', $this->getCheckoutSummaryUrl($cartId), [], [], static::$authorizedHeaderWithAccept);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/completed_order_response');
}
/**
* @param OrderInterface $cart
* @param mixed $cartId
*
* @return string
*/
private function getCheckoutCompleteUrl(OrderInterface $cart)
private function getCheckoutCompleteUrl($cartId)
{
return sprintf('/api/v1/checkouts/complete/%d', $cart->getId());
return sprintf('/api/v1/checkouts/complete/%d', $cartId);
}
}

View file

@ -51,14 +51,13 @@ final class CheckoutPaymentApiTest extends CheckoutApiTestCase
public function it_does_not_allow_to_select_payment_for_order_that_is_not_addressed_and_has_no_shipping_method_selected()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->addressOrder($cart);
$this->client->request('PATCH', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('PATCH', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/payment_invalid_order_state', Response::HTTP_INTERNAL_SERVER_ERROR);
@ -70,13 +69,12 @@ final class CheckoutPaymentApiTest extends CheckoutApiTestCase
public function it_does_not_allow_to_select_unexisting_payment_method()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$this->addressOrder($cart);
$this->selectOrderShippingMethod($cart);
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->selectOrderShippingMethod($cartId);
$data =
<<<EOT
@ -89,7 +87,7 @@ final class CheckoutPaymentApiTest extends CheckoutApiTestCase
}
EOT;
$this->client->request('PUT', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
@ -102,15 +100,14 @@ EOT;
public function it_provides_details_about_available_payment_methods()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->selectOrderShippingMethod($cartId);
$this->addressOrder($cart);
$this->selectOrderShippingMethod($cart);
$this->client->request('GET', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/get_available_payment_methods', Response::HTTP_OK);
@ -122,12 +119,12 @@ EOT;
public function it_does_not_provide_details_about_available_payment_methods_before_addressing()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->client->request('GET', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/get_available_payment_methods_failed', Response::HTTP_BAD_REQUEST);
@ -139,14 +136,13 @@ EOT;
public function it_does_not_provide_details_about_available_payment_methods_before_choosing_shipping_method()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->addressOrder($cart);
$this->client->request('GET', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/get_available_payment_methods_failed', Response::HTTP_BAD_REQUEST);
@ -158,17 +154,14 @@ EOT;
public function it_allows_to_select_payment_method_for_order()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
/** @var PaymentMethodInterface $paymentMethod */
$paymentMethod = $checkoutData['cash_on_delivery'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->selectOrderShippingMethod($cartId);
$this->addressOrder($cart);
$this->selectOrderShippingMethod($cart);
$this->client->request('GET', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$rawResponse = json_decode($response->getContent(), true);
@ -184,12 +177,12 @@ EOT;
}
EOT;
$this->client->request('PUT', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
$this->client->request('GET', $this->getCheckoutSummaryUrl($cart), [], [], static::$authorizedHeaderWithAccept);
$this->client->request('GET', $this->getCheckoutSummaryUrl($cartId), [], [], static::$authorizedHeaderWithAccept);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/payment_selected_order_response');
@ -201,16 +194,15 @@ EOT;
public function it_allows_to_change_payment_method_after_its_already_been_chosen()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->selectOrderShippingMethod($cartId);
$this->selectOrderPaymentMethod($cartId);
$this->addressOrder($cart);
$this->selectOrderShippingMethod($cart);
$this->selectOrderPaymentMethod($cart);
$this->client->request('GET', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$rawResponse = json_decode($response->getContent(), true);
@ -226,7 +218,7 @@ EOT;
}
EOT;
$this->client->request('PUT', $this->getSelectPaymentUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getSelectPaymentUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
@ -234,12 +226,12 @@ EOT;
}
/**
* @param OrderInterface $cart
* @param mixed $cartId
*
* @return string
*/
private function getSelectPaymentUrl(OrderInterface $cart)
private function getSelectPaymentUrl($cartId)
{
return sprintf('/api/v1/checkouts/select-payment/%d', $cart->getId());
return sprintf('/api/v1/checkouts/select-payment/%d', $cartId);
}
}

View file

@ -51,15 +51,15 @@ final class CheckoutShippingApiTest extends CheckoutApiTestCase
public function it_does_not_allow_to_select_shipping_for_order_that_is_not_addressed()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->client->request('PUT', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('PUT', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/shipping_invalid_order_state', Response::HTTP_INTERNAL_SERVER_ERROR);
$this->assertResponse($response, 'checkout/shipping_invalid_order_state', Response::HTTP_BAD_REQUEST);
}
/**
@ -67,8 +67,17 @@ final class CheckoutShippingApiTest extends CheckoutApiTestCase
*/
public function it_does_not_allow_to_select_shipping_for_order_without_specifying_shipping_method()
{
// TO-DO
// feature cannot be tested properly due to bug with cascade shipments validation
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->client->request('PUT', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/shipping_invalid_order_state', Response::HTTP_BAD_REQUEST);
}
/**
@ -90,14 +99,13 @@ final class CheckoutShippingApiTest extends CheckoutApiTestCase
public function it_provides_details_about_available_shipping_method()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->addressOrder($cart);
$this->client->request('GET', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/get_available_shipping_methods', Response::HTTP_OK);
@ -109,12 +117,12 @@ final class CheckoutShippingApiTest extends CheckoutApiTestCase
public function it_does_not_provide_details_about_available_shipping_method_before_addressing()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->client->request('GET', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/get_available_shipping_methods_failed', Response::HTTP_BAD_REQUEST);
@ -126,12 +134,11 @@ final class CheckoutShippingApiTest extends CheckoutApiTestCase
public function it_does_not_allow_to_select_unexisting_shipping_method()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$this->addressOrder($cart);
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$data =
<<<EOT
@ -144,7 +151,7 @@ final class CheckoutShippingApiTest extends CheckoutApiTestCase
}
EOT;
$this->client->request('PUT', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/shipping_validation_failed', Response::HTTP_BAD_REQUEST);
@ -156,14 +163,13 @@ EOT;
public function it_allows_to_select_shipping_method_for_order()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->addressOrder($cart);
$this->client->request('GET', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$rawResponse = json_decode($response->getContent(), true);
@ -179,12 +185,12 @@ EOT;
}
EOT;
$this->client->request('PUT', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
$this->client->request('GET', $this->getCheckoutSummaryUrl($cart), [], [], static::$authorizedHeaderWithAccept);
$this->client->request('GET', $this->getCheckoutSummaryUrl($cartId), [], [], static::$authorizedHeaderWithAccept);
$response = $this->client->getResponse();
$this->assertResponse($response, 'checkout/shipping_selected_order_response');
@ -196,15 +202,14 @@ EOT;
public function it_allows_to_change_order_shipping_method_after_its_already_been_chosen()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->selectOrderShippingMethod($cartId);
$this->addressOrder($cart);
$this->selectOrderShippingMethod($cart);
$this->client->request('GET', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$rawResponse = json_decode($response->getContent(), true);
@ -220,7 +225,7 @@ EOT;
}
EOT;
$this->client->request('PUT', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
@ -232,16 +237,15 @@ EOT;
public function it_allows_to_change_order_shipping_method_after_selecting_payment_method()
{
$this->loadFixturesFromFile('authentication/api_administrator.yml');
$checkoutData = $this->loadFixturesFromFile('resources/checkout.yml');
$this->loadFixturesFromFile('resources/checkout.yml');
/** @var OrderInterface $cart */
$cart = $checkoutData['order1'];
$cartId = $this->createCart();
$this->addItemToCart($cartId);
$this->addressOrder($cartId);
$this->selectOrderShippingMethod($cartId);
$this->selectOrderPaymentMethod($cartId);
$this->addressOrder($cart);
$this->selectOrderShippingMethod($cart);
$this->selectOrderPaymentMethod($cart);
$this->client->request('GET', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType);
$this->client->request('GET', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType);
$response = $this->client->getResponse();
$rawResponse = json_decode($response->getContent(), true);
@ -257,19 +261,19 @@ EOT;
}
EOT;
$this->client->request('PUT', $this->getSelectShippingUrl($cart), [], [], static::$authorizedHeaderWithContentType, $data);
$this->client->request('PUT', $this->getSelectShippingUrl($cartId), [], [], static::$authorizedHeaderWithContentType, $data);
$response = $this->client->getResponse();
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
}
/**
* @param OrderInterface $cart
* @param mixed $cartId
*
* @return string
*/
private function getSelectShippingUrl(OrderInterface $cart)
private function getSelectShippingUrl($cartId)
{
return sprintf('/api/v1/checkouts/select-shipping/%d', $cart->getId());
return sprintf('/api/v1/checkouts/select-shipping/%d', $cartId);
}
}

View file

@ -1,21 +1,3 @@
Sylius\Component\Core\Model\Order:
order1:
channel: "@channel"
currencyCode: "EUR"
addItem: ["@orderItem1"]
localeCode: "en_US"
Sylius\Component\Core\Model\OrderItem:
orderItem1:
quantity: 1
unitPrice: 2000
addUnit: ["@orderItemUnit1"]
variant: "@productVariant1"
Sylius\Component\Core\Model\OrderItemUnit:
orderItemUnit1:
__construct: ["@orderItem1"]
Sylius\Component\Core\Model\Channel:
channel:
code: "CHANNEL"
@ -30,46 +12,53 @@ Sylius\Component\Core\Model\Channel:
currencies: ["@currency"]
Sylius\Component\Core\Model\Product:
product1:
updatedAt: 2015-10-10
mug:
code: MUG
channels: ["@channel"]
currentLocale: en_US
currentTranslation: "@productTranslation1"
variants: ["@productVariant1"]
code: MUG_SW
product2:
updatedAt: 2015-10-04
currentLocale: en_US
currentTranslation: "@productTranslation2"
variants: ["@productVariant2"]
code: MUG_LOTR
currentTranslation: "@mug_translation"
Sylius\Component\Core\Model\ProductTranslation:
productTranslation1:
slug: mug-star-wars
mug_translation:
slug: mug
locale: en_US
name: 'Star wars mug'
name: 'Mug'
description: <paragraph(2)>
translatable: "@product1"
productTranslation2:
slug: mug-lotr
locale: en_US
name: 'Lotr mug'
description: <paragraph(2)>
translatable: "@product2"
translatable: "@mug"
Sylius\Component\Core\Model\ProductVariant:
productVariant1:
code: MUG_1
channelPricings: ["@channelPricing1"]
productVariant2:
code: MUG_2
channelPricings: ["@channelPricing2"]
mug_sw:
code: MUG_SW
product: "@mug"
currentLocale: en_US
currentTranslation: "@sw_mug_translation"
updatedAt: 2015-10-10
channelPricings: ["@sw_mug_web_channel_pricing"]
hard_available_mug:
code: HARD_AVAILABLE_MUG
product: "@mug"
currentLocale: en_US
currentTranslation: "@hard_available_mug_translation"
updatedAt: 2015-10-05
channelPricings: ["@hard_available_mug_web_channel_pricing"]
tracked: true
onHand: 2
Sylius\Component\Product\Model\ProductVariantTranslation:
sw_mug_translation:
locale: en_US
name: 'Star wars mug'
translatable: "@mug_sw"
hard_available_mug_translation:
locale: en_US
name: 'Breaking bad mug'
translatable: "@hard_available_mug"
Sylius\Component\Core\Model\ChannelPricing:
channelPricing1:
sw_mug_web_channel_pricing:
channel: "@channel"
price: 20
channelPricing2:
hard_available_mug_web_channel_pricing:
channel: "@channel"
price: 20
@ -151,3 +140,11 @@ Sylius\Component\Addressing\Model\Zone:
Sylius\Component\Addressing\Model\ZoneMember:
member_{NL, BE}:
code: <current()>
Sylius\Component\Core\Model\Customer:
customer_oliver:
firstName: Oliver
lastName: Queen
email: oliver.queen@star-city.com
emailCanonical: oliver.queen@star-city.com
birthday: <date()>

View file

@ -8,8 +8,11 @@
"state": "cart",
"customer": {
"id": @integer@,
"email": "john@doe.com",
"email_canonical": "john@doe.com",
"email": "oliver.queen@star-city.com",
"email_canonical": "oliver.queen@star-city.com",
"first_name": "Oliver",
"last_name": "Queen",
"birthday": "@string@.isDateTime()",
"gender": "u",
"_links": {
"self": {

View file

@ -75,16 +75,7 @@
}
}
},
"differentBillingAddress": {},
"customer": {
"children": {
"email": {
"errors": [
"Please enter your email."
]
}
}
}
"differentBillingAddress": {}
}
}
}

View file

@ -52,12 +52,7 @@
}
}
},
"differentBillingAddress": {},
"customer": {
"children": {
"email": {}
}
}
"differentBillingAddress": {}
}
}
}

View file

@ -75,12 +75,7 @@
}
}
},
"differentBillingAddress": {},
"customer": {
"children": {
"email": {}
}
}
"differentBillingAddress": {}
}
}
}

View file

@ -10,8 +10,11 @@
"state": "new",
"customer": {
"id": @integer@,
"email": "john@doe.com",
"email_canonical": "john@doe.com",
"email": "oliver.queen@star-city.com",
"email_canonical": "oliver.queen@star-city.com",
"first_name": "Oliver",
"last_name": "Queen",
"birthday": "@string@.isDateTime()",
"gender": "u",
"_links": {
"self": {

View file

@ -8,8 +8,11 @@
"state": "cart",
"customer": {
"id": @integer@,
"email": "john@doe.com",
"email_canonical": "john@doe.com",
"email": "oliver.queen@star-city.com",
"email_canonical": "oliver.queen@star-city.com",
"first_name": "Oliver",
"last_name": "Queen",
"birthday": "@string@.isDateTime()",
"gender": "u",
"_links": {
"self": {

View file

@ -1,4 +1,25 @@
{
"code": 500,
"message": "Transition \"select_shipping\" cannot be applied on state \"cart\" of object \"Sylius\\Component\\Core\\Model\\Order\" with graph \"sylius_order_checkout\""
"code": 400,
"message": "Validation Failed",
"errors": {
"children": {
"shipments": {
"children": [
{
"children": {
"method": {
"errors": [
"Please select shipping method."
],
"children": [
{},
{}
]
}
}
}
]
}
}
}
}

View file

@ -8,8 +8,11 @@
"state": "cart",
"customer": {
"id": @integer@,
"email": "john@doe.com",
"email_canonical": "john@doe.com",
"email": "oliver.queen@star-city.com",
"email_canonical": "oliver.queen@star-city.com",
"first_name": "Oliver",
"last_name": "Queen",
"birthday": "@string@.isDateTime()",
"gender": "u",
"_links": {
"self": {