spree_api 4.0.5 → 4.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eee4336e3cce0f5d5184fe32e8a5368667dfaf92e180dfdbbba25a37e3bd5b2c
4
- data.tar.gz: 6b89ed6f3f76d098d97986df9d59f2f5a6e31b4f393c6b742767336dff1976b3
3
+ metadata.gz: bb492da2ac5731707cc636e985a915489f9e8f7a1fe1e862fc5dd82cea7149ea
4
+ data.tar.gz: afac179a5eb83e3873b8a93f7f2a8b5f80ea96638f037d0c23fcbb89a476db01
5
5
  SHA512:
6
- metadata.gz: 8015d850adc187e86c89f2337f87c109900013f0b31a9c0d48d6c3a300eb09b9ef2cf85b9246274fb3a672d9ed024ee21a0ff85c8357daff61641b5e5df70ab1
7
- data.tar.gz: 525a1c127982b7f0fa5c0754c6d2da056d0f84a4215df49be3646a4ceb2e4507913a1ac02676d01e1fbdebbef268a4958f221ddcd839a6f803da6c8b9be9671f
6
+ metadata.gz: 922bb826d8866c0906c74d68ead4fd05e662889752f9e0f1fcacc390be79917cb252aa03a52896cb5131e791b8924db5e45906ec35754e0de4b5eb25deef78c1
7
+ data.tar.gz: 0df8a5b955761eadf596ad71e512b4ba9e56f3e79794ef78e02e248152b53edfc19180b71b32130c2325aeec4de06670a87feefb14a4b9c014df3dfdbcf01101
@@ -6,6 +6,7 @@ module Spree
6
6
  include Spree::Core::ControllerHelpers::StrongParameters
7
7
  rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
8
8
  rescue_from CanCan::AccessDenied, with: :access_denied
9
+ rescue_from Spree::Core::GatewayError, with: :gateway_error
9
10
 
10
11
  def content_type
11
12
  Spree::Api::Config[:api_v2_content_type]
@@ -120,6 +121,10 @@ module Spree
120
121
  def access_denied(exception)
121
122
  render_error_payload(exception.message, 403)
122
123
  end
124
+
125
+ def gateway_error(exception)
126
+ render_error_payload(exception.message)
127
+ end
123
128
  end
124
129
  end
125
130
  end
@@ -0,0 +1,77 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ module Account
6
+ class AddressesController < ::Spree::Api::V2::BaseController
7
+ before_action :require_spree_current_user
8
+
9
+ def index
10
+ render_serialized_payload { serialize_collection(collection) }
11
+ end
12
+
13
+ def create
14
+ result = create_service.call(user: spree_current_user, address_params: address_params)
15
+ render_result(result)
16
+ end
17
+
18
+ def update
19
+ result = update_service.call(address: resource, address_params: address_params)
20
+ render_result(result)
21
+ end
22
+
23
+ private
24
+
25
+ def collection
26
+ collection_finder.new(scope: scope, params: params).execute
27
+ end
28
+
29
+ def resource
30
+ @resource ||= scope.find(params[:id])
31
+ end
32
+
33
+ def scope
34
+ spree_current_user.addresses
35
+ end
36
+
37
+ def collection_finder
38
+ Spree::Api::Dependencies.storefront_address_finder.constantize
39
+ end
40
+
41
+ def collection_serializer
42
+ Spree::Api::Dependencies.storefront_address_serializer.constantize
43
+ end
44
+
45
+ def resource_serializer
46
+ Spree::Api::Dependencies.storefront_address_serializer.constantize
47
+ end
48
+
49
+ def serialize_collection(collection)
50
+ collection_serializer.new(collection).serializable_hash
51
+ end
52
+
53
+ def create_service
54
+ Spree::Api::Dependencies.storefront_account_create_address_service.constantize
55
+ end
56
+
57
+ def update_service
58
+ Spree::Api::Dependencies.storefront_account_update_address_service.constantize
59
+ end
60
+
61
+ def address_params
62
+ params.require(:address).permit(permitted_address_attributes)
63
+ end
64
+
65
+ def render_result(result)
66
+ if result.success?
67
+ render_serialized_payload { serialize_resource(result.value) }
68
+ else
69
+ render_error_payload(result.error)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -35,11 +35,11 @@ module Spree
35
35
  end
36
36
 
37
37
  def collection_serializer
38
- Spree::Api::Dependencies.storefront_cart_serializer.constantize
38
+ Spree::Api::Dependencies.storefront_order_serializer.constantize
39
39
  end
40
40
 
41
41
  def resource_serializer
42
- Spree::Api::Dependencies.storefront_cart_serializer.constantize
42
+ Spree::Api::Dependencies.storefront_order_serializer.constantize
43
43
  end
44
44
 
45
45
  def collection_finder
@@ -65,7 +65,11 @@ module Spree
65
65
  def shipping_rates
66
66
  result = shipping_rates_service.call(order: spree_current_order)
67
67
 
68
- render_serialized_payload { serialize_shipping_rates(result.value) }
68
+ if result.success?
69
+ render_serialized_payload { serialize_shipping_rates(result.value) }
70
+ else
71
+ render_error_payload(result.error)
72
+ end
69
73
  end
70
74
 
71
75
  def payment_methods
@@ -121,8 +125,7 @@ module Spree
121
125
  def serialize_shipping_rates(shipments)
122
126
  shipping_rates_serializer.new(
123
127
  shipments,
124
- include: [:shipping_rates],
125
- params: { show_rates: true }
128
+ include: [:shipping_rates, :stock_location]
126
129
  ).serializable_hash
127
130
  end
128
131
  end
@@ -0,0 +1,27 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ class StoresController < ::Spree::Api::V2::BaseController
6
+ def show
7
+ render_serialized_payload { serialize_resource(resource) }
8
+ end
9
+
10
+ private
11
+
12
+ def scope
13
+ Spree::Store
14
+ end
15
+
16
+ def resource
17
+ scope.find_by!(code: params[:code])
18
+ end
19
+
20
+ def resource_serializer
21
+ Spree::Api::Dependencies.storefront_store_serializer.constantize
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -13,7 +13,9 @@ module Spree
13
13
  :storefront_country_serializer, :storefront_current_order_finder, :storefront_completed_order_finder, :storefront_order_sorter,
14
14
  :storefront_collection_paginator, :storefront_user_serializer, :storefront_products_sorter, :storefront_products_finder,
15
15
  :storefront_product_serializer, :storefront_taxon_serializer, :storefront_taxon_finder, :storefront_find_by_variant_finder,
16
- :storefront_cart_update_service, :storefront_cart_estimate_shipping_rates_service, :storefront_estimated_shipment_serializer
16
+ :storefront_cart_update_service, :storefront_cart_estimate_shipping_rates_service, :storefront_estimated_shipment_serializer,
17
+ :storefront_store_serializer, :storefront_address_serializer, :storefront_order_serializer,
18
+ :storefront_account_create_address_service, :storefront_account_update_address_service, :storefront_address_finder
17
19
  ].freeze
18
20
 
19
21
  attr_accessor *INJECTION_POINTS
@@ -48,7 +50,12 @@ module Spree
48
50
  @storefront_checkout_remove_store_credit_service = Spree::Dependencies.checkout_remove_store_credit_service
49
51
  @storefront_checkout_get_shipping_rates_service = Spree::Dependencies.checkout_get_shipping_rates_service
50
52
 
53
+ # account services
54
+ @storefront_account_create_address_service = Spree::Dependencies.account_create_address_service
55
+ @storefront_account_update_address_service = Spree::Dependencies.account_update_address_service
56
+
51
57
  # serializers
58
+ @storefront_address_serializer = 'Spree::V2::Storefront::AddressSerializer'
52
59
  @storefront_cart_serializer = 'Spree::V2::Storefront::CartSerializer'
53
60
  @storefront_credit_card_serializer = 'Spree::V2::Storefront::CreditCardSerializer'
54
61
  @storefront_country_serializer = 'Spree::V2::Storefront::CountrySerializer'
@@ -58,6 +65,8 @@ module Spree
58
65
  @storefront_payment_method_serializer = 'Spree::V2::Storefront::PaymentMethodSerializer'
59
66
  @storefront_product_serializer = 'Spree::V2::Storefront::ProductSerializer'
60
67
  @storefront_estimated_shipment_serializer = 'Spree::V2::Storefront::EstimatedShippingRateSerializer'
68
+ @storefront_store_serializer = 'Spree::V2::Storefront::StoreSerializer'
69
+ @storefront_order_serializer = 'Spree::V2::Storefront::CartSerializer'
61
70
 
62
71
  # sorters
63
72
  @storefront_order_sorter = Spree::Dependencies.order_sorter
@@ -67,6 +76,7 @@ module Spree
67
76
  @storefront_collection_paginator = Spree::Dependencies.collection_paginator
68
77
 
69
78
  # finders
79
+ @storefront_address_finder = Spree::Dependencies.address_finder
70
80
  @storefront_country_finder = Spree::Dependencies.country_finder
71
81
  @storefront_current_order_finder = Spree::Dependencies.current_order_finder
72
82
  @storefront_completed_order_finder = Spree::Dependencies.completed_order_finder
@@ -8,7 +8,9 @@ module Spree
8
8
  :updated_at, :completed_at, :included_tax_total, :additional_tax_total, :display_additional_tax_total,
9
9
  :display_included_tax_total, :tax_total, :currency, :state, :token, :email,
10
10
  :display_item_total, :display_ship_total, :display_adjustment_total, :display_tax_total,
11
- :promo_total, :display_promo_total, :item_count, :special_instructions, :display_total
11
+ :promo_total, :display_promo_total, :item_count, :special_instructions, :display_total,
12
+ :pre_tax_item_amount, :display_pre_tax_item_amount, :pre_tax_total, :display_pre_tax_total,
13
+ :shipment_state, :payment_state
12
14
 
13
15
  has_many :line_items
14
16
  has_many :variants
@@ -20,12 +22,14 @@ module Spree
20
22
 
21
23
  belongs_to :user
22
24
  belongs_to :billing_address,
23
- id_method_name: :bill_address_id,
24
- serializer: :address
25
+ id_method_name: :bill_address_id,
26
+ serializer: :address,
27
+ record_type: :address
25
28
 
26
29
  belongs_to :shipping_address,
27
- id_method_name: :ship_address_id,
28
- serializer: :address
30
+ id_method_name: :ship_address_id,
31
+ serializer: :address,
32
+ record_type: :address
29
33
  end
30
34
  end
31
35
  end
@@ -9,7 +9,8 @@ module Spree
9
9
  :display_adjustment_total, :additional_tax_total,
10
10
  :discounted_amount, :display_discounted_amount,
11
11
  :display_additional_tax_total, :promo_total, :display_promo_total,
12
- :included_tax_total, :display_included_tax_total
12
+ :included_tax_total, :display_included_tax_total,
13
+ :pre_tax_amount, :display_pre_tax_amount
13
14
 
14
15
  belongs_to :variant
15
16
  end
@@ -8,7 +8,7 @@ module Spree
8
8
  has_one :payment_method
9
9
 
10
10
  attributes :amount, :response_code, :number, :cvv_response_code, :cvv_response_message,
11
- :payment_method_id, :payment_method_name
11
+ :payment_method_id, :payment_method_name, :state
12
12
  end
13
13
  end
14
14
  end
@@ -9,7 +9,9 @@ module Spree
9
9
 
10
10
  attribute :free, &:free?
11
11
 
12
- has_many :shipping_rates, if: proc { |_record, params| params&.dig(:show_rates) }
12
+ has_many :shipping_rates
13
+
14
+ belongs_to :stock_location
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module V2
3
+ module Storefront
4
+ class StockLocationSerializer < BaseSerializer
5
+ set_type :stock_location
6
+
7
+ attributes :name
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module V2
3
+ module Storefront
4
+ class StoreCreditCategorySerializer < BaseSerializer
5
+ set_type :store_credit_category
6
+
7
+ attributes :name
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,7 +4,7 @@ module Spree
4
4
  class StoreCreditSerializer < BaseSerializer
5
5
  set_type :store_credit
6
6
 
7
- belongs_to :category
7
+ belongs_to :category, serializer: :store_credit_category
8
8
  has_many :store_credit_events
9
9
  belongs_to :credit_type,
10
10
  id_method_name: :type_id,
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module V2
3
+ module Storefront
4
+ class StoreSerializer < BaseSerializer
5
+ set_type :store
6
+
7
+ attributes :name, :url, :meta_description, :meta_keywords, :seo_title, :default_currency, :default, :supported_currencies, :facebook,
8
+ :twitter, :instagram, :default_locale, :customer_support_email, :default_country_id, :description,
9
+ :address, :contact_phone, :contact_email
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,7 +4,7 @@ module Spree
4
4
  class TaxonSerializer < BaseSerializer
5
5
  set_type :taxon
6
6
 
7
- attributes :name, :pretty_name, :permalink, :seo_title, :meta_title, :meta_description,
7
+ attributes :name, :pretty_name, :permalink, :seo_title, :description, :meta_title, :meta_description,
8
8
  :meta_keywords, :left, :right, :position, :depth, :updated_at
9
9
 
10
10
  attribute :is_root, &:root?
@@ -152,6 +152,7 @@ Spree::Core::Engine.add_routes do
152
152
  resource :account, controller: :account, only: %i[show]
153
153
 
154
154
  namespace :account do
155
+ resources :addresses, controller: :addresses, only: %i[index create update]
155
156
  resources :credit_cards, controller: :credit_cards, only: %i[index show]
156
157
  resources :orders, controller: :orders, only: %i[index show]
157
158
  end
@@ -160,7 +161,8 @@ Spree::Core::Engine.add_routes do
160
161
  get '/countries/:iso', to: 'countries#show', as: :country
161
162
  get '/order_status/:number', to: 'order_status#show', as: :order_status
162
163
  resources :products, only: %i[index show]
163
- resources :taxons, only: %i[index show]
164
+ resources :taxons, only: %i[index show], id: /.+/
165
+ get '/stores/:code', to: 'stores#show', as: :store
164
166
  end
165
167
  end
166
168
 
@@ -1123,6 +1123,14 @@ components:
1123
1123
  company:
1124
1124
  type: string
1125
1125
  example: 'Google Inc.'
1126
+ AddressList:
1127
+ required:
1128
+ - data
1129
+ properties:
1130
+ data:
1131
+ type: array
1132
+ items:
1133
+ $ref: '#/components/schemas/Address'
1126
1134
  Cart:
1127
1135
  required:
1128
1136
  - data
@@ -1289,6 +1297,18 @@ components:
1289
1297
  display_tax_total:
1290
1298
  type: string
1291
1299
  example: '$10.00'
1300
+ pre_tax_item_amount:
1301
+ type: string
1302
+ example: '17.00'
1303
+ display_pre_tax_item_amount:
1304
+ type: string
1305
+ example: '$17.00'
1306
+ pre_tax_total:
1307
+ type: string
1308
+ example: '20.00'
1309
+ display_pre_tax_total:
1310
+ type: string
1311
+ example: '$20.00'
1292
1312
  item_count:
1293
1313
  type: number
1294
1314
  example: 2
@@ -1501,6 +1521,12 @@ components:
1501
1521
  display_discounted_amount:
1502
1522
  type: string
1503
1523
  example: '$125.00'
1524
+ pre_tax_amount:
1525
+ type: string
1526
+ example: '125.0'
1527
+ display_pre_tax_amount:
1528
+ type: string
1529
+ example: '$125.00'
1504
1530
  promo_total:
1505
1531
  type: string
1506
1532
  example: '-5.0'
@@ -27,6 +27,8 @@ shared_examples 'returns valid cart JSON' do
27
27
  expect(json_response['data']).to have_type('cart')
28
28
  expect(json_response['data']).to have_attribute(:number).with_value(order.number)
29
29
  expect(json_response['data']).to have_attribute(:state).with_value(order.state)
30
+ expect(json_response['data']).to have_attribute(:payment_state).with_value(order.payment_state)
31
+ expect(json_response['data']).to have_attribute(:shipment_state).with_value(order.shipment_state)
30
32
  expect(json_response['data']).to have_attribute(:token).with_value(order.token)
31
33
  expect(json_response['data']).to have_attribute(:total).with_value(order.total.to_s)
32
34
  expect(json_response['data']).to have_attribute(:item_total).with_value(order.item_total.to_s)
@@ -48,6 +50,10 @@ shared_examples 'returns valid cart JSON' do
48
50
  expect(json_response['data']).to have_attribute(:promo_total).with_value(order.promo_total.to_s)
49
51
  expect(json_response['data']).to have_attribute(:display_promo_total).with_value(order.display_promo_total.to_s)
50
52
  expect(json_response['data']).to have_attribute(:display_total).with_value(order.display_total.to_s)
53
+ expect(json_response['data']).to have_attribute(:pre_tax_item_amount).with_value(order.pre_tax_item_amount.to_s)
54
+ expect(json_response['data']).to have_attribute(:display_pre_tax_item_amount).with_value(order.display_pre_tax_item_amount.to_s)
55
+ expect(json_response['data']).to have_attribute(:pre_tax_total).with_value(order.pre_tax_total.to_s)
56
+ expect(json_response['data']).to have_attribute(:display_pre_tax_total).with_value(order.display_pre_tax_total.to_s)
51
57
  expect(json_response['data']).to have_relationships(:user, :line_items, :variants, :billing_address, :shipping_address, :payments, :shipments, :promotions)
52
58
  end
53
59
  end
@@ -2,20 +2,27 @@
2
2
  require_relative '../core/lib/spree/core/version.rb'
3
3
 
4
4
  Gem::Specification.new do |s|
5
+ s.name = "spree_api"
6
+ s.version = Spree.version
5
7
  s.authors = ["Ryan Bigg"]
6
8
  s.email = ["ryan@spreecommerce.com"]
7
- s.description = %q{Spree's API}
8
9
  s.summary = %q{Spree's API}
10
+ s.description = %q{Spree's API}
9
11
  s.homepage = 'http://spreecommerce.org'
10
12
  s.license = 'BSD-3-Clause'
11
13
 
14
+ s.metadata = {
15
+ "bug_tracker_uri" => "https://github.com/spree/spree/issues",
16
+ "changelog_uri" => "https://github.com/spree/spree/releases/tag/v#{s.version}",
17
+ "documentation_uri" => "https://guides.spreecommerce.org/",
18
+ "source_code_uri" => "https://github.com/spree/spree/tree/v#{s.version}",
19
+ }
20
+
12
21
  s.required_ruby_version = '>= 2.5.0'
13
22
 
14
23
  s.files = `git ls-files`.split($\).reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
15
24
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
- s.name = "spree_api"
17
25
  s.require_paths = ["lib"]
18
- s.version = Spree.version
19
26
 
20
27
  s.add_development_dependency 'jsonapi-rspec'
21
28
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 4.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-rspec
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.5
33
+ version: 4.0.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.0.5
40
+ version: 4.0.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rabl
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +133,7 @@ files:
133
133
  - app/controllers/spree/api/v1/variants_controller.rb
134
134
  - app/controllers/spree/api/v1/zones_controller.rb
135
135
  - app/controllers/spree/api/v2/base_controller.rb
136
+ - app/controllers/spree/api/v2/storefront/account/addresses_controller.rb
136
137
  - app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb
137
138
  - app/controllers/spree/api/v2/storefront/account/orders_controller.rb
138
139
  - app/controllers/spree/api/v2/storefront/account_controller.rb
@@ -141,6 +142,7 @@ files:
141
142
  - app/controllers/spree/api/v2/storefront/countries_controller.rb
142
143
  - app/controllers/spree/api/v2/storefront/order_status_controller.rb
143
144
  - app/controllers/spree/api/v2/storefront/products_controller.rb
145
+ - app/controllers/spree/api/v2/storefront/stores_controller.rb
144
146
  - app/controllers/spree/api/v2/storefront/taxons_controller.rb
145
147
  - app/helpers/spree/api/api_helpers.rb
146
148
  - app/helpers/spree/api/v2/collection_options_helpers.rb
@@ -166,9 +168,12 @@ files:
166
168
  - app/serializers/spree/v2/storefront/shipment_serializer.rb
167
169
  - app/serializers/spree/v2/storefront/shipping_rate_serializer.rb
168
170
  - app/serializers/spree/v2/storefront/state_serializer.rb
171
+ - app/serializers/spree/v2/storefront/stock_location_serializer.rb
172
+ - app/serializers/spree/v2/storefront/store_credit_category_serializer.rb
169
173
  - app/serializers/spree/v2/storefront/store_credit_event_serializer.rb
170
174
  - app/serializers/spree/v2/storefront/store_credit_serializer.rb
171
175
  - app/serializers/spree/v2/storefront/store_credit_type_serializer.rb
176
+ - app/serializers/spree/v2/storefront/store_serializer.rb
172
177
  - app/serializers/spree/v2/storefront/taxon_image_serializer.rb
173
178
  - app/serializers/spree/v2/storefront/taxon_serializer.rb
174
179
  - app/serializers/spree/v2/storefront/taxonomy_serializer.rb
@@ -300,7 +305,11 @@ files:
300
305
  homepage: http://spreecommerce.org
301
306
  licenses:
302
307
  - BSD-3-Clause
303
- metadata: {}
308
+ metadata:
309
+ bug_tracker_uri: https://github.com/spree/spree/issues
310
+ changelog_uri: https://github.com/spree/spree/releases/tag/v4.0.6
311
+ documentation_uri: https://guides.spreecommerce.org/
312
+ source_code_uri: https://github.com/spree/spree/tree/v4.0.6
304
313
  post_install_message:
305
314
  rdoc_options: []
306
315
  require_paths: