Sylius / ShopApiPlugin

Shop API for Sylius.
https://sylius.com
129 stars 89 forks source link

[HELP] - "Completing checkout" Endpoint - Unable to checkout an order. #675

Closed hasithaarimac closed 4 years ago

hasithaarimac commented 4 years ago

Hi All,

I'm having trouble with Completing checkout through shop API. I'm getting a validation error message even though I set a valid shipping and billing address to my order. (Error message: "Please provide the cart with a shipping and billing address") Please look at the following request and response.

CURL of the request

curl --location --request PUT 'http://{HOST}/shop-api/checkout/ed699a18-fc5d-4ba1-a7f0-4bcc87fa9500/complete' \
--header 'Content-Type: application/json' \
--header 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2MDE0NDQwNDksImV4cCI6MTYwMTQ0NzY0OSwicm9sZXMiOlsiUk9MRV9VU0VSIl0sInVzZXJuYW1lIjoiaGFzaXRoYUBxd2UuY29tIn0.b0fvbxDk1rfQ_pB20WYNVg8wRW17bF9FErneA-2Vy1Iz7flOcRjHbt-uSZrgms1_bBJ8YZUGXynIOTN0FfZT8Q' \
--data-raw '{
    "email": "hasitha@qwe.com",
    "notes": "test"
}'

Response body

"token": [
            "Please provide the cart with a shipping and billing address"
        ]

summarized cart details (Here we can see the shipping and billing address of the current cart. Its already set using "/checkout/:token/address" endpoint)

{
    "tokenValue": "ed699a18-fc5d-4ba1-a7f0-4bcc87fa9500",
    "channel": "FASHION_WEB",
    "currency": "USD",
    "locale": "en_US",
    "checkoutState": "shipping_skipped",
    "items": [
        {
            "id": 96,
            "quantity": 1,
            "total": 10000,
            "product": {
                "code": "my_new_product2",
                "name": "my product 2",
                "slug": "my-product-2",
                "channelCode": "FASHION_WEB",
                "averageRating": 0,
                "taxons": {
                    "others": []
                },
                "variants": [
                    {
                        "code": "product2_varient",
                        "name": "product2 Variant",
                        "axis": [
                            "t_shirt_size_s"
                        ],
                        "nameAxis": {
                            "t_shirt_size_s": "T-shirt size S"
                        },
                        "available": true,
                        "price": {
                            "current": 10000,
                            "currency": "USD"
                        },
                        "images": []
                    }
                ],
                "attributes": [],
                "associations": [],
                "images": [],
                "_links": {
                    "self": {
                        "href": "/shop-api/products/by-slug/my-product-2"
                    }
                }
            }
        }
    ],
    "totals": {
        "total": 10000,
        "items": 10000,
        "taxes": 0,
        "shipping": 0,
        "promotion": 0
    },
    "shippingAddress": {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "countryCode": "US",
        "street": "Baker Street 221b",
        "city": "London",
        "postcode": "NW1",
        "provinceName": "Greater London",
        "company": "Holmes Investigation Service",
        "phoneNumber": "+490000000000"
    },
    "billingAddress": {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "countryCode": "US",
        "street": "Baker Street 221b",
        "city": "London",
        "postcode": "NW1",
        "provinceName": "Greater London",
        "company": "Holmes Investigation Service",
        "phoneNumber": "+490000000000"
    },
    "payments": [
        {
            "state": "cart",
            "method": {
                "code": "bank_transfer",
                "name": "Bank transfer",
                "description": "Aut non est qui illo.",
                "instructions": ""
            },
            "price": {
                "current": 10000,
                "currency": "USD"
            }
        }
    ],
    "shipments": [],
    "cartDiscounts": []
}
mamazu commented 4 years ago

It is probably missing a payment-selection. Because the order is still in state "shipping_skipped"

diimpp commented 4 years ago

@hasithaarimac there is known problem with https://github.com/Sylius/ShopApiPlugin/blob/3ace12724f53c330d6b894fe2bbe639ecc140d76/src/Validator/Cart/CartReadyForCheckoutValidator.php#L47 validator.

Fix this line by changing getState() to getCheckoutState().

@mamazu this is reminder, that you have introduced this bug and it's not fixed yet. https://github.com/Sylius/ShopApiPlugin/issues/665 Consider doing revert, if you don't have time to fix it.

mamazu commented 4 years ago

Thanks for the reminder.

hasithaarimac commented 4 years ago

The checkout process works now!