spree_api 4.8.3 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +57 -0
- data/app/controllers/concerns/spree/api/v2/caching.rb +12 -9
- data/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb +2 -2
- data/app/controllers/spree/api/v2/base_controller.rb +7 -1
- data/app/controllers/spree/api/v2/platform/resource_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +1 -1
- data/app/controllers/spree/api/v2/storefront/products_controller.rb +8 -1
- data/app/controllers/spree/api/v2/storefront/variants_controller.rb +41 -0
- data/app/controllers/spree/api/v2/storefront/wishlists_controller.rb +43 -0
- data/app/models/concerns/spree/webhooks/has_webhooks.rb +13 -5
- data/app/models/spree/oauth_application.rb +7 -0
- data/app/models/spree/order/webhooks.rb +39 -0
- data/app/models/spree/payment/webhooks.rb +23 -0
- data/app/models/spree/product/webhooks.rb +42 -0
- data/app/models/spree/shipment/webhooks.rb +19 -0
- data/app/models/spree/stock_item/webhooks.rb +40 -0
- data/app/models/spree/stock_movement/webhooks.rb +49 -0
- data/app/models/spree/variant/webhooks.rb +25 -0
- data/app/models/spree/webhooks/subscriber.rb +4 -0
- data/app/serializers/spree/api/v2/platform/admin_user_serializer.rb +11 -0
- data/app/serializers/spree/api/v2/platform/refund_serializer.rb +1 -0
- data/app/serializers/spree/api/v2/platform/store_credit_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/credit_card_serializer.rb +1 -1
- data/app/serializers/spree/v2/storefront/shipping_category_serializer.rb +10 -0
- data/app/serializers/spree/v2/storefront/shipping_method_serializer.rb +10 -0
- data/app/services/spree/api/error_handler.rb +1 -0
- data/app/services/spree/webhooks/subscribers/handle_request.rb +4 -4
- data/app/services/spree/webhooks/subscribers/make_request.rb +2 -2
- data/app/services/spree/webhooks/subscribers/queue_requests.rb +3 -3
- data/config/initializers/doorkeeper.rb +2 -0
- data/config/routes.rb +4 -1
- data/lib/spree/api/configuration.rb +3 -1
- data/lib/spree/api/dependencies.rb +5 -1
- data/lib/spree/api/engine.rb +0 -8
- data/lib/spree/api/testing_support/matchers/webhooks.rb +4 -4
- data/lib/spree/api/testing_support/spree_webhooks.rb +2 -2
- data/spree_api.gemspec +3 -3
- metadata +22 -15
- data/LICENSE +0 -26
- data/app/models/spree/api/webhooks/order_decorator.rb +0 -43
- data/app/models/spree/api/webhooks/payment_decorator.rb +0 -26
- data/app/models/spree/api/webhooks/product_decorator.rb +0 -46
- data/app/models/spree/api/webhooks/shipment_decorator.rb +0 -21
- data/app/models/spree/api/webhooks/stock_item_decorator.rb +0 -43
- data/app/models/spree/api/webhooks/stock_movement_decorator.rb +0 -52
- data/app/models/spree/api/webhooks/variant_decorator.rb +0 -26
|
@@ -32,6 +32,7 @@ module Spree
|
|
|
32
32
|
def report_error(exception:, message:, opts:)
|
|
33
33
|
# overwrite this method in your application to support different error handlers
|
|
34
34
|
# eg. Sentry, Rollbar, etc
|
|
35
|
+
Sentry.capture_exception(exception) if defined?(Sentry)
|
|
35
36
|
|
|
36
37
|
success(exception: exception, message: message)
|
|
37
38
|
end
|
|
@@ -19,7 +19,7 @@ module Spree
|
|
|
19
19
|
end
|
|
20
20
|
return process(:warn, msg("failed for '#{url}'")) if request.failed_request?
|
|
21
21
|
|
|
22
|
-
process
|
|
22
|
+
process
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
private
|
|
@@ -30,8 +30,8 @@ module Spree
|
|
|
30
30
|
delegate :id, :url, to: :subscriber
|
|
31
31
|
delegate :created_at, :id, to: :event, prefix: true
|
|
32
32
|
|
|
33
|
-
def process(log_level, msg)
|
|
34
|
-
Rails.logger.public_send(log_level, msg)
|
|
33
|
+
def process(log_level = nil, msg = nil)
|
|
34
|
+
Rails.logger.public_send(log_level, msg) if msg.present? && log_level.present?
|
|
35
35
|
make_request
|
|
36
36
|
update_event(msg)
|
|
37
37
|
nil
|
|
@@ -59,7 +59,7 @@ module Spree
|
|
|
59
59
|
)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
def update_event(msg)
|
|
62
|
+
def update_event(msg = nil)
|
|
63
63
|
event.update(
|
|
64
64
|
execution_time: execution_time,
|
|
65
65
|
request_errors: msg,
|
|
@@ -45,7 +45,7 @@ module Spree
|
|
|
45
45
|
def http
|
|
46
46
|
http = Net::HTTP.new(uri_host, uri_port)
|
|
47
47
|
http.read_timeout = webhooks_timeout.to_i if custom_read_timeout?
|
|
48
|
-
http.use_ssl =
|
|
48
|
+
http.use_ssl = use_ssl?
|
|
49
49
|
http
|
|
50
50
|
end
|
|
51
51
|
|
|
@@ -71,7 +71,7 @@ module Spree
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def use_ssl?
|
|
74
|
-
|
|
74
|
+
uri.scheme == 'https'
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def uri
|
|
@@ -4,8 +4,8 @@ module Spree
|
|
|
4
4
|
class QueueRequests
|
|
5
5
|
prepend Spree::ServiceModule::Base
|
|
6
6
|
|
|
7
|
-
def call(event_name:, webhook_payload_body:, **options)
|
|
8
|
-
filtered_subscribers(event_name, webhook_payload_body, options).each do |subscriber|
|
|
7
|
+
def call(event_name:, webhook_payload_body:, record: nil, **options)
|
|
8
|
+
filtered_subscribers(event_name, webhook_payload_body, record, options).each do |subscriber|
|
|
9
9
|
Spree::Webhooks::Subscribers::MakeRequestJob.perform_later(
|
|
10
10
|
webhook_payload_body, event_name, subscriber
|
|
11
11
|
)
|
|
@@ -14,7 +14,7 @@ module Spree
|
|
|
14
14
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
|
-
def filtered_subscribers(event_name,
|
|
17
|
+
def filtered_subscribers(event_name, webhook_payload_body, record, options)
|
|
18
18
|
Spree::Webhooks::Subscriber.active.with_urls_for(event_name)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -45,4 +45,6 @@ Doorkeeper.configure do
|
|
|
45
45
|
# using Bcrupt for token secrets is currently not supported by Doorkeeper
|
|
46
46
|
hash_token_secrets fallback: :plain
|
|
47
47
|
hash_application_secrets fallback: :plain, using: '::Doorkeeper::SecretStoring::BCrypt'
|
|
48
|
+
|
|
49
|
+
access_token_expires_in 1.month
|
|
48
50
|
end
|
data/config/routes.rb
CHANGED
|
@@ -14,7 +14,7 @@ Spree::Core::Engine.add_routes do
|
|
|
14
14
|
delete 'remove_line_item/:line_item_id', to: 'cart#remove_line_item', as: :cart_remove_line_item
|
|
15
15
|
patch :set_quantity
|
|
16
16
|
patch :apply_coupon_code
|
|
17
|
-
delete 'remove_coupon_code/:coupon_code', to: 'cart#remove_coupon_code', as: :cart_remove_coupon_code
|
|
17
|
+
delete 'remove_coupon_code/:coupon_code', to: 'cart#remove_coupon_code', as: :cart_remove_coupon_code, constraints: { coupon_code: /[^\/]+/ }
|
|
18
18
|
delete 'remove_coupon_code', to: 'cart#remove_coupon_code', as: :cart_remove_coupon_code_without_code
|
|
19
19
|
get :estimate_shipping_rates
|
|
20
20
|
patch :associate
|
|
@@ -45,6 +45,7 @@ Spree::Core::Engine.add_routes do
|
|
|
45
45
|
get '/countries/:iso', to: 'countries#show', as: :country
|
|
46
46
|
get '/order_status/:number', to: 'order_status#show', as: :order_status
|
|
47
47
|
resources :products, only: %i[index show]
|
|
48
|
+
get '/products/:id/variants', to: 'variants#index', as: :product_variants
|
|
48
49
|
resources :taxons, only: %i[index show], id: /.+/
|
|
49
50
|
get '/stores/:code', to: 'stores#show', as: :store
|
|
50
51
|
get '/store', to: 'stores#current', as: :current_store
|
|
@@ -59,6 +60,8 @@ Spree::Core::Engine.add_routes do
|
|
|
59
60
|
post :add_item
|
|
60
61
|
patch 'set_item_quantity/:item_id', to: 'wishlists#set_item_quantity', as: :set_item_quantity
|
|
61
62
|
delete 'remove_item/:item_id', to: 'wishlists#remove_item', as: :remove_item
|
|
63
|
+
post :add_items
|
|
64
|
+
delete :remove_items
|
|
62
65
|
end
|
|
63
66
|
end
|
|
64
67
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
require 'spree/core/preferences/runtime_configuration'
|
|
2
|
+
|
|
1
3
|
module Spree
|
|
2
4
|
module Api
|
|
3
|
-
class Configuration < Preferences::
|
|
5
|
+
class Configuration < Spree::Preferences::RuntimeConfiguration
|
|
4
6
|
preference :api_v2_serializers_cache_ttl, :integer, default: 3600 # 1 hour in seconds
|
|
5
7
|
preference :api_v2_collection_cache_ttl, :integer, default: 3600 # 1 hour in seconds
|
|
6
8
|
preference :api_v2_collection_cache_namespace, :string, default: 'api_v2_collection_cache'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'spree/core/dependencies_helper'
|
|
2
|
+
|
|
1
3
|
module Spree
|
|
2
4
|
module Api
|
|
3
5
|
class ApiDependencies
|
|
@@ -60,6 +62,7 @@ module Spree
|
|
|
60
62
|
storefront_estimated_shipment_serializer: 'Spree::V2::Storefront::EstimatedShippingRateSerializer',
|
|
61
63
|
storefront_store_serializer: 'Spree::V2::Storefront::StoreSerializer',
|
|
62
64
|
storefront_order_serializer: 'Spree::V2::Storefront::OrderSerializer',
|
|
65
|
+
storefront_variant_serializer: 'Spree::V2::Storefront::VariantSerializer',
|
|
63
66
|
|
|
64
67
|
# sorters
|
|
65
68
|
storefront_collection_sorter: -> { Spree::Dependencies.collection_sorter },
|
|
@@ -81,11 +84,12 @@ module Spree
|
|
|
81
84
|
storefront_find_by_variant_finder: -> { Spree::Dependencies.line_item_by_variant_finder },
|
|
82
85
|
storefront_products_finder: -> { Spree::Dependencies.products_finder },
|
|
83
86
|
storefront_taxon_finder: -> { Spree::Dependencies.taxon_finder },
|
|
87
|
+
storefront_variant_finder: -> { Spree::Dependencies.variant_finder },
|
|
84
88
|
|
|
85
89
|
error_handler: 'Spree::Api::ErrorHandler',
|
|
86
90
|
|
|
87
91
|
# serializers
|
|
88
|
-
platform_admin_user_serializer: 'Spree::Api::V2::Platform::
|
|
92
|
+
platform_admin_user_serializer: 'Spree::Api::V2::Platform::AdminUserSerializer',
|
|
89
93
|
|
|
90
94
|
# coupon code handler
|
|
91
95
|
platform_coupon_handler: -> { Spree::Dependencies.coupon_handler },
|
data/lib/spree/api/engine.rb
CHANGED
|
@@ -18,17 +18,9 @@ module Spree
|
|
|
18
18
|
Migrations.new(config, engine_name).check
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def self.activate
|
|
22
|
-
Dir.glob(File.join(File.dirname(__FILE__), '../../../app/models/spree/api/webhooks/*_decorator*.rb')) do |c|
|
|
23
|
-
Rails.application.config.cache_classes ? require(c) : load(c)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
21
|
def self.root
|
|
28
22
|
@root ||= Pathname.new(File.expand_path('../../..', __dir__))
|
|
29
23
|
end
|
|
30
|
-
|
|
31
|
-
config.to_prepare &method(:activate).to_proc
|
|
32
24
|
end
|
|
33
25
|
end
|
|
34
26
|
end
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
# isn't added to the matcher definition, because it acts in a different
|
|
27
27
|
# way depending on what's the resource being tested.
|
|
28
28
|
#
|
|
29
|
-
RSpec::Matchers.define :emit_webhook_event do |event_to_emit|
|
|
29
|
+
RSpec::Matchers.define :emit_webhook_event do |event_to_emit, record = nil|
|
|
30
30
|
match do |block|
|
|
31
31
|
queue_requests = instance_double(Spree::Webhooks::Subscribers::QueueRequests)
|
|
32
32
|
|
|
@@ -36,7 +36,7 @@ RSpec::Matchers.define :emit_webhook_event do |event_to_emit|
|
|
|
36
36
|
with_webhooks_enabled { Timecop.freeze { block.call } }
|
|
37
37
|
|
|
38
38
|
expect(queue_requests).to(
|
|
39
|
-
have_received(:call).with(event_name: event_to_emit, webhook_payload_body: webhook_payload_body.to_json).once
|
|
39
|
+
have_received(:call).with(event_name: event_to_emit, webhook_payload_body: webhook_payload_body.to_json, record: record).once
|
|
40
40
|
)
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -61,7 +61,7 @@ RSpec::Matchers.define :emit_webhook_event do |event_to_emit|
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def with_webhooks_enabled
|
|
64
|
-
|
|
64
|
+
Spree::Webhooks.disabled = false
|
|
65
65
|
yield
|
|
66
|
-
|
|
66
|
+
Spree::Webhooks.disabled = true
|
|
67
67
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
RSpec.configure do |config|
|
|
2
2
|
config.before(:each, :spree_webhooks) do
|
|
3
|
-
|
|
3
|
+
Spree::Webhooks.disabled = false
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
config.after(:each, :spree_webhooks) do
|
|
7
|
-
|
|
7
|
+
Spree::Webhooks.disabled = true
|
|
8
8
|
end
|
|
9
9
|
end
|
data/spree_api.gemspec
CHANGED
|
@@ -3,12 +3,12 @@ require_relative '../core/lib/spree/core/version'
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'spree_api'
|
|
5
5
|
s.version = Spree.version
|
|
6
|
-
s.authors = ['Ryan Bigg']
|
|
7
|
-
s.email = ['
|
|
6
|
+
s.authors = ['Ryan Bigg', 'Spark Solutions Sp. z o.o.', 'Vendo Connect Inc.']
|
|
7
|
+
s.email = ['hello@spreecommerce.org']
|
|
8
8
|
s.summary = %q{Spree's API}
|
|
9
9
|
s.description = %q{Spree's API}
|
|
10
10
|
s.homepage = 'https://spreecommerce.org'
|
|
11
|
-
s.
|
|
11
|
+
s.licenses = ['AGPL-3.0-or-later', 'BSD-3-Clause']
|
|
12
12
|
|
|
13
13
|
s.metadata = {
|
|
14
14
|
'bug_tracker_uri' => 'https://github.com/spree/spree/issues',
|
metadata
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spree_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Bigg
|
|
8
|
+
- Spark Solutions Sp. z o.o.
|
|
9
|
+
- Vendo Connect Inc.
|
|
8
10
|
autorequire:
|
|
9
11
|
bindir: bin
|
|
10
12
|
cert_chain: []
|
|
11
|
-
date: 2024-06
|
|
13
|
+
date: 2024-09-06 00:00:00.000000000 Z
|
|
12
14
|
dependencies:
|
|
13
15
|
- !ruby/object:Gem::Dependency
|
|
14
16
|
name: i18n-tasks
|
|
@@ -114,24 +116,24 @@ dependencies:
|
|
|
114
116
|
requirements:
|
|
115
117
|
- - '='
|
|
116
118
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: 4.
|
|
119
|
+
version: 4.10.0
|
|
118
120
|
type: :runtime
|
|
119
121
|
prerelease: false
|
|
120
122
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
123
|
requirements:
|
|
122
124
|
- - '='
|
|
123
125
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: 4.
|
|
126
|
+
version: 4.10.0
|
|
125
127
|
description: Spree's API
|
|
126
128
|
email:
|
|
127
|
-
-
|
|
129
|
+
- hello@spreecommerce.org
|
|
128
130
|
executables: []
|
|
129
131
|
extensions: []
|
|
130
132
|
extra_rdoc_files: []
|
|
131
133
|
files:
|
|
132
134
|
- ".gitignore"
|
|
133
135
|
- Gemfile
|
|
134
|
-
- LICENSE
|
|
136
|
+
- LICENSE.md
|
|
135
137
|
- Rakefile
|
|
136
138
|
- app/controllers/concerns/spree/api/v2/caching.rb
|
|
137
139
|
- app/controllers/concerns/spree/api/v2/coupon_codes_helper.rb
|
|
@@ -203,6 +205,7 @@ files:
|
|
|
203
205
|
- app/controllers/spree/api/v2/storefront/products_controller.rb
|
|
204
206
|
- app/controllers/spree/api/v2/storefront/stores_controller.rb
|
|
205
207
|
- app/controllers/spree/api/v2/storefront/taxons_controller.rb
|
|
208
|
+
- app/controllers/spree/api/v2/storefront/variants_controller.rb
|
|
206
209
|
- app/controllers/spree/api/v2/storefront/wishlists_controller.rb
|
|
207
210
|
- app/helpers/spree/api/v2/collection_options_helpers.rb
|
|
208
211
|
- app/helpers/spree/api/v2/display_money_helper.rb
|
|
@@ -211,16 +214,16 @@ files:
|
|
|
211
214
|
- app/models/concerns/spree/user_api_authentication.rb
|
|
212
215
|
- app/models/concerns/spree/user_api_methods.rb
|
|
213
216
|
- app/models/concerns/spree/webhooks/has_webhooks.rb
|
|
214
|
-
- app/models/spree/api/webhooks/order_decorator.rb
|
|
215
|
-
- app/models/spree/api/webhooks/payment_decorator.rb
|
|
216
|
-
- app/models/spree/api/webhooks/product_decorator.rb
|
|
217
|
-
- app/models/spree/api/webhooks/shipment_decorator.rb
|
|
218
|
-
- app/models/spree/api/webhooks/stock_item_decorator.rb
|
|
219
|
-
- app/models/spree/api/webhooks/stock_movement_decorator.rb
|
|
220
|
-
- app/models/spree/api/webhooks/variant_decorator.rb
|
|
221
217
|
- app/models/spree/oauth_access_grant.rb
|
|
222
218
|
- app/models/spree/oauth_access_token.rb
|
|
223
219
|
- app/models/spree/oauth_application.rb
|
|
220
|
+
- app/models/spree/order/webhooks.rb
|
|
221
|
+
- app/models/spree/payment/webhooks.rb
|
|
222
|
+
- app/models/spree/product/webhooks.rb
|
|
223
|
+
- app/models/spree/shipment/webhooks.rb
|
|
224
|
+
- app/models/spree/stock_item/webhooks.rb
|
|
225
|
+
- app/models/spree/stock_movement/webhooks.rb
|
|
226
|
+
- app/models/spree/variant/webhooks.rb
|
|
224
227
|
- app/models/spree/webhooks/base.rb
|
|
225
228
|
- app/models/spree/webhooks/event.rb
|
|
226
229
|
- app/models/spree/webhooks/event_signature.rb
|
|
@@ -232,6 +235,7 @@ files:
|
|
|
232
235
|
- app/serializers/spree/api/v2/base_serializer.rb
|
|
233
236
|
- app/serializers/spree/api/v2/platform/address_serializer.rb
|
|
234
237
|
- app/serializers/spree/api/v2/platform/adjustment_serializer.rb
|
|
238
|
+
- app/serializers/spree/api/v2/platform/admin_user_serializer.rb
|
|
235
239
|
- app/serializers/spree/api/v2/platform/asset_serializer.rb
|
|
236
240
|
- app/serializers/spree/api/v2/platform/base_serializer.rb
|
|
237
241
|
- app/serializers/spree/api/v2/platform/calculator_serializer.rb
|
|
@@ -337,6 +341,8 @@ files:
|
|
|
337
341
|
- app/serializers/spree/v2/storefront/product_serializer.rb
|
|
338
342
|
- app/serializers/spree/v2/storefront/promotion_serializer.rb
|
|
339
343
|
- app/serializers/spree/v2/storefront/shipment_serializer.rb
|
|
344
|
+
- app/serializers/spree/v2/storefront/shipping_category_serializer.rb
|
|
345
|
+
- app/serializers/spree/v2/storefront/shipping_method_serializer.rb
|
|
340
346
|
- app/serializers/spree/v2/storefront/shipping_rate_serializer.rb
|
|
341
347
|
- app/serializers/spree/v2/storefront/state_serializer.rb
|
|
342
348
|
- app/serializers/spree/v2/storefront/stock_location_serializer.rb
|
|
@@ -399,12 +405,13 @@ files:
|
|
|
399
405
|
- spree_api.gemspec
|
|
400
406
|
homepage: https://spreecommerce.org
|
|
401
407
|
licenses:
|
|
408
|
+
- AGPL-3.0-or-later
|
|
402
409
|
- BSD-3-Clause
|
|
403
410
|
metadata:
|
|
404
411
|
bug_tracker_uri: https://github.com/spree/spree/issues
|
|
405
|
-
changelog_uri: https://github.com/spree/spree/releases/tag/v4.
|
|
412
|
+
changelog_uri: https://github.com/spree/spree/releases/tag/v4.10.0
|
|
406
413
|
documentation_uri: https://docs.spreecommerce.org/
|
|
407
|
-
source_code_uri: https://github.com/spree/spree/tree/v4.
|
|
414
|
+
source_code_uri: https://github.com/spree/spree/tree/v4.10.0
|
|
408
415
|
post_install_message:
|
|
409
416
|
rdoc_options: []
|
|
410
417
|
require_paths:
|
data/LICENSE
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2007-2015, Spree Commerce, Inc. and other contributors
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
-
are permitted provided that the following conditions are met:
|
|
6
|
-
|
|
7
|
-
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
-
this list of conditions and the following disclaimer.
|
|
9
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
-
this list of conditions and the following disclaimer in the documentation
|
|
11
|
-
and/or other materials provided with the distribution.
|
|
12
|
-
* Neither the name Spree nor the names of its contributors may be used to
|
|
13
|
-
endorse or promote products derived from this software without specific
|
|
14
|
-
prior written permission.
|
|
15
|
-
|
|
16
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
20
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
21
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1,43 +0,0 @@
|
|
|
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)
|
|
@@ -1,26 +0,0 @@
|
|
|
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)
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module Webhooks
|
|
4
|
-
module ProductDecorator
|
|
5
|
-
def self.prepended(base)
|
|
6
|
-
def base.custom_webhook_events
|
|
7
|
-
%w[product.back_in_stock product.backorderable product.discontinued
|
|
8
|
-
product.out_of_stock product.activated product.archived product.drafted]
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def base.ignored_attributes_for_update_webhook_event
|
|
12
|
-
%w[status]
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
base.after_update_commit :queue_webhooks_requests_for_product_discontinued!
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def after_activate
|
|
19
|
-
super
|
|
20
|
-
queue_webhooks_requests!('product.activated')
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def after_archive
|
|
24
|
-
super
|
|
25
|
-
queue_webhooks_requests!('product.archived')
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def after_draft
|
|
29
|
-
super
|
|
30
|
-
queue_webhooks_requests!('product.drafted')
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
def queue_webhooks_requests_for_product_discontinued!
|
|
36
|
-
return unless discontinue_on_previously_changed?
|
|
37
|
-
return if (change = discontinue_on_previous_change).blank? || change.last.blank?
|
|
38
|
-
|
|
39
|
-
queue_webhooks_requests!('product.discontinued')
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
Spree::Product.prepend(Spree::Api::Webhooks::ProductDecorator)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module Webhooks
|
|
4
|
-
module ShipmentDecorator
|
|
5
|
-
def self.prepended(base)
|
|
6
|
-
def base.custom_webhook_events
|
|
7
|
-
%w[shipment.shipped]
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def after_ship
|
|
12
|
-
super
|
|
13
|
-
queue_webhooks_requests!('shipment.shipped')
|
|
14
|
-
order.queue_webhooks_requests!('order.shipped') if order.fully_shipped?
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
Spree::Shipment.prepend(Spree::Api::Webhooks::ShipmentDecorator)
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module Webhooks
|
|
4
|
-
module StockItemDecorator
|
|
5
|
-
def self.prepended(base)
|
|
6
|
-
base.around_save :queue_webhooks_requests_for_variant_backorderable!
|
|
7
|
-
base.around_save :queue_webhooks_requests_for_product_backorderable!
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
def queue_webhooks_requests_for_variant_backorderable!
|
|
13
|
-
was_out_of_stock = !variant.in_stock_or_backorderable?
|
|
14
|
-
was_not_backorderable = !variant_backorderable?
|
|
15
|
-
yield
|
|
16
|
-
if was_out_of_stock && was_not_backorderable && variant_backorderable?
|
|
17
|
-
reload
|
|
18
|
-
variant.queue_webhooks_requests!('variant.backorderable')
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def queue_webhooks_requests_for_product_backorderable!
|
|
23
|
-
product_was_out_of_stock = !product.any_variant_in_stock_or_backorderable?
|
|
24
|
-
product_was_not_backorderable = !product_backorderable?
|
|
25
|
-
yield
|
|
26
|
-
if product_was_out_of_stock && product_was_not_backorderable && product_backorderable?
|
|
27
|
-
variant.product.queue_webhooks_requests!('product.backorderable')
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def product_backorderable?
|
|
32
|
-
Spree::StockItem.exists?(backorderable: true, variant_id: variant.product.variants.ids)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def variant_backorderable?
|
|
36
|
-
variant.stock_items.exists?(backorderable: true)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
Spree::StockItem.prepend(Spree::Api::Webhooks::StockItemDecorator)
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module Webhooks
|
|
4
|
-
module StockMovementDecorator
|
|
5
|
-
def self.prepended(base)
|
|
6
|
-
base.around_save :queue_webhooks_requests_for_variant_out_of_stock!
|
|
7
|
-
base.around_save :queue_webhooks_requests_for_variant_back_in_stock!
|
|
8
|
-
base.around_save :queue_webhooks_requests_for_product_out_of_stock!
|
|
9
|
-
base.around_save :queue_webhooks_requests_for_product_back_in_stock!
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
def queue_webhooks_requests_for_variant_out_of_stock!
|
|
15
|
-
variant_in_stock_before_update = variant.in_stock_or_backorderable?
|
|
16
|
-
yield
|
|
17
|
-
if variant_in_stock_before_update && !variant.in_stock_or_backorderable?
|
|
18
|
-
reload
|
|
19
|
-
stock_item.variant.queue_webhooks_requests!('variant.out_of_stock')
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def queue_webhooks_requests_for_variant_back_in_stock!
|
|
24
|
-
variant_was_out_of_stock = !variant.in_stock_or_backorderable?
|
|
25
|
-
yield
|
|
26
|
-
if variant_was_out_of_stock && variant.in_stock_or_backorderable?
|
|
27
|
-
reload
|
|
28
|
-
variant.queue_webhooks_requests!('variant.back_in_stock')
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def queue_webhooks_requests_for_product_back_in_stock!
|
|
33
|
-
product_was_out_of_stock = !product.any_variant_in_stock_or_backorderable?
|
|
34
|
-
yield
|
|
35
|
-
if product_was_out_of_stock && product.any_variant_in_stock_or_backorderable?
|
|
36
|
-
product.queue_webhooks_requests!('product.back_in_stock')
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def queue_webhooks_requests_for_product_out_of_stock!
|
|
41
|
-
product_was_in_stock = product.any_variant_in_stock_or_backorderable?
|
|
42
|
-
yield
|
|
43
|
-
if product_was_in_stock && !product.any_variant_in_stock_or_backorderable?
|
|
44
|
-
product.queue_webhooks_requests!('product.out_of_stock')
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
Spree::StockMovement.prepend(Spree::Api::Webhooks::StockMovementDecorator)
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module Spree
|
|
2
|
-
module Api
|
|
3
|
-
module Webhooks
|
|
4
|
-
module VariantDecorator
|
|
5
|
-
def self.prepended(base)
|
|
6
|
-
def base.custom_webhook_events
|
|
7
|
-
%w[variant.back_in_stock variant.backorderable variant.discontinued variant.out_of_stock]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
base.after_update_commit :queue_webhooks_requests_for_variant_discontinued!
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
def queue_webhooks_requests_for_variant_discontinued!
|
|
16
|
-
return unless discontinue_on_previously_changed?
|
|
17
|
-
return if (change = discontinue_on_previous_change).blank? || change.last.blank?
|
|
18
|
-
|
|
19
|
-
queue_webhooks_requests!('variant.discontinued')
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
Spree::Variant.prepend(Spree::Api::Webhooks::VariantDecorator)
|