Users should be able to set things like email, currency or any Order value not dependent on other objects.
curl -H 'X-Spree-Token: 123' -X POST http://localhost:9292/api/orders.json
api/orders.json should be the root path for creating the orders.
curl -H 'X-Spree-Token: 123' -H 'Content-Type: application/json' -X POST \
http://localhost:9292/api/orders/R886752482/line_items.json --data @./line_item.json
api/orders/:number/line_items.json could be default path for adding and updating items on the order.
{
"line_item": {
"variant_id": 1,
"quantity": 2
}
}
It could have a default route to move the order to the next state. Not sure about this. It should probably offer an option to move automatically as well like for example as the user provides an address it would move the order to next state.
curl -H 'X-Spree-Token: 123' -X PUT http://localhost:9292/api/checkouts/R886752482/next.json
api/orders/:number/next.json or api/checkout/:number/next.json could be the route for that.
Currently as you provide the order addresses it move the order to next step, defaults to delivery, automatically.
curl -H 'X-Spree-Token: 123' -H 'Content-Type: application/json' -X PUT \
http://localhost:9292/api/checkouts/R886752482 --data @./address.json
Not a big fan of using the same route for all checkout steps. Currently submitting a PUT to api/checkouts/:number makes it hard to build the json body as well as kind of lead us to things like accept nested params.
Propose we set up a new controller or use the existing api/addresses_controller and mount a route like api/orders/:number/addresses for providing addresses (apparently we do have a show and update action on that route.
Current addresses json example:
address.json
{
"order": {
"bill_address_attributes": {
"firstname": "Spree",
"lastname": "Commerce",
"address1": "1 Someplace Lane",
"address2": "Suite 1",
"city": "Bethesda",
"zipcode": "16804",
"phone": "123.4567.890",
"company": null,
"alternative_phone": null,
"state_name": null,
"country_id": 49,
"state_id": 48
},
"ship_address_attributes": {
"firstname": "Spree",
"lastname": "Commerce",
"address1": "1 Someplace Lane",
"address2": "Suite 1",
"city": "Bethesda",
"zipcode": "16804",
"phone": "123.4567.890",
"company": null,
"alternative_phone": null,
"state_name": null,
"country_id": 49,
"state_id": 48
}
}
}
Have always ignored this step on the api. Should take a deep closer look. Since spree currently always pick a shipping rate by default. One could get past this step by just.
curl -H 'X-Spree-Token: 123' -X PUT http://localhost:9292/api/checkouts/R886752482/next.json
Not sure about what route should look like yet. Only know for sure we shouldn't use something like PUT api/checkouts/:number for that. Perhaps api/orders/:number/shipments.json to fetch and POST api/orders/:number/shipping_rates.json for choosing a shipping rate makes moresense.
ps. Remember shipments are not created manually so maybe an endpoint for explicitly creating shipments would be great.