spree_api 4.3.0.rc3 → 4.4.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v2/caching.rb +7 -3
  3. data/app/controllers/concerns/spree/api/v2/coupon_codes_helper.rb +29 -0
  4. data/app/controllers/concerns/spree/api/v2/number_resource.rb +11 -0
  5. data/app/controllers/concerns/spree/api/v2/platform/nested_set_reposition_concern.rb +37 -0
  6. data/app/controllers/concerns/spree/api/v2/platform/promotion_calculator_params.rb +17 -0
  7. data/app/controllers/concerns/spree/api/v2/platform/promotion_rule_params.rb +16 -0
  8. data/app/controllers/concerns/spree/api/v2/storefront/metadata_controller_concern.rb +18 -0
  9. data/app/controllers/spree/api/v1/checkouts_controller.rb +1 -1
  10. data/app/controllers/spree/api/v2/base_controller.rb +7 -5
  11. data/app/controllers/spree/api/v2/platform/adjustments_controller.rb +19 -0
  12. data/app/controllers/spree/api/v2/platform/classifications_controller.rb +1 -22
  13. data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +4 -0
  14. data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +13 -18
  15. data/app/controllers/spree/api/v2/platform/digital_links_controller.rb +25 -0
  16. data/app/controllers/spree/api/v2/platform/digitals_controller.rb +19 -0
  17. data/app/controllers/spree/api/v2/platform/line_items_controller.rb +59 -0
  18. data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +5 -19
  19. data/app/controllers/spree/api/v2/platform/menus_controller.rb +0 -4
  20. data/app/controllers/spree/api/v2/platform/orders_controller.rb +163 -0
  21. data/app/controllers/spree/api/v2/platform/payment_methods_controller.rb +27 -0
  22. data/app/controllers/spree/api/v2/platform/payments_controller.rb +17 -0
  23. data/app/controllers/spree/api/v2/platform/promotion_actions_controller.rb +30 -0
  24. data/app/controllers/spree/api/v2/platform/promotion_categories_controller.rb +19 -0
  25. data/app/controllers/spree/api/v2/platform/promotion_rules_controller.rb +25 -0
  26. data/app/controllers/spree/api/v2/platform/promotions_controller.rb +31 -0
  27. data/app/controllers/spree/api/v2/platform/resource_controller.rb +47 -16
  28. data/app/controllers/spree/api/v2/platform/roles_controller.rb +15 -0
  29. data/app/controllers/spree/api/v2/platform/shipments_controller.rb +143 -0
  30. data/app/controllers/spree/api/v2/platform/shipping_categories_controller.rb +15 -0
  31. data/app/controllers/spree/api/v2/platform/shipping_methods_controller.rb +24 -0
  32. data/app/controllers/spree/api/v2/platform/states_controller.rb +19 -0
  33. data/app/controllers/spree/api/v2/platform/stock_items_controller.rb +19 -0
  34. data/app/controllers/spree/api/v2/platform/stock_locations_controller.rb +19 -0
  35. data/app/controllers/spree/api/v2/platform/store_credit_categories_controller.rb +15 -0
  36. data/app/controllers/spree/api/v2/platform/store_credit_types_controller.rb +15 -0
  37. data/app/controllers/spree/api/v2/platform/store_credits_controller.rb +19 -0
  38. data/app/controllers/spree/api/v2/platform/tax_categories_controller.rb +19 -0
  39. data/app/controllers/spree/api/v2/platform/tax_rates_controller.rb +23 -0
  40. data/app/controllers/spree/api/v2/platform/taxonomies_controller.rb +19 -0
  41. data/app/controllers/spree/api/v2/platform/taxons_controller.rb +25 -0
  42. data/app/controllers/spree/api/v2/platform/users_controller.rb +4 -0
  43. data/app/controllers/spree/api/v2/platform/variants_controller.rb +19 -0
  44. data/app/controllers/spree/api/v2/platform/webhooks/events_controller.rb +21 -0
  45. data/app/controllers/spree/api/v2/platform/webhooks/subscribers_controller.rb +21 -0
  46. data/app/controllers/spree/api/v2/platform/wished_items_controller.rb +19 -0
  47. data/app/controllers/spree/api/v2/platform/wishlists_controller.rb +19 -0
  48. data/app/controllers/spree/api/v2/platform/zones_controller.rb +19 -0
  49. data/app/controllers/spree/api/v2/resource_controller.rb +3 -3
  50. data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +5 -3
  51. data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +4 -1
  52. data/app/controllers/spree/api/v2/storefront/cart_controller.rb +57 -29
  53. data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +24 -0
  54. data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +54 -0
  55. data/app/controllers/spree/api/v2/storefront/products_controller.rb +8 -0
  56. data/app/controllers/spree/api/v2/storefront/wishlists_controller.rb +171 -0
  57. data/app/helpers/spree/api/v2/collection_options_helpers.rb +1 -1
  58. data/app/jobs/spree/webhooks/subscribers/make_request_job.rb +17 -0
  59. data/app/models/concerns/spree/webhooks/has_webhooks.rb +58 -0
  60. data/app/models/spree/api/webhooks/order_decorator.rb +43 -0
  61. data/app/models/spree/api/webhooks/payment_decorator.rb +26 -0
  62. data/app/models/spree/api/webhooks/product_decorator.rb +27 -0
  63. data/app/models/spree/api/webhooks/shipment_decorator.rb +21 -0
  64. data/app/models/spree/api/webhooks/stock_item_decorator.rb +43 -0
  65. data/app/models/spree/api/webhooks/stock_movement_decorator.rb +52 -0
  66. data/app/models/spree/api/webhooks/variant_decorator.rb +26 -0
  67. data/app/models/spree/oauth_access_grant.rb +7 -0
  68. data/app/models/spree/oauth_access_token.rb +7 -0
  69. data/app/models/spree/oauth_application.rb +15 -0
  70. data/app/models/spree/webhooks/base.rb +11 -0
  71. data/app/models/spree/webhooks/event.rb +12 -0
  72. data/app/models/spree/webhooks/subscriber.rb +57 -0
  73. data/app/presenters/spree/api/products/filters_presenter.rb +39 -0
  74. data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +19 -1
  75. data/app/serializers/spree/api/v2/base_serializer.rb +11 -4
  76. data/app/serializers/spree/api/v2/platform/address_serializer.rb +1 -1
  77. data/app/serializers/spree/api/v2/platform/adjustment_serializer.rb +20 -0
  78. data/app/serializers/spree/api/v2/platform/asset_serializer.rb +13 -0
  79. data/app/serializers/spree/api/v2/platform/calculator_serializer.rb +17 -0
  80. data/app/serializers/spree/api/v2/platform/classification_serializer.rb +1 -1
  81. data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +1 -1
  82. data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +8 -1
  83. data/app/serializers/spree/api/v2/platform/country_serializer.rb +1 -1
  84. data/app/serializers/spree/api/v2/platform/credit_card_serializer.rb +14 -0
  85. data/app/serializers/spree/api/v2/platform/customer_return_serializer.rb +17 -0
  86. data/app/serializers/spree/api/v2/platform/digital_link_serializer.rb +16 -0
  87. data/app/serializers/spree/api/v2/platform/digital_serializer.rb +30 -0
  88. data/app/serializers/spree/api/v2/platform/feature_page_serializer.rb +11 -0
  89. data/app/serializers/spree/api/v2/platform/homepage_serializer.rb +11 -0
  90. data/app/serializers/spree/api/v2/platform/inventory_unit_serializer.rb +19 -0
  91. data/app/serializers/spree/api/v2/platform/line_item_serializer.rb +19 -0
  92. data/app/serializers/spree/api/v2/platform/log_entry_serializer.rb +13 -0
  93. data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +1 -1
  94. data/app/serializers/spree/api/v2/platform/menu_serializer.rb +1 -1
  95. data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +1 -1
  96. data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +1 -1
  97. data/app/serializers/spree/api/v2/platform/order_promotion_serializer.rb +14 -0
  98. data/app/serializers/spree/api/v2/platform/order_serializer.rb +31 -0
  99. data/app/serializers/spree/api/v2/platform/payment_capture_event_serializer.rb +13 -0
  100. data/app/serializers/spree/api/v2/platform/payment_method_serializer.rb +18 -0
  101. data/app/serializers/spree/api/v2/platform/payment_serializer.rb +21 -0
  102. data/app/serializers/spree/api/v2/platform/price_serializer.rb +19 -0
  103. data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +1 -1
  104. data/app/serializers/spree/api/v2/platform/product_serializer.rb +7 -3
  105. data/app/serializers/spree/api/v2/platform/promotion_action_line_item_serializer.rb +14 -0
  106. data/app/serializers/spree/api/v2/platform/promotion_action_serializer.rb +19 -0
  107. data/app/serializers/spree/api/v2/platform/promotion_category_serializer.rb +13 -0
  108. data/app/serializers/spree/api/v2/platform/promotion_rule_serializer.rb +21 -0
  109. data/app/serializers/spree/api/v2/platform/promotion_serializer.rb +17 -0
  110. data/app/serializers/spree/api/v2/platform/property_serializer.rb +11 -0
  111. data/app/serializers/spree/api/v2/platform/prototype_serializer.rb +15 -0
  112. data/app/serializers/spree/api/v2/platform/refund_reason_serializer.rb +11 -0
  113. data/app/serializers/spree/api/v2/platform/refund_serializer.rb +16 -0
  114. data/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb +10 -0
  115. data/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb +18 -0
  116. data/app/serializers/spree/api/v2/platform/reimbursement_type_serializer.rb +11 -0
  117. data/app/serializers/spree/api/v2/platform/return_authorization_reason_serializer.rb +11 -0
  118. data/app/serializers/spree/api/v2/platform/return_authorization_serializer.rb +17 -0
  119. data/app/serializers/spree/api/v2/platform/return_item_serializer.rb +16 -0
  120. data/app/serializers/spree/api/v2/platform/role_serializer.rb +11 -0
  121. data/app/serializers/spree/api/v2/platform/shipment_serializer.rb +22 -0
  122. data/app/serializers/spree/api/v2/platform/shipping_category_serializer.rb +11 -0
  123. data/app/serializers/spree/api/v2/platform/shipping_method_serializer.rb +16 -0
  124. data/app/serializers/spree/api/v2/platform/shipping_rate_serializer.rb +15 -0
  125. data/app/serializers/spree/api/v2/platform/standard_page_serializer.rb +11 -0
  126. data/app/serializers/spree/api/v2/platform/state_change_serializer.rb +13 -0
  127. data/app/serializers/spree/api/v2/platform/state_serializer.rb +1 -1
  128. data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +1 -3
  129. data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +2 -4
  130. data/app/serializers/spree/api/v2/platform/stock_movement_serializer.rb +11 -0
  131. data/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb +15 -0
  132. data/app/serializers/spree/api/v2/platform/store_credit_category_serializer.rb +12 -0
  133. data/app/serializers/spree/api/v2/platform/store_credit_event_serializer.rb +14 -0
  134. data/app/serializers/spree/api/v2/platform/store_credit_serializer.rb +18 -0
  135. data/app/serializers/spree/api/v2/platform/store_credit_type_serializer.rb +12 -0
  136. data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -1
  137. data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +2 -2
  138. data/app/serializers/spree/api/v2/platform/tax_rate_serializer.rb +14 -0
  139. data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +1 -1
  140. data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +1 -1
  141. data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
  142. data/app/serializers/spree/api/v2/platform/variant_serializer.rb +3 -2
  143. data/app/serializers/spree/api/v2/platform/webhooks/event_serializer.rb +15 -0
  144. data/app/serializers/spree/api/v2/platform/webhooks/subscriber_serializer.rb +13 -0
  145. data/app/serializers/spree/api/v2/platform/wished_item_serializer.rb +29 -0
  146. data/app/serializers/spree/api/v2/platform/wishlist_serializer.rb +19 -0
  147. data/app/serializers/spree/api/v2/platform/zone_member_serializer.rb +13 -0
  148. data/app/serializers/spree/api/v2/platform/zone_serializer.rb +13 -0
  149. data/app/serializers/spree/v2/storefront/address_serializer.rb +1 -1
  150. data/app/serializers/spree/v2/storefront/cart_serializer.rb +1 -1
  151. data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +5 -1
  152. data/app/serializers/spree/v2/storefront/credit_card_serializer.rb +1 -1
  153. data/app/serializers/spree/v2/storefront/digital_link_serializer.rb +11 -0
  154. data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -2
  155. data/app/serializers/spree/v2/storefront/line_item_serializer.rb +2 -1
  156. data/app/serializers/spree/v2/storefront/option_type_serializer.rb +1 -1
  157. data/app/serializers/spree/v2/storefront/option_value_serializer.rb +1 -1
  158. data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +1 -1
  159. data/app/serializers/spree/v2/storefront/payment_serializer.rb +1 -1
  160. data/app/serializers/spree/v2/storefront/product_serializer.rb +2 -2
  161. data/app/serializers/spree/v2/storefront/promotion_serializer.rb +1 -1
  162. data/app/serializers/spree/v2/storefront/shipment_serializer.rb +2 -1
  163. data/app/serializers/spree/v2/storefront/store_credit_serializer.rb +1 -1
  164. data/app/serializers/spree/v2/storefront/store_serializer.rb +1 -1
  165. data/app/serializers/spree/v2/storefront/taxon_serializer.rb +1 -1
  166. data/app/serializers/spree/v2/storefront/taxonomy_serializer.rb +1 -1
  167. data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
  168. data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
  169. data/app/serializers/spree/v2/storefront/wished_item_serializer.rb +29 -0
  170. data/app/serializers/spree/v2/storefront/wishlist_serializer.rb +17 -0
  171. data/app/services/spree/webhooks/subscribers/handle_request.rb +73 -0
  172. data/app/services/spree/webhooks/subscribers/make_request.rb +82 -0
  173. data/app/services/spree/webhooks/subscribers/queue_requests.rb +17 -0
  174. data/app/services/spree/webhooks.rb +13 -0
  175. data/config/i18n-tasks.yml +40 -0
  176. data/config/initializers/doorkeeper.rb +12 -12
  177. data/config/initializers/rabl.rb +2 -2
  178. data/config/locales/en.yml +29 -27
  179. data/config/routes.rb +85 -59
  180. data/db/migrate/20210902162826_create_spree_webhooks_tables.rb +16 -0
  181. data/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb +21 -0
  182. data/db/migrate/20211025162826_create_spree_webhooks_events.rb +14 -0
  183. data/docs/oauth/index.yml +126 -33
  184. data/docs/v2/platform/index.yaml +19182 -1717
  185. data/docs/v2/storefront/index.yaml +14823 -14588
  186. data/{app/models/spree → lib/spree/api}/api_dependencies.rb +60 -5
  187. data/lib/spree/api/engine.rb +24 -1
  188. data/lib/spree/api/testing_support/factories/oauth_application_factory.rb +6 -0
  189. data/lib/spree/api/testing_support/factories/webhook_event_factory.rb +27 -0
  190. data/lib/spree/api/testing_support/factories/webhook_subscriber_factory.rb +13 -0
  191. data/lib/spree/api/testing_support/factories.rb +3 -0
  192. data/lib/spree/api/testing_support/helpers.rb +1 -1
  193. data/lib/spree/api/testing_support/jobs.rb +18 -0
  194. data/lib/spree/api/testing_support/matchers/webhooks.rb +67 -0
  195. data/lib/spree/api/testing_support/serializers.rb +25 -0
  196. data/lib/spree/api/testing_support/spree_webhooks.rb +9 -0
  197. data/lib/spree/api/testing_support/v2/base.rb +1 -1
  198. data/lib/spree/api/testing_support/v2/current_order.rb +34 -1
  199. data/lib/spree/api/testing_support/v2/platform_contexts.rb +109 -50
  200. data/lib/spree/api/testing_support/v2/serializers_params.rb +3 -1
  201. data/lib/spree/api.rb +1 -0
  202. data/spec/fixtures/files/icon_256x256.jpg +0 -0
  203. data/spree_api.gemspec +16 -15
  204. metadata +176 -28
  205. data/app/controllers/spree/api/errors_controller.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bd9fd052b9bc9fd57cabf4fb28955081e4e3522aad98fe014641d46ca7b5c2c
4
- data.tar.gz: f91442e429d34783f73dbc25806afa80ab0cbd5013c07c499c8b7da4bc5a29aa
3
+ metadata.gz: 9efbbbc5f98656b455a5f57457b1175474f9cdb0ea1329daf3e224e4541bc6bc
4
+ data.tar.gz: dd8438e1e0a2c20403abff778aad945d339d5bb062ec0140443433392211e360
5
5
  SHA512:
6
- metadata.gz: dcc5d4344630b798bb0ea424285c89267ec2034d2a2f2fb483686c17670793b13fb23499a10aec1c579a3c807cd995b2b6b9f6c33ba68cfe4da9883b57de017f
7
- data.tar.gz: c9d7016ddc08b9d26a438b46a5374d1c229e90e51cb2bace94c4f616c647d13d37eecd913c10ed80126508e25b23d5054032f1bd4ef349098c2caa8fc8869ae6
6
+ metadata.gz: 63fdc90d763549596e7dca38e3e99a7868158ad2ad1378501ded373effab5b418a7238ac491b0836d19867f40c0870068a6eb23a4edc425e0d750aec507cba59
7
+ data.tar.gz: f49a4a8bd7930f70f4f5815d38b8cd87b620636a45a87d500f422c0b63cee5ea35d28db94fc1da2e3f456c1105173f9b9787c1375c3fbbb8112ad46670ca35f9
@@ -5,11 +5,15 @@ module Spree
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  def collection_cache_key(collection)
8
- unscoped_collection = collection.unscope(:includes).unscope(:order)
8
+ ids_and_timestamps = collection.unscope(:includes).unscope(:order).pluck(:id, :updated_at)
9
+
10
+ ids = ids_and_timestamps.map(&:first)
11
+ max_updated_at = ids_and_timestamps.map(&:last).max
12
+
9
13
  cache_key_parts = [
10
14
  self.class.to_s,
11
- unscoped_collection.maximum(:updated_at),
12
- unscoped_collection.ids,
15
+ max_updated_at,
16
+ ids,
13
17
  resource_includes,
14
18
  sparse_fields,
15
19
  serializer_params,
@@ -0,0 +1,29 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module CouponCodesHelper
5
+ def select_coupon_codes
6
+ params[:coupon_code].present? ? [params[:coupon_code]] : check_coupon_codes
7
+ end
8
+
9
+ def check_coupon_codes
10
+ spree_current_order.promotions.coupons.map(&:code)
11
+ end
12
+
13
+ def select_error(coupon_codes)
14
+ result = coupon_handler.new(spree_current_order).remove(coupon_codes.first)
15
+ result.error
16
+ end
17
+
18
+ def select_errors(coupon_codes)
19
+ results = []
20
+ coupon_codes.each do |coupon_code|
21
+ results << coupon_handler.new(spree_current_order).remove(coupon_code)
22
+ end
23
+
24
+ results.select(&:error)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module NumberResource
5
+ def resource
6
+ @resource ||= scope.find_by(number: params[:id]) || scope.find(params[:id])
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ module NestedSetRepositionConcern
6
+ def reposition
7
+ spree_authorize! :update, resource if spree_current_user.present?
8
+
9
+ @new_parent = scope.find(permitted_resource_params[:new_parent_id])
10
+ new_index = permitted_resource_params[:new_position_idx].to_i
11
+
12
+ if resource.move_to_child_with_index(@new_parent, new_index)
13
+ # If successful reposition call the custom method for handling success.
14
+ successful_reposition_actions
15
+ elsif resource.errors.any?
16
+ # If there are errors output them to the response
17
+ render_error_payload(resource.errors.full_messages.to_sentence)
18
+ else
19
+ # If the user drops the re-positioned item in the same location it came from
20
+ # we just render the serialized payload, nothing has changed, we don't need to
21
+ # render any errors, or fire any custom success methods.
22
+ render_serialized_payload { serialize_resource(resource) }
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def successful_reposition_actions
29
+ # Call a separate method for a successful reposition so this can be easily overridden
30
+ # if a more complex set of events need to occur after a successful reposition.
31
+ render_serialized_payload { serialize_resource(resource) }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ module PromotionCalculatorParams
6
+ private
7
+
8
+ def calculator_params
9
+ [:preferred_flat_percent, :preferred_amount, :preferred_first_item, :preferred_additional_item,
10
+ :preferred_max_items, :preferred_percent, :preferred_minimal_amount, :preferred_normal_amount,
11
+ :preferred_discount_amount, :preferred_currency, :preferred_base_amount, :preferred_base_percent, { preferred_tiers: {} }]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ module PromotionRuleParams
6
+ private
7
+
8
+ def rule_params
9
+ [:preferred_match_policy, :preferred_country_id, :preferred_amount_min, :preferred_operator_min, :preferred_amount_max,
10
+ :preferred_operator_max, { taxon_ids: [], user_ids: [], product_ids: [], preferred_eligible_values: {} }]
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ module MetadataControllerConcern
6
+ protected
7
+
8
+ def ensure_valid_metadata
9
+ if params[:public_metadata].present? && !params[:public_metadata].is_a?(ActionController::Parameters) ||
10
+ params[:private_metadata].present? && !params[:private_metadata].is_a?(ActionController::Parameters)
11
+ render_error_payload(I18n.t(:invalid_params, scope: 'spree.api.v2.metadata'))
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -47,7 +47,7 @@ module Spree
47
47
  params[:order][:user_id] if params[:order]
48
48
  end
49
49
 
50
- # Should be overriden if you have areas of your checkout that don't match
50
+ # Should be overridden if you have areas of your checkout that don't match
51
51
  # up to a step within checkout_steps, such as a registration step
52
52
  def skip_state_validation?
53
53
  false
@@ -17,6 +17,7 @@ module Spree
17
17
  rescue_from JSONAPI::Serializer::UnsupportedIncludeError, with: :error_during_processing
18
18
  end
19
19
  rescue_from ArgumentError, with: :error_during_processing
20
+ rescue_from ActionDispatch::Http::Parameters::ParseError, with: :error_during_processing
20
21
 
21
22
  def content_type
22
23
  Spree::Api::Config[:api_v2_content_type]
@@ -64,9 +65,9 @@ module Spree
64
65
  render json: json, status: status, content_type: content_type
65
66
  end
66
67
 
67
- def render_result(result)
68
+ def render_result(result, ok_status = 200)
68
69
  if result.success?
69
- render_serialized_payload { serialize_resource(result.value) }
70
+ render_serialized_payload(ok_status) { serialize_resource(result.value) }
70
71
  else
71
72
  render_error_payload(result.error)
72
73
  end
@@ -78,7 +79,7 @@ module Spree
78
79
 
79
80
  doorkeeper_authorize!
80
81
 
81
- @spree_current_user ||= Spree.user_class.find_by(id: doorkeeper_token.resource_owner_id)
82
+ @spree_current_user ||= doorkeeper_token.resource_owner
82
83
  end
83
84
 
84
85
  def spree_authorize!(action, subject, *args)
@@ -89,13 +90,13 @@ module Spree
89
90
  raise CanCan::AccessDenied if spree_current_user.nil?
90
91
  end
91
92
 
92
- # Needs to be overriden so that we use Spree's Ability rather than anyone else's.
93
+ # Needs to be overridden so that we use Spree's Ability rather than anyone else's.
93
94
  def current_ability
94
95
  @current_ability ||= Spree::Dependencies.ability_class.constantize.new(spree_current_user)
95
96
  end
96
97
 
97
98
  def request_includes
98
- # if API user want's to receive only the bare-minimum
99
+ # if API user wants to receive only the bare-minimum
99
100
  # the API will return only the main resource without any included
100
101
  if params[:include]&.blank?
101
102
  []
@@ -131,6 +132,7 @@ module Spree
131
132
  {
132
133
  currency: current_currency,
133
134
  locale: current_locale,
135
+ price_options: current_price_options,
134
136
  store: current_store,
135
137
  user: spree_current_user,
136
138
  image_transformation: params[:image_transformation],
@@ -0,0 +1,19 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class AdjustmentsController < ResourceController
6
+ private
7
+
8
+ def model_class
9
+ Spree::Adjustment
10
+ end
11
+
12
+ def scope_includes
13
+ [:order, :adjustable]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,23 +3,6 @@ module Spree
3
3
  module V2
4
4
  module Platform
5
5
  class ClassificationsController < ResourceController
6
- before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
7
-
8
- def reposition
9
- spree_authorize! :update, resource if spree_current_user.present?
10
-
11
- result = classification_reposition_service.call(
12
- classification: resource,
13
- position: permitted_resource_params[:position]
14
- )
15
-
16
- if result.success?
17
- render_serialized_payload { serialize_resource(result.value) }
18
- else
19
- render_error_payload(result.error)
20
- end
21
- end
22
-
23
6
  private
24
7
 
25
8
  def model_class
@@ -29,13 +12,9 @@ module Spree
29
12
  def scope_includes
30
13
  [
31
14
  taxon: [],
32
- product: [:variants_including_master, :variant_images, :master, variants: [:prices]]
15
+ product: [:variants_including_master, :variant_images, :master, { variants: [:prices] }]
33
16
  ]
34
17
  end
35
-
36
- def classification_reposition_service
37
- Spree::Dependencies.classification_reposition_service.constantize
38
- end
39
18
  end
40
19
  end
41
20
  end
@@ -8,6 +8,10 @@ module Spree
8
8
  def model_class
9
9
  Spree::CmsPage
10
10
  end
11
+
12
+ def scope_includes
13
+ [:cms_sections]
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -3,29 +3,24 @@ module Spree
3
3
  module V2
4
4
  module Platform
5
5
  class CmsSectionsController < ResourceController
6
- before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
6
+ private
7
7
 
8
- def reposition
9
- spree_authorize! :update, @moved_section if spree_current_user.present?
8
+ def model_class
9
+ Spree::CmsSection
10
+ end
10
11
 
11
- @moved_section = scope.find(params[:section_id])
12
- new_index = params[:new_position_idx].to_i + 1
12
+ def spree_permitted_attributes
13
+ stored_attributes = []
13
14
 
14
- if @moved_section && new_index
15
- @moved_section.set_list_position(new_index)
16
- else
17
- head :bad_request
15
+ Spree::CmsSection::TYPES.each do |type|
16
+ type.constantize.stored_attributes.each do |_name, values|
17
+ values.each do |value|
18
+ stored_attributes << value
19
+ end
20
+ end
18
21
  end
19
22
 
20
- if @moved_section.save
21
- head :no_content
22
- end
23
- end
24
-
25
- private
26
-
27
- def model_class
28
- Spree::CmsSection
23
+ super + stored_attributes.compact.uniq!
29
24
  end
30
25
  end
31
26
  end
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class DigitalLinksController < ResourceController
6
+ def reset
7
+ spree_authorize! :update, resource if spree_current_user.present?
8
+
9
+ if resource.reset!
10
+ render_serialized_payload { serialize_resource(resource) }
11
+ else
12
+ render_error_payload(resource.errors)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def model_class
19
+ Spree::DigitalLink
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class DigitalsController < ResourceController
6
+ private
7
+
8
+ def model_class
9
+ Spree::Digital
10
+ end
11
+
12
+ def spree_permitted_attributes
13
+ super + [:attachment]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class LineItemsController < ResourceController
6
+ def create
7
+ order = current_store.orders.find(permitted_resource_params[:order_id])
8
+
9
+ result = create_service.call(order: order, line_item_attributes: permitted_resource_params)
10
+
11
+ if result.success?
12
+ render_serialized_payload(201) { serialize_resource(result.value) }
13
+ else
14
+ render_error_payload(result.error)
15
+ end
16
+ end
17
+
18
+ def update
19
+ result = update_service.call(line_item: resource, line_item_attributes: permitted_resource_params)
20
+
21
+ if result.success?
22
+ render_serialized_payload { serialize_resource(result.value) }
23
+ else
24
+ render_error_payload(resource.errors)
25
+ end
26
+ end
27
+
28
+ def destroy
29
+ result = destroy_service.call(line_item: resource)
30
+
31
+ if result.success?
32
+ head 204
33
+ else
34
+ render_error_payload(result.error)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def model_class
41
+ Spree::LineItem
42
+ end
43
+
44
+ def create_service
45
+ Spree::Api::Dependencies.platform_line_item_create_service.constantize
46
+ end
47
+
48
+ def update_service
49
+ Spree::Api::Dependencies.platform_line_item_update_service.constantize
50
+ end
51
+
52
+ def destroy_service
53
+ Spree::Api::Dependencies.platform_line_item_destroy_service.constantize
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -3,31 +3,17 @@ module Spree
3
3
  module V2
4
4
  module Platform
5
5
  class MenuItemsController < ResourceController
6
- before_action -> { doorkeeper_authorize! :write, :admin }, only: WRITE_ACTIONS << :reposition
7
-
8
- def reposition
9
- spree_authorize! :update, @moved_item if spree_current_user.present?
10
-
11
- @moved_item = scope.find(params[:id])
12
- @new_parent = scope.find(params[:new_parent_id])
13
- new_index = params[:new_position_idx].to_i
14
-
15
- if @moved_item && @new_parent && new_index
16
- @moved_item.move_to_child_with_index(@new_parent, new_index)
17
- else
18
- head :bad_request
19
- end
20
-
21
- if @moved_item.save
22
- render_serialized_payload { serialize_resource(resource) }
23
- end
24
- end
6
+ include ::Spree::Api::V2::Platform::NestedSetRepositionConcern
25
7
 
26
8
  private
27
9
 
28
10
  def model_class
29
11
  Spree::MenuItem
30
12
  end
13
+
14
+ def spree_permitted_attributes
15
+ super + [:new_parent_id, :new_position_idx]
16
+ end
31
17
  end
32
18
  end
33
19
  end
@@ -12,10 +12,6 @@ module Spree
12
12
  def scope_includes
13
13
  [:menu_items]
14
14
  end
15
-
16
- def scope
17
- current_store.menus
18
- end
19
15
  end
20
16
  end
21
17
  end
@@ -0,0 +1,163 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class OrdersController < ResourceController
6
+ include CouponCodesHelper
7
+ include NumberResource
8
+
9
+ def create
10
+ resource = current_store.orders.new(permitted_resource_params)
11
+
12
+ if resource.save
13
+ render_serialized_payload(201) { serialize_resource(resource) }
14
+ else
15
+ render_error_payload(resource.errors)
16
+ end
17
+ end
18
+
19
+ def update
20
+ result = update_service.call(
21
+ order: resource,
22
+ params: params,
23
+ permitted_attributes: spree_permitted_attributes,
24
+ request_env: request.headers.env
25
+ )
26
+
27
+ render_result(result)
28
+ end
29
+
30
+ def next
31
+ result = next_service.call(order: resource)
32
+
33
+ render_result(result)
34
+ end
35
+
36
+ def advance
37
+ result = advance_service.call(order: resource)
38
+
39
+ render_result(result)
40
+ end
41
+
42
+ def complete
43
+ result = complete_service.call(order: resource)
44
+
45
+ render_result(result)
46
+ end
47
+
48
+ def empty
49
+ result = empty_service.call(order: resource)
50
+
51
+ render_result(result)
52
+ end
53
+
54
+ def cancel
55
+ result = cancel_service.call(order: resource, canceler: spree_current_user)
56
+
57
+ render_result(result)
58
+ end
59
+
60
+ def approve
61
+ result = approve_service.call(order: resource, approver: spree_current_user)
62
+
63
+ render_result(result)
64
+ end
65
+
66
+ def destroy
67
+ result = destroy_service.call(order: resource)
68
+
69
+ if result.success?
70
+ head 204
71
+ else
72
+ render_error_payload(result.error)
73
+ end
74
+ end
75
+
76
+ def apply_coupon_code
77
+ resource.coupon_code = params[:coupon_code]
78
+ result = coupon_handler.new(resource).apply
79
+
80
+ if result.error.blank?
81
+ render_serialized_payload { serialize_resource(resource.reload) }
82
+ else
83
+ render_error_payload(result.error)
84
+ end
85
+ end
86
+
87
+ def use_store_credit
88
+ result = use_store_credit_service.call(
89
+ order: resource,
90
+ amount: params[:amount].try(:to_f)
91
+ )
92
+
93
+ render_result(result)
94
+ end
95
+
96
+ private
97
+
98
+ def model_class
99
+ Spree::Order
100
+ end
101
+
102
+ def allowed_sort_attributes
103
+ super.push(:available_on, :total, :payment_total, :item_total, :shipment_total,
104
+ :adjustment_total, :promo_total, :included_tax_total, :additional_tax_total,
105
+ :item_count, :tax_total, :completed_at)
106
+ end
107
+
108
+ def update_service
109
+ Spree::Api::Dependencies.platform_order_update_service.constantize
110
+ end
111
+
112
+ def next_service
113
+ Spree::Api::Dependencies.platform_order_next_service.constantize
114
+ end
115
+
116
+ def advance_service
117
+ Spree::Api::Dependencies.platform_order_advance_service.constantize
118
+ end
119
+
120
+ def use_store_credit_service
121
+ Spree::Api::Dependencies.platform_order_use_store_credit_service.constantize
122
+ end
123
+
124
+ def complete_service
125
+ Spree::Api::Dependencies.platform_order_complete_service.constantize
126
+ end
127
+
128
+ def empty_service
129
+ Spree::Api::Dependencies.platform_order_empty_service.constantize
130
+ end
131
+
132
+ def destroy_service
133
+ Spree::Api::Dependencies.platform_order_destroy_service.constantize
134
+ end
135
+
136
+ def approve_service
137
+ Spree::Api::Dependencies.platform_order_approve_service.constantize
138
+ end
139
+
140
+ def cancel_service
141
+ Spree::Api::Dependencies.platform_order_cancel_service.constantize
142
+ end
143
+
144
+ def coupon_handler
145
+ Spree::Api::Dependencies.platform_coupon_handler.constantize
146
+ end
147
+
148
+ def spree_permitted_attributes
149
+ super + [
150
+ bill_address_attributes: Spree::Address.json_api_permitted_attributes,
151
+ ship_address_attributes: Spree::Address.json_api_permitted_attributes,
152
+ line_items_attributes: Spree::LineItem.json_api_permitted_attributes,
153
+ payments_attributes: Spree::Payment.json_api_permitted_attributes + [
154
+ source_attributes: Spree::CreditCard.json_api_permitted_attributes
155
+ ],
156
+ shipments_attributes: Spree::Shipment.json_api_permitted_attributes
157
+ ]
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end