solidus_api 2.9.6 → 2.10.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_api might be problematic. Click here for more details.

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -0
  3. data/app/controllers/spree/api/addresses_controller.rb +1 -1
  4. data/app/controllers/spree/api/checkouts_controller.rb +4 -17
  5. data/app/controllers/spree/api/credit_cards_controller.rb +1 -1
  6. data/app/controllers/spree/api/images_controller.rb +1 -1
  7. data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
  8. data/app/controllers/spree/api/option_types_controller.rb +1 -1
  9. data/app/controllers/spree/api/option_values_controller.rb +1 -1
  10. data/app/controllers/spree/api/orders_controller.rb +1 -7
  11. data/app/controllers/spree/api/payments_controller.rb +1 -1
  12. data/app/controllers/spree/api/product_properties_controller.rb +1 -1
  13. data/app/controllers/spree/api/properties_controller.rb +1 -1
  14. data/app/controllers/spree/api/resource_controller.rb +1 -1
  15. data/app/controllers/spree/api/return_authorizations_controller.rb +1 -1
  16. data/app/controllers/spree/api/shipments_controller.rb +1 -1
  17. data/app/controllers/spree/api/stock_items_controller.rb +1 -1
  18. data/app/controllers/spree/api/stock_locations_controller.rb +1 -1
  19. data/app/controllers/spree/api/stores_controller.rb +1 -1
  20. data/app/controllers/spree/api/taxonomies_controller.rb +1 -1
  21. data/app/controllers/spree/api/taxons_controller.rb +1 -1
  22. data/app/controllers/spree/api/variants_controller.rb +1 -1
  23. data/app/controllers/spree/api/zones_controller.rb +1 -1
  24. data/app/helpers/spree/api/api_helpers.rb +1 -1
  25. data/app/views/spree/api/shared/_pagination.json.jbuilder +1 -1
  26. data/lib/spree/api/config.rb +9 -0
  27. data/lib/spree/api/engine.rb +4 -4
  28. data/lib/spree/api/responders.rb +1 -0
  29. data/lib/spree/api.rb +0 -7
  30. data/{app/models → lib}/spree/api_configuration.rb +0 -0
  31. data/openapi/.stoplight.yml +7 -0
  32. data/openapi/api.oas2.yml +6107 -0
  33. data/openapi/authentication.md +25 -0
  34. data/openapi/checkout-flow.md +50 -0
  35. data/openapi/errors.md +3 -0
  36. data/openapi/lint.yml +1 -0
  37. data/openapi/main.hub.yml +65 -0
  38. data/openapi/pagination.md +7 -0
  39. data/openapi/theme.css +0 -0
  40. data/spec/requests/spree/api/checkouts_controller_spec.rb +5 -33
  41. data/spec/requests/spree/api/classifications_controller_spec.rb +1 -1
  42. data/spec/requests/spree/api/orders_controller_spec.rb +3 -26
  43. data/spec/requests/spree/api/payments_controller_spec.rb +3 -3
  44. data/spec/requests/spree/api/stock_items_controller_spec.rb +5 -5
  45. data/spec/requests/spree/api/stock_locations_controller_spec.rb +4 -4
  46. metadata +16 -6
@@ -0,0 +1,25 @@
1
+ # Authentication
2
+
3
+ The Solidus API provides two means of authentication: one is through your Solidus user's API key, while the other is through an order's guest token.
4
+
5
+ ### API key
6
+
7
+ You can use your API key to access all resources in the API. The API key must be passed in the `Authorization` header in the following form:
8
+
9
+ ```
10
+ Authorization: Bearer API_KEY
11
+ ```
12
+
13
+ By default, API keys are only generated for admins, but you can easily customize Solidus to generate them for all users, which is useful for instance if you want users to be able to sign in and manage their profile via the API.
14
+
15
+ ### Order token
16
+
17
+ For allowing guests to manage their cart and place their order, you can use the order's guest token. This token is contained in the `guest_token` property of the order, and it allows you to perform certain checkout-related operations on the order such as managing line items, completing the checkout flow etc.
18
+
19
+ The order token must be passed in the `X-Spree-Order-Token` header in the following form:
20
+
21
+ ```
22
+ X-Spree-Order-Token: ORDER_TOKEN
23
+ ```
24
+
25
+ If you are already providing an API key, you don't need to also provide the order token (although you may do so).
@@ -0,0 +1,50 @@
1
+ # Checkout flow
2
+
3
+ Given the amount of endpoints at your disposal, it can be difficult to understand how to string the right API calls together to perform a full checkout flow. This document explains how to perform a full checkout flow.
4
+
5
+ ## 1. Create an order
6
+
7
+ The first step is to create an order via `POST /orders`. You should save the number of the order that is created as well as the guest token, in case you are not authenticating with an API key.
8
+
9
+ ## 2. Fill the cart
10
+
11
+ Once you have an order, you can begin filling your cart. Here are some endpoints you can use for that:
12
+
13
+ - `POST /checkouts/:order_number/line_items`
14
+ - `PATCH /checkouts/:order_number/line_items/:id`
15
+ - `DELETE /checkouts/:order_number/line_items/:id`
16
+ - `PUT /orders/:order_number/empty`
17
+
18
+ ## 3. (Optional) Apply a coupon code
19
+
20
+ You can also apply a coupon code on the order via `POST /orders/:order_number/coupon_codes`.
21
+
22
+ ## 4. Start the checkout flow
23
+
24
+ When you are ready to start the checkout flow, you can call `PUT /checkouts/:order_number/next` to transition the order from the `cart` to the `address` state.
25
+
26
+ ## 5. Enter billing and shipping addresses
27
+
28
+ To enter the billing and shipping addresses, use the `PATCH /checkouts/:order_number` endpoint.
29
+
30
+ Once again, call `PUT /checkouts/:order_number/next` to transition the order from the `address` to the `shipping` state.
31
+
32
+ ## 6. Select a shipping method
33
+
34
+ You can retrieve the available shipping methods, along with their rates, via `GET /shipments/:shipment_number/estimated_rates`. This allows you to let your user choose the shipping method they prefer.
35
+
36
+ When you want to select a shipping method, call `PUT /shipments/:shipment_number/select_shipping_method`.
37
+
38
+ Finally, call `PUT /checkouts/:order_number/next` to transition the order from the `shipping` to the `payment` state.
39
+
40
+ ## 7. Enter payment details
41
+
42
+ To create a payment, call `POST /orders/:order_number/payments`.
43
+
44
+ Now call `PUT /checkouts/:order_number/next` to transition the order from the `payment` to the `confirm` state.
45
+
46
+ ## 8. Complete the order
47
+
48
+ At this point, you should show the user a summary of their cart and ask them to confirm they want to place the order.
49
+
50
+ When they confirm, call `PUT /checkouts/:order_number/complete` to complete the checkout flow and place the order!
data/openapi/errors.md ADDED
@@ -0,0 +1,3 @@
1
+ # Errors
2
+
3
+ Error responses for each endpoint are documented. When interacting with an endpoint, make sure to handle all possible errors appropriately.
data/openapi/lint.yml ADDED
@@ -0,0 +1 @@
1
+ rules: {}
@@ -0,0 +1,65 @@
1
+ title: Solidus API
2
+ logo: 'https://next.stoplight.io/images/mark-light-bg.png'
3
+ header:
4
+ nav:
5
+ left: []
6
+ right: []
7
+ pages:
8
+ /:
9
+ title: Welcome
10
+ data:
11
+ blocks:
12
+ - type: text
13
+ data: >-
14
+ # Solidus API
15
+
16
+
17
+ Welcome! This is the documentation for the
18
+ [Solidus](https://solidus.io) REST API.
19
+
20
+
21
+ This documentation refers to a stock installation of Solidus.
22
+ However, every store may customize their API in any number of ways,
23
+ so make sure to ensure the store you are working with conforms to
24
+ this documentation or refer to the store's own documentation for
25
+ interacting with the API.
26
+
27
+
28
+ Endpoints are grouped by the logical resource they interact with.
29
+ Note that some of the endpoints are duplicated, since the same
30
+ resource may be accessed at the root level or as the child of
31
+ another resource (e.g. you may access all variants or the variants
32
+ that belong to a specific product).
33
+ - type: text
34
+ data: ''
35
+ children:
36
+ - title: Authentication
37
+ route:
38
+ path: /authentication
39
+ data:
40
+ $ref: ./authentication.md
41
+ - title: Pagination
42
+ route:
43
+ path: /pagination
44
+ data:
45
+ $ref: ./pagination.md
46
+ - title: Errors
47
+ route:
48
+ path: /errors
49
+ data:
50
+ $ref: ./errors.md
51
+ - title: Checkout Flow
52
+ route:
53
+ path: /checkout-flow
54
+ data:
55
+ $ref: ./checkout-flow.md
56
+ config:
57
+ sidebar:
58
+ token: ''
59
+ - title: API Reference
60
+ config:
61
+ includeDownloadLink: true
62
+ route:
63
+ path: /api-reference
64
+ data:
65
+ $ref: ./api.oas2.yml
@@ -0,0 +1,7 @@
1
+ # Pagination
2
+
3
+ Most endpoints that return a collection are paginated. A paginated response contains metadata about the current page at the root level and the resources in the current page in a child key named after the resource (e.g. `orders`).
4
+
5
+ You can pass the `page` and `per_page` parameters to set the current page and the desired number of items per page. Note that the default and the maximum number of items per page is decided at the application level.
6
+
7
+ All pagination metadata is documented in the individual API endpoints, so take a look there if you're unsure what data you can expect.
data/openapi/theme.css ADDED
File without changes
@@ -172,7 +172,6 @@ module Spree
172
172
  end
173
173
 
174
174
  describe 'setting the payment amount' do
175
- let(:order) { create(:order_with_line_items, state: :payment) }
176
175
  let(:params) do
177
176
  {
178
177
  order_token: order.guest_token,
@@ -323,44 +322,17 @@ module Spree
323
322
  end
324
323
  end
325
324
 
326
- it "cannot update attributes of another step" do
327
- order.update_column(:state, "payment")
328
-
329
- params = {
330
- order_token: order.guest_token,
331
- order: {
332
- payments_attributes: [
333
- {
334
- payment_method_id: @payment_method.id.to_s,
335
- source_attributes: attributes_for(:credit_card)
336
- }
337
- ],
338
- ship_address_attributes: {
339
- zipcode: 'MALICIOUS ZIPCODE'
340
- }
341
- }
342
- }
343
- expect do
344
- put spree.api_checkout_path(order), params: params
345
- end.not_to change { order.reload.ship_address.zipcode }
346
- expect(response.status).to eq(200)
347
- end
348
-
349
325
  it "returns the order if the order is already complete" do
350
326
  order.update_columns(completed_at: Time.current, state: 'complete')
351
327
  put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
352
328
  assert_unauthorized!
353
329
  end
354
330
 
355
- context "in delivery state" do
356
- let(:order) { create(:order_with_line_items, state: :delivery) }
357
-
358
- # Regression test for https://github.com/spree/spree/issues/3784
359
- it "can update the special instructions for an order" do
360
- instructions = "Don't drop it. (Please)"
361
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { special_instructions: instructions } }
362
- expect(json_response['special_instructions']).to eql(instructions)
363
- end
331
+ # Regression test for https://github.com/spree/spree/issues/3784
332
+ it "can update the special instructions for an order" do
333
+ instructions = "Don't drop it. (Please)"
334
+ put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { special_instructions: instructions } }
335
+ expect(json_response['special_instructions']).to eql(instructions)
364
336
  end
365
337
 
366
338
  context "as an admin" do
@@ -39,7 +39,7 @@ module Spree
39
39
  end
40
40
 
41
41
  it "should touch the taxon" do
42
- taxon.update_attributes(updated_at: Time.current - 10.seconds)
42
+ taxon.update(updated_at: Time.current - 10.seconds)
43
43
  taxon_last_updated_at = taxon.updated_at
44
44
  put spree.api_classifications_path, params: { taxon_id: taxon.id, product_id: last_product.id, position: 0 }
45
45
  taxon.reload
@@ -156,7 +156,6 @@ module Spree
156
156
  end
157
157
 
158
158
  context 'creating payment' do
159
- let!(:order) { create(:order_with_line_items) }
160
159
  let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
161
160
 
162
161
  context "with allowed payment method" do
@@ -167,28 +166,6 @@ module Spree
167
166
  subject
168
167
  }.to change { Spree::Payment.count }.by(1)
169
168
  end
170
-
171
- context 'trying to change the address' do
172
- let(:order_params) do
173
- super().merge(
174
- ship_address_attributes: {
175
- zipcode: '90100'
176
- }
177
- )
178
- end
179
-
180
- it 'changes the address' do
181
- expect {
182
- subject
183
- }.to change { order.reload.ship_address.zipcode }
184
- end
185
-
186
- it 'invalidates the shipments' do
187
- expect {
188
- subject
189
- }.to change { order.reload.shipments }.to([])
190
- end
191
- end
192
169
  end
193
170
 
194
171
  context "with disallowed payment method" do
@@ -329,7 +306,7 @@ module Spree
329
306
 
330
307
  context 'when an item does not track inventory' do
331
308
  before do
332
- order.line_items.first.variant.update_attributes!(track_inventory: false)
309
+ order.line_items.first.variant.update!(track_inventory: false)
333
310
  end
334
311
 
335
312
  it 'contains stock information on variant' do
@@ -570,7 +547,7 @@ module Spree
570
547
  end
571
548
 
572
549
  it "can add shipping address" do
573
- order.update_attributes!(ship_address_id: nil)
550
+ order.update!(ship_address_id: nil)
574
551
 
575
552
  expect {
576
553
  put spree.api_order_path(order), params: { order: { ship_address_attributes: shipping_address } }
@@ -578,7 +555,7 @@ module Spree
578
555
  end
579
556
 
580
557
  it "receives error message if trying to add shipping address with errors" do
581
- order.update_attributes!(ship_address_id: nil)
558
+ order.update!(ship_address_id: nil)
582
559
 
583
560
  shipping_address[:firstname] = ""
584
561
 
@@ -137,7 +137,7 @@ module Spree
137
137
  context "for a given payment" do
138
138
  context "updating" do
139
139
  it "can update" do
140
- payment.update_attributes(state: 'pending')
140
+ payment.update(state: 'pending')
141
141
  put spree.api_order_payment_path(order, payment), params: { payment: { amount: 2.01 } }
142
142
  expect(response.status).to eq(200)
143
143
  expect(payment.reload.amount).to eq(2.01)
@@ -145,14 +145,14 @@ module Spree
145
145
 
146
146
  context "update fails" do
147
147
  it "returns a 422 status when the amount is invalid" do
148
- payment.update_attributes(state: 'pending')
148
+ payment.update(state: 'pending')
149
149
  put spree.api_order_payment_path(order, payment), params: { payment: { amount: 'invalid' } }
150
150
  expect(response.status).to eq(422)
151
151
  expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
152
152
  end
153
153
 
154
154
  it "returns a 403 status when the payment is not pending" do
155
- payment.update_attributes(state: 'completed')
155
+ payment.update(state: 'completed')
156
156
  put spree.api_order_payment_path(order, payment), params: { payment: { amount: 2.01 } }
157
157
  expect(response.status).to eq(403)
158
158
  expect(json_response["error"]).to eq("This payment cannot be updated because it is completed.")
@@ -25,7 +25,7 @@ module Spree
25
25
  end
26
26
 
27
27
  it "cannot list stock items for an inactive stock location" do
28
- stock_location.update_attributes!(active: false)
28
+ stock_location.update!(active: false)
29
29
  get spree.api_stock_location_stock_items_path(stock_location)
30
30
  expect(response).to be_not_found
31
31
  end
@@ -39,7 +39,7 @@ module Spree
39
39
  end
40
40
 
41
41
  it "cannot see a stock item for an inactive stock location" do
42
- stock_location.update_attributes!(active: false)
42
+ stock_location.update!(active: false)
43
43
  get spree.api_stock_location_stock_item_path(stock_location, stock_item)
44
44
  expect(response.status).to eq(404)
45
45
  end
@@ -155,7 +155,7 @@ module Spree
155
155
 
156
156
  context 'variant does not track inventory' do
157
157
  before do
158
- variant.update_attributes(track_inventory: false)
158
+ variant.update(track_inventory: false)
159
159
  end
160
160
 
161
161
  it "doesn't set the stock item's count_on_hand" do
@@ -221,7 +221,7 @@ module Spree
221
221
 
222
222
  context 'not tracking inventory' do
223
223
  before do
224
- stock_item.variant.update_attributes(track_inventory: false)
224
+ stock_item.variant.update(track_inventory: false)
225
225
  end
226
226
 
227
227
  it "doesn't set the stock item's count_on_hand" do
@@ -279,7 +279,7 @@ module Spree
279
279
 
280
280
  context 'not tracking inventory' do
281
281
  before do
282
- stock_item.variant.update_attributes(track_inventory: false)
282
+ stock_item.variant.update(track_inventory: false)
283
283
  end
284
284
 
285
285
  it "doesn't update the stock item's count_on_hand" do
@@ -21,7 +21,7 @@ module Spree
21
21
  end
22
22
 
23
23
  it "cannot see inactive stock locations" do
24
- stock_location.update_attributes!(active: false)
24
+ stock_location.update!(active: false)
25
25
  get spree.api_stock_locations_path
26
26
  expect(response).to be_successful
27
27
  stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
@@ -37,7 +37,7 @@ module Spree
37
37
  end
38
38
 
39
39
  it "cannot see inactive stock locations" do
40
- stock_location.update_attributes!(active: false)
40
+ stock_location.update!(active: false)
41
41
  get spree.api_stock_location_path(stock_location)
42
42
  expect(response).to be_not_found
43
43
  end
@@ -84,7 +84,7 @@ module Spree
84
84
  end
85
85
 
86
86
  it "can see inactive stock locations" do
87
- stock_location.update_attributes!(active: false)
87
+ stock_location.update!(active: false)
88
88
  get spree.api_stock_locations_path
89
89
  expect(response).to be_successful
90
90
  stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
@@ -122,7 +122,7 @@ module Spree
122
122
  end
123
123
 
124
124
  it "can see inactive stock locations" do
125
- stock_location.update_attributes!(active: false)
125
+ stock_location.update!(active: false)
126
126
  get spree.api_stock_location_path(stock_location)
127
127
  expect(response).to be_successful
128
128
  expect(json_response['name']).to eq stock_location.name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.6
4
+ version: 2.10.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-16 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.9.6
61
+ version: 2.10.0.beta1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.9.6
68
+ version: 2.10.0.beta1
69
69
  description: REST API for the Solidus e-commerce framework.
70
70
  email: contact@solidus.io
71
71
  executables: []
@@ -111,7 +111,6 @@ files:
111
111
  - app/controllers/spree/api/variants_controller.rb
112
112
  - app/controllers/spree/api/zones_controller.rb
113
113
  - app/helpers/spree/api/api_helpers.rb
114
- - app/models/spree/api_configuration.rb
115
114
  - app/views/.rubocop.yml
116
115
  - app/views/spree/api/address_books/show.json.jbuilder
117
116
  - app/views/spree/api/addresses/_address.json.jbuilder
@@ -230,13 +229,24 @@ files:
230
229
  - db/migrate/20131017162334_add_index_to_user_spree_api_key.rb
231
230
  - lib/solidus_api.rb
232
231
  - lib/spree/api.rb
232
+ - lib/spree/api/config.rb
233
233
  - lib/spree/api/engine.rb
234
234
  - lib/spree/api/responders.rb
235
235
  - lib/spree/api/responders/rabl_template.rb
236
236
  - lib/spree/api/testing_support/caching.rb
237
237
  - lib/spree/api/testing_support/helpers.rb
238
238
  - lib/spree/api/testing_support/setup.rb
239
+ - lib/spree/api_configuration.rb
239
240
  - lib/spree_api.rb
241
+ - openapi/.stoplight.yml
242
+ - openapi/api.oas2.yml
243
+ - openapi/authentication.md
244
+ - openapi/checkout-flow.md
245
+ - openapi/errors.md
246
+ - openapi/lint.yml
247
+ - openapi/main.hub.yml
248
+ - openapi/pagination.md
249
+ - openapi/theme.css
240
250
  - script/rails
241
251
  - solidus_api.gemspec
242
252
  - spec/controllers/spree/api/base_controller_spec.rb
@@ -309,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
309
319
  - !ruby/object:Gem::Version
310
320
  version: 1.8.23
311
321
  requirements: []
312
- rubygems_version: 3.0.3
322
+ rubygems_version: 3.0.6
313
323
  signing_key:
314
324
  specification_version: 4
315
325
  summary: REST API for the Solidus e-commerce framework.