spree_api 4.3.3 → 4.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/spree/api/v2/caching.rb +7 -3
- data/app/controllers/concerns/spree/api/v2/coupon_codes_helper.rb +29 -0
- data/app/controllers/concerns/spree/api/v2/number_resource.rb +11 -0
- data/app/controllers/concerns/spree/api/v2/platform/nested_set_reposition_concern.rb +37 -0
- data/app/controllers/concerns/spree/api/v2/platform/promotion_calculator_params.rb +17 -0
- data/app/controllers/concerns/spree/api/v2/platform/promotion_rule_params.rb +16 -0
- data/app/controllers/concerns/spree/api/v2/storefront/metadata_controller_concern.rb +18 -0
- data/app/controllers/spree/api/v1/checkouts_controller.rb +1 -1
- data/app/controllers/spree/api/v2/base_controller.rb +6 -5
- data/app/controllers/spree/api/v2/platform/adjustments_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/classifications_controller.rb +1 -22
- data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +4 -0
- data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +13 -18
- data/app/controllers/spree/api/v2/platform/digital_links_controller.rb +25 -0
- data/app/controllers/spree/api/v2/platform/digitals_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/line_items_controller.rb +59 -0
- data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +5 -19
- data/app/controllers/spree/api/v2/platform/menus_controller.rb +0 -4
- data/app/controllers/spree/api/v2/platform/orders_controller.rb +163 -0
- data/app/controllers/spree/api/v2/platform/payment_methods_controller.rb +27 -0
- data/app/controllers/spree/api/v2/platform/payments_controller.rb +17 -0
- data/app/controllers/spree/api/v2/platform/promotion_actions_controller.rb +30 -0
- data/app/controllers/spree/api/v2/platform/promotion_categories_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/promotion_rules_controller.rb +25 -0
- data/app/controllers/spree/api/v2/platform/promotions_controller.rb +31 -0
- data/app/controllers/spree/api/v2/platform/resource_controller.rb +47 -16
- data/app/controllers/spree/api/v2/platform/roles_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/shipments_controller.rb +143 -0
- data/app/controllers/spree/api/v2/platform/shipping_categories_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/shipping_methods_controller.rb +24 -0
- data/app/controllers/spree/api/v2/platform/states_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/stock_items_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/stock_locations_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/store_credit_categories_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/store_credit_types_controller.rb +15 -0
- data/app/controllers/spree/api/v2/platform/store_credits_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/tax_categories_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/tax_rates_controller.rb +23 -0
- data/app/controllers/spree/api/v2/platform/taxonomies_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/taxons_controller.rb +25 -0
- data/app/controllers/spree/api/v2/platform/users_controller.rb +4 -0
- data/app/controllers/spree/api/v2/platform/variants_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/webhooks/events_controller.rb +21 -0
- data/app/controllers/spree/api/v2/platform/webhooks/subscribers_controller.rb +21 -0
- data/app/controllers/spree/api/v2/platform/wished_items_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/wishlists_controller.rb +19 -0
- data/app/controllers/spree/api/v2/platform/zones_controller.rb +19 -0
- data/app/controllers/spree/api/v2/resource_controller.rb +3 -3
- data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +2 -2
- data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +4 -1
- data/app/controllers/spree/api/v2/storefront/cart_controller.rb +18 -28
- data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +24 -0
- data/app/controllers/spree/api/v2/storefront/digitals_controller.rb +54 -0
- data/app/controllers/spree/api/v2/storefront/wishlists_controller.rb +171 -0
- data/app/helpers/spree/api/v2/collection_options_helpers.rb +1 -1
- data/app/jobs/spree/webhooks/subscribers/make_request_job.rb +17 -0
- data/app/models/concerns/spree/webhooks/has_webhooks.rb +58 -0
- data/app/models/spree/api/webhooks/order_decorator.rb +43 -0
- data/app/models/spree/api/webhooks/payment_decorator.rb +26 -0
- data/app/models/spree/api/webhooks/product_decorator.rb +27 -0
- data/app/models/spree/api/webhooks/shipment_decorator.rb +21 -0
- data/app/models/spree/api/webhooks/stock_item_decorator.rb +43 -0
- data/app/models/spree/api/webhooks/stock_movement_decorator.rb +52 -0
- data/app/models/spree/api/webhooks/variant_decorator.rb +26 -0
- data/app/models/spree/oauth_access_grant.rb +7 -0
- data/app/models/spree/oauth_access_token.rb +7 -0
- data/app/models/spree/oauth_application.rb +15 -0
- data/app/models/spree/webhooks/base.rb +11 -0
- data/app/models/spree/webhooks/event.rb +12 -0
- data/app/models/spree/webhooks/subscriber.rb +57 -0
- data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +19 -1
- data/app/serializers/spree/api/v2/base_serializer.rb +11 -4
- data/app/serializers/spree/api/v2/platform/address_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/adjustment_serializer.rb +20 -0
- data/app/serializers/spree/api/v2/platform/asset_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/calculator_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/classification_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +8 -1
- data/app/serializers/spree/api/v2/platform/country_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/credit_card_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/customer_return_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/digital_link_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/digital_serializer.rb +30 -0
- data/app/serializers/spree/api/v2/platform/feature_page_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/homepage_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/inventory_unit_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/line_item_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/log_entry_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/menu_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/order_promotion_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/order_serializer.rb +31 -0
- data/app/serializers/spree/api/v2/platform/payment_capture_event_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/payment_method_serializer.rb +18 -0
- data/app/serializers/spree/api/v2/platform/payment_serializer.rb +21 -0
- data/app/serializers/spree/api/v2/platform/price_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/product_serializer.rb +7 -3
- data/app/serializers/spree/api/v2/platform/promotion_action_line_item_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/promotion_action_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/promotion_category_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/promotion_rule_serializer.rb +21 -0
- data/app/serializers/spree/api/v2/platform/promotion_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/property_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/prototype_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/refund_reason_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/refund_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/reimbursement_credit_serializer.rb +10 -0
- data/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb +18 -0
- data/app/serializers/spree/api/v2/platform/reimbursement_type_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/return_authorization_reason_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/return_authorization_serializer.rb +17 -0
- data/app/serializers/spree/api/v2/platform/return_item_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/role_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/shipment_serializer.rb +22 -0
- data/app/serializers/spree/api/v2/platform/shipping_category_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/shipping_method_serializer.rb +16 -0
- data/app/serializers/spree/api/v2/platform/shipping_rate_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/standard_page_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/state_change_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/state_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +1 -3
- data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +2 -4
- data/app/serializers/spree/api/v2/platform/stock_movement_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/stock_transfer_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/store_credit_category_serializer.rb +12 -0
- data/app/serializers/spree/api/v2/platform/store_credit_event_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/store_credit_serializer.rb +18 -0
- data/app/serializers/spree/api/v2/platform/store_credit_type_serializer.rb +12 -0
- data/app/serializers/spree/api/v2/platform/store_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +2 -2
- data/app/serializers/spree/api/v2/platform/tax_rate_serializer.rb +14 -0
- data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/user_serializer.rb +1 -1
- data/app/serializers/spree/api/v2/platform/variant_serializer.rb +3 -2
- data/app/serializers/spree/api/v2/platform/webhooks/event_serializer.rb +15 -0
- data/app/serializers/spree/api/v2/platform/webhooks/subscriber_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/wished_item_serializer.rb +29 -0
- data/app/serializers/spree/api/v2/platform/wishlist_serializer.rb +19 -0
- data/app/serializers/spree/api/v2/platform/zone_member_serializer.rb +13 -0
- data/app/serializers/spree/api/v2/platform/zone_serializer.rb +13 -0
- data/app/serializers/spree/v2/storefront/address_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/cart_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +5 -1
- data/app/serializers/spree/v2/storefront/credit_card_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/digital_link_serializer.rb +11 -0
- data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -2
- data/app/serializers/spree/v2/storefront/line_item_serializer.rb +2 -1
- data/app/serializers/spree/v2/storefront/option_type_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/option_value_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/payment_method_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/payment_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/product_serializer.rb +2 -2
- data/app/serializers/spree/v2/storefront/promotion_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/shipment_serializer.rb +2 -1
- data/app/serializers/spree/v2/storefront/store_credit_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/store_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/taxon_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/taxonomy_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/user_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/variant_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/wished_item_serializer.rb +29 -0
- data/app/serializers/spree/v2/storefront/wishlist_serializer.rb +17 -0
- data/app/services/spree/webhooks/subscribers/handle_request.rb +73 -0
- data/app/services/spree/webhooks/subscribers/make_request.rb +82 -0
- data/app/services/spree/webhooks/subscribers/queue_requests.rb +17 -0
- data/app/services/spree/webhooks.rb +13 -0
- data/config/i18n-tasks.yml +40 -0
- data/config/initializers/doorkeeper.rb +12 -12
- data/config/initializers/rabl.rb +2 -2
- data/config/locales/en.yml +29 -27
- data/config/routes.rb +83 -59
- data/db/migrate/20210902162826_create_spree_webhooks_tables.rb +16 -0
- data/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb +21 -0
- data/db/migrate/20211025162826_create_spree_webhooks_events.rb +14 -0
- data/docs/oauth/index.yml +126 -33
- data/docs/v2/platform/index.yaml +19100 -1736
- data/docs/v2/storefront/index.yaml +14797 -14609
- data/{app/models/spree → lib/spree/api}/api_dependencies.rb +56 -4
- data/lib/spree/api/engine.rb +24 -1
- data/lib/spree/api/testing_support/factories/oauth_application_factory.rb +6 -0
- data/lib/spree/api/testing_support/factories/webhook_event_factory.rb +27 -0
- data/lib/spree/api/testing_support/factories/webhook_subscriber_factory.rb +13 -0
- data/lib/spree/api/testing_support/factories.rb +3 -0
- data/lib/spree/api/testing_support/helpers.rb +1 -1
- data/lib/spree/api/testing_support/jobs.rb +18 -0
- data/lib/spree/api/testing_support/matchers/webhooks.rb +67 -0
- data/lib/spree/api/testing_support/serializers.rb +25 -0
- data/lib/spree/api/testing_support/spree_webhooks.rb +9 -0
- data/lib/spree/api/testing_support/v2/base.rb +1 -1
- data/lib/spree/api/testing_support/v2/current_order.rb +34 -1
- data/lib/spree/api/testing_support/v2/platform_contexts.rb +101 -52
- data/lib/spree/api/testing_support/v2/serializers_params.rb +3 -1
- data/lib/spree/api.rb +1 -0
- data/spec/fixtures/files/icon_256x256.jpg +0 -0
- data/spree_api.gemspec +16 -15
- metadata +177 -30
- data/app/controllers/spree/api/errors_controller.rb +0 -9
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class VariantsController < ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def model_class
|
9
|
+
Spree::Variant
|
10
|
+
end
|
11
|
+
|
12
|
+
def spree_permitted_attributes
|
13
|
+
super + [:option_value_ids, :price, :currency]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
module Webhooks
|
6
|
+
class EventsController < ResourceController
|
7
|
+
private
|
8
|
+
|
9
|
+
def model_class
|
10
|
+
Spree::Webhooks::Event
|
11
|
+
end
|
12
|
+
|
13
|
+
def scope_includes
|
14
|
+
%i[subscriber]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
module Webhooks
|
6
|
+
class SubscribersController < ResourceController
|
7
|
+
private
|
8
|
+
|
9
|
+
def model_class
|
10
|
+
Spree::Webhooks::Subscriber
|
11
|
+
end
|
12
|
+
|
13
|
+
def spree_permitted_attributes
|
14
|
+
super + [{ subscriptions: [] }]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class WishedItemsController < ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def scope_includes
|
9
|
+
[:variant]
|
10
|
+
end
|
11
|
+
|
12
|
+
def model_class
|
13
|
+
Spree::WishedItem
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Platform
|
5
|
+
class WishlistsController < ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def model_class
|
9
|
+
Spree::Wishlist
|
10
|
+
end
|
11
|
+
|
12
|
+
def scope_includes
|
13
|
+
[:wished_items]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -24,11 +24,11 @@ module Spree
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def allowed_sort_attributes
|
27
|
-
|
27
|
+
default_sort_attributes
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
[:id, :name, :number, :position, :updated_at, :created_at]
|
30
|
+
def default_sort_attributes
|
31
|
+
[:id, :name, :slug, :number, :position, :updated_at, :created_at, :deleted_at]
|
32
32
|
end
|
33
33
|
|
34
34
|
def scope(skip_cancancan: false)
|
@@ -59,11 +59,11 @@ module Spree
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def create_service
|
62
|
-
Spree::Api::Dependencies.
|
62
|
+
Spree::Api::Dependencies.storefront_address_create_service.constantize
|
63
63
|
end
|
64
64
|
|
65
65
|
def update_service
|
66
|
-
Spree::Api::Dependencies.
|
66
|
+
Spree::Api::Dependencies.storefront_address_update_service.constantize
|
67
67
|
end
|
68
68
|
|
69
69
|
def address_params
|
@@ -23,7 +23,10 @@ module Spree
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def scope
|
26
|
-
super.where(
|
26
|
+
super.not_expired.not_removed.where(
|
27
|
+
user: spree_current_user,
|
28
|
+
payment_method: current_store.payment_methods.available_on_front_end
|
29
|
+
)
|
27
30
|
end
|
28
31
|
|
29
32
|
def collection_serializer
|
@@ -3,7 +3,11 @@ module Spree
|
|
3
3
|
module V2
|
4
4
|
module Storefront
|
5
5
|
class CartController < ::Spree::Api::V2::BaseController
|
6
|
-
include
|
6
|
+
include OrderConcern
|
7
|
+
include CouponCodesHelper
|
8
|
+
include Spree::Api::V2::Storefront::MetadataControllerConcern
|
9
|
+
|
10
|
+
before_action :ensure_valid_metadata, only: %i[create add_item]
|
7
11
|
before_action :ensure_order, except: %i[create associate]
|
8
12
|
before_action :load_variant, only: :add_item
|
9
13
|
before_action :require_spree_current_user, only: :associate
|
@@ -12,14 +16,16 @@ module Spree
|
|
12
16
|
def create
|
13
17
|
spree_authorize! :create, Spree::Order
|
14
18
|
|
15
|
-
|
19
|
+
create_cart_params = {
|
16
20
|
user: spree_current_user,
|
17
21
|
store: current_store,
|
18
|
-
currency: current_currency
|
22
|
+
currency: current_currency,
|
23
|
+
public_metadata: add_item_params[:public_metadata],
|
24
|
+
private_metadata: add_item_params[:private_metadata],
|
19
25
|
}
|
20
26
|
|
21
27
|
order = spree_current_order if spree_current_order.present?
|
22
|
-
order ||= create_service.call(
|
28
|
+
order ||= create_service.call(create_cart_params).value
|
23
29
|
|
24
30
|
render_serialized_payload(201) { serialize_resource(order) }
|
25
31
|
end
|
@@ -31,8 +37,10 @@ module Spree
|
|
31
37
|
result = add_item_service.call(
|
32
38
|
order: spree_current_order,
|
33
39
|
variant: @variant,
|
34
|
-
quantity:
|
35
|
-
|
40
|
+
quantity: add_item_params[:quantity],
|
41
|
+
public_metadata: add_item_params[:public_metadata],
|
42
|
+
private_metadata: add_item_params[:private_metadata],
|
43
|
+
options: add_item_params[:options]
|
36
44
|
)
|
37
45
|
|
38
46
|
render_order(result)
|
@@ -107,7 +115,7 @@ module Spree
|
|
107
115
|
|
108
116
|
coupon_codes = select_coupon_codes
|
109
117
|
|
110
|
-
return render_error_payload(
|
118
|
+
return render_error_payload(I18n.t('spree.api.v2.cart.no_coupon_code')) if coupon_codes.empty?
|
111
119
|
|
112
120
|
result_errors = coupon_codes.count > 1 ? select_errors(coupon_codes) : select_error(coupon_codes)
|
113
121
|
|
@@ -209,7 +217,7 @@ module Spree
|
|
209
217
|
end
|
210
218
|
|
211
219
|
def load_variant
|
212
|
-
@variant = current_store.variants.find(
|
220
|
+
@variant = current_store.variants.find(add_item_params[:variant_id])
|
213
221
|
end
|
214
222
|
|
215
223
|
def render_error_item_quantity
|
@@ -227,26 +235,8 @@ module Spree
|
|
227
235
|
).serializable_hash
|
228
236
|
end
|
229
237
|
|
230
|
-
def
|
231
|
-
params
|
232
|
-
end
|
233
|
-
|
234
|
-
def check_coupon_codes
|
235
|
-
spree_current_order.promotions.coupons.map(&:code)
|
236
|
-
end
|
237
|
-
|
238
|
-
def select_error(coupon_codes)
|
239
|
-
result = coupon_handler.new(spree_current_order).remove(coupon_codes.first)
|
240
|
-
result.error
|
241
|
-
end
|
242
|
-
|
243
|
-
def select_errors(coupon_codes)
|
244
|
-
results = []
|
245
|
-
coupon_codes.each do |coupon_code|
|
246
|
-
results << coupon_handler.new(spree_current_order).remove(coupon_code)
|
247
|
-
end
|
248
|
-
|
249
|
-
results.select(&:error)
|
238
|
+
def add_item_params
|
239
|
+
params.permit(:quantity, :variant_id, public_metadata: {}, private_metadata: {}, options: {})
|
250
240
|
end
|
251
241
|
end
|
252
242
|
end
|
@@ -44,6 +44,22 @@ module Spree
|
|
44
44
|
render_order(result)
|
45
45
|
end
|
46
46
|
|
47
|
+
def create_payment
|
48
|
+
result = create_payment_service.call(order: spree_current_order, params: params)
|
49
|
+
|
50
|
+
if result.success?
|
51
|
+
render_serialized_payload(201) { serialize_resource(spree_current_order.reload) }
|
52
|
+
else
|
53
|
+
render_error_payload(result.error)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def select_shipping_method
|
58
|
+
result = select_shipping_method_service.call(order: spree_current_order, params: params)
|
59
|
+
|
60
|
+
render_order(result)
|
61
|
+
end
|
62
|
+
|
47
63
|
def add_store_credit
|
48
64
|
spree_authorize! :update, spree_current_order, order_token
|
49
65
|
|
@@ -118,6 +134,14 @@ module Spree
|
|
118
134
|
Spree::Api::Dependencies.storefront_shipment_serializer.constantize
|
119
135
|
end
|
120
136
|
|
137
|
+
def create_payment_service
|
138
|
+
Spree::Api::Dependencies.storefront_payment_create_service.constantize
|
139
|
+
end
|
140
|
+
|
141
|
+
def select_shipping_method_service
|
142
|
+
Spree::Api::Dependencies.storefront_checkout_select_shipping_method_service.constantize
|
143
|
+
end
|
144
|
+
|
121
145
|
def serialize_payment_methods(payment_methods)
|
122
146
|
payment_methods_serializer.new(payment_methods, params: serializer_params).serializable_hash
|
123
147
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class DigitalsController < ::Spree::Api::V2::ResourceController
|
6
|
+
def download
|
7
|
+
if attachment.present?
|
8
|
+
if digital_link.authorize!
|
9
|
+
if defined?(ActiveStorage::Service::DiskService) && ActiveStorage::Blob.service.instance_of?(ActiveStorage::Service::DiskService)
|
10
|
+
# The asset is hosted on disk, use send_file.
|
11
|
+
|
12
|
+
send_file(
|
13
|
+
ActiveStorage::Blob.service.path_for(attachment.key),
|
14
|
+
filename: attachment.filename.to_s,
|
15
|
+
type: attachment.content_type.to_s,
|
16
|
+
status: :ok
|
17
|
+
) and return
|
18
|
+
|
19
|
+
else
|
20
|
+
# The asset is hosted on a 3rd party service, use an expiring url with disposition: 'attachment'.
|
21
|
+
|
22
|
+
redirect_to attachment.url(
|
23
|
+
expires_in: current_store.digital_asset_link_expire_time.seconds,
|
24
|
+
disposition: 'attachment',
|
25
|
+
host: current_store.formatted_url
|
26
|
+
) and return
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
Rails.logger.error I18n.t('spree.api.v2.digitals.missing_file')
|
32
|
+
end
|
33
|
+
|
34
|
+
render json: { error: I18n.t('spree.api.v2.digitals.unauthorized') }, status: 403
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def model_class
|
40
|
+
Spree::Digital
|
41
|
+
end
|
42
|
+
|
43
|
+
def digital_link
|
44
|
+
@digital_link ||= DigitalLink.find_by!(token: params[:token])
|
45
|
+
end
|
46
|
+
|
47
|
+
def attachment
|
48
|
+
@attachment ||= digital_link.digital.try(:attachment) if digital_link.present?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class WishlistsController < ::Spree::Api::V2::ResourceController
|
6
|
+
before_action :require_spree_current_user, except: [:show]
|
7
|
+
before_action :ensure_valid_quantity, only: [:add_item, :set_item_quantity]
|
8
|
+
|
9
|
+
def show
|
10
|
+
spree_authorize! :show, resource
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
spree_authorize! :create, Spree::Wishlist
|
16
|
+
|
17
|
+
@wishlist = spree_current_user.wishlists.new(wishlist_attributes)
|
18
|
+
|
19
|
+
ensure_current_store(@wishlist)
|
20
|
+
|
21
|
+
@wishlist.save
|
22
|
+
|
23
|
+
if @wishlist.persisted?
|
24
|
+
render_serialized_payload(201) { serialize_resource(@wishlist) }
|
25
|
+
else
|
26
|
+
render_error_payload(@wishlist.errors.full_messages.to_sentence)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
authorize! :update, resource
|
32
|
+
|
33
|
+
resource.update wishlist_attributes
|
34
|
+
|
35
|
+
if resource.errors.empty?
|
36
|
+
render_serialized_payload { serialize_resource(resource) }
|
37
|
+
else
|
38
|
+
render_error_payload(resource.errors.full_messages.to_sentence)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy
|
43
|
+
authorize! :destroy, resource
|
44
|
+
|
45
|
+
if resource.destroy
|
46
|
+
head 204
|
47
|
+
else
|
48
|
+
render_error_payload(I18n.t('spree.api.v2.wishlist.errors.the_wishlist_could_not_be_destroyed'))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def default
|
53
|
+
spree_authorize! :create, Spree::Wishlist
|
54
|
+
|
55
|
+
@default_wishlist = spree_current_user.default_wishlist_for_store(current_store)
|
56
|
+
|
57
|
+
render_serialized_payload { serialize_resource(@default_wishlist) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_item
|
61
|
+
spree_authorize! :create, Spree::WishedItem
|
62
|
+
|
63
|
+
if resource.wished_items.present? && resource.wished_items.detect { |wv| wv.variant_id.to_s == params[:variant_id].to_s }.present?
|
64
|
+
@wished_item = resource.wished_items.detect { |wi| wi.variant_id.to_s == params[:variant_id].to_s }
|
65
|
+
@wished_item.quantity = params[:quantity]
|
66
|
+
else
|
67
|
+
@wished_item = Spree::WishedItem.new(params.permit(:quantity, :variant_id))
|
68
|
+
@wished_item.wishlist = resource
|
69
|
+
@wished_item.save
|
70
|
+
end
|
71
|
+
|
72
|
+
resource.reload
|
73
|
+
|
74
|
+
if @wished_item.persisted?
|
75
|
+
render_serialized_payload { serialize_wished_item(@wished_item) }
|
76
|
+
else
|
77
|
+
render_error_payload(resource.errors.full_messages.to_sentence)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_item_quantity
|
82
|
+
spree_authorize! :update, wished_item
|
83
|
+
|
84
|
+
wished_item.update(params.permit(:quantity))
|
85
|
+
|
86
|
+
if wished_item.errors.empty?
|
87
|
+
render_serialized_payload { serialize_wished_item(wished_item) }
|
88
|
+
else
|
89
|
+
render_error_payload(resource.errors.full_messages.to_sentence)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def remove_item
|
94
|
+
spree_authorize! :destroy, wished_item
|
95
|
+
|
96
|
+
if wished_item.destroy
|
97
|
+
render_serialized_payload { serialize_wished_item(wished_item) }
|
98
|
+
else
|
99
|
+
render_error_payload(resource.errors.full_messages.to_sentence)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def scope(skip_cancancan: true)
|
106
|
+
if action_name == 'show'
|
107
|
+
super
|
108
|
+
else
|
109
|
+
super.where(user: spree_current_user)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def resource
|
114
|
+
@resource ||= scope.find_by(token: params[:id])
|
115
|
+
end
|
116
|
+
|
117
|
+
def model_class
|
118
|
+
Spree::Wishlist
|
119
|
+
end
|
120
|
+
|
121
|
+
def resource_serializer
|
122
|
+
::Spree::V2::Storefront::WishlistSerializer
|
123
|
+
end
|
124
|
+
|
125
|
+
def collection_serializer
|
126
|
+
resource_serializer
|
127
|
+
end
|
128
|
+
|
129
|
+
def wishlist_attributes
|
130
|
+
params.require(:wishlist).permit(permitted_wishlist_attributes)
|
131
|
+
end
|
132
|
+
|
133
|
+
def wished_item_attributes
|
134
|
+
params.permit(permitted_wished_item_attributes)
|
135
|
+
end
|
136
|
+
|
137
|
+
def wished_item
|
138
|
+
@wished_item ||= resource.wished_items.find(params[:item_id])
|
139
|
+
end
|
140
|
+
|
141
|
+
def serialize_wished_item(wished_item)
|
142
|
+
::Spree::V2::Storefront::WishedItemSerializer.new(
|
143
|
+
wished_item,
|
144
|
+
params: serializer_params,
|
145
|
+
include: resource_includes,
|
146
|
+
fields: sparse_fields
|
147
|
+
).serializable_hash
|
148
|
+
end
|
149
|
+
|
150
|
+
def serializer_params
|
151
|
+
super.merge(is_variant_included: params[:is_variant_included])
|
152
|
+
end
|
153
|
+
|
154
|
+
def render_error_item_quantity
|
155
|
+
render json: { error: I18n.t('spree.api.v2.wishlist.wrong_quantity') }, status: 422
|
156
|
+
end
|
157
|
+
|
158
|
+
def ensure_valid_quantity
|
159
|
+
return render_error_item_quantity if params[:quantity].present? && params[:quantity].to_i <= 0
|
160
|
+
|
161
|
+
params[:quantity] = if params[:quantity].present?
|
162
|
+
params[:quantity].to_i
|
163
|
+
else
|
164
|
+
1
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -23,7 +23,7 @@ module Spree
|
|
23
23
|
# leaving this method in public scope so it's still possible to modify
|
24
24
|
# those params to support non-standard non-JSON API parameters
|
25
25
|
def collection_permitted_params
|
26
|
-
params.permit(:format, :page, :per_page, :sort, :include, :
|
26
|
+
params.permit(:format, :page, :per_page, :sort, :include, fields: {}, filter: {})
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spree
|
2
|
+
module Webhooks
|
3
|
+
module Subscribers
|
4
|
+
class MakeRequestJob < Spree::BaseJob
|
5
|
+
queue_as :spree_webhooks
|
6
|
+
|
7
|
+
def perform(webhook_payload_body, event_name, subscriber)
|
8
|
+
Spree::Webhooks::Subscribers::HandleRequest.new(
|
9
|
+
event_name: event_name,
|
10
|
+
subscriber: subscriber,
|
11
|
+
webhook_payload_body: webhook_payload_body
|
12
|
+
).call
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Spree
|
2
|
+
module Webhooks
|
3
|
+
module HasWebhooks
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
after_create_commit(proc { queue_webhooks_requests!(inferred_event_name(:create)) })
|
8
|
+
after_destroy_commit(proc { queue_webhooks_requests!(inferred_event_name(:delete)) })
|
9
|
+
after_update_commit(proc { queue_webhooks_requests!(inferred_event_name(:update)) })
|
10
|
+
|
11
|
+
def queue_webhooks_requests!(event_name)
|
12
|
+
return if disable_spree_webhooks? || webhook_payload_body.blank?
|
13
|
+
return if update_event?(event_name) && updating_only_timestamps?
|
14
|
+
|
15
|
+
Spree::Webhooks::Subscribers::QueueRequests.call(event_name: event_name, webhook_payload_body: webhook_payload_body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.default_webhook_events
|
19
|
+
model_name = name.demodulize.tableize.singularize
|
20
|
+
%W[#{model_name}.create #{model_name}.delete #{model_name}.update]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.supported_webhook_events
|
24
|
+
events = default_webhook_events
|
25
|
+
events += custom_webhook_events if respond_to?(:custom_webhook_events)
|
26
|
+
events
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def webhook_payload_body
|
33
|
+
resource_serializer.new(self).serializable_hash.to_json
|
34
|
+
end
|
35
|
+
|
36
|
+
def inferred_event_name(operation)
|
37
|
+
"#{self.class.name.demodulize.tableize.singularize}.#{operation}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def resource_serializer
|
41
|
+
demodulized_class_name = self.class.to_s.demodulize
|
42
|
+
"Spree::Api::V2::Platform::#{demodulized_class_name}Serializer".constantize
|
43
|
+
end
|
44
|
+
|
45
|
+
def updating_only_timestamps?
|
46
|
+
(saved_changes.keys - %w[created_at updated_at deleted_at]).empty?
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_event?(event_name)
|
50
|
+
event_name.end_with?('.update')
|
51
|
+
end
|
52
|
+
|
53
|
+
def disable_spree_webhooks?
|
54
|
+
ENV['DISABLE_SPREE_WEBHOOKS'] == 'true'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module Webhooks
|
4
|
+
module OrderDecorator
|
5
|
+
def self.prepended(base)
|
6
|
+
def base.custom_webhook_events
|
7
|
+
%w[order.canceled order.placed order.resumed order.shipped]
|
8
|
+
end
|
9
|
+
|
10
|
+
base.after_update_commit :queue_webhooks_requests_for_order_resumed!
|
11
|
+
end
|
12
|
+
|
13
|
+
def after_cancel
|
14
|
+
super
|
15
|
+
queue_webhooks_requests!('order.canceled')
|
16
|
+
end
|
17
|
+
|
18
|
+
def finalize!
|
19
|
+
super
|
20
|
+
queue_webhooks_requests!('order.placed')
|
21
|
+
end
|
22
|
+
|
23
|
+
def after_resume
|
24
|
+
super
|
25
|
+
queue_webhooks_requests!('order.resumed')
|
26
|
+
self.state_machine_resumed = false
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def queue_webhooks_requests_for_order_resumed!
|
32
|
+
return if state_machine_resumed?
|
33
|
+
return unless state_previously_changed?
|
34
|
+
return unless state_previous_change&.last == 'resumed'
|
35
|
+
|
36
|
+
queue_webhooks_requests!('order.resumed')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Spree::Order.prepend(Spree::Api::Webhooks::OrderDecorator)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module Webhooks
|
4
|
+
module PaymentDecorator
|
5
|
+
def self.prepended(base)
|
6
|
+
def base.custom_webhook_events
|
7
|
+
%w[payment.paid payment.voided]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def after_void
|
12
|
+
super
|
13
|
+
queue_webhooks_requests!('payment.voided')
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_completed
|
17
|
+
super
|
18
|
+
queue_webhooks_requests!('payment.paid')
|
19
|
+
order.queue_webhooks_requests!('order.paid') if order.paid?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Spree::Payment.prepend(Spree::Api::Webhooks::PaymentDecorator)
|