summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorAlessandro Desantis <desa.alessandro@gmail.com>2020-09-30 15:26:16 +0200
committerAlessandro Desantis <desa.alessandro@gmail.com>2020-10-01 14:41:47 +0200
commit57f0d68c7ef5e7918c48cbee74173333129ecbfa (patch)
tree5dda2ffcbe5ed54afb7c4c0dca7a240cb7250b64 /app/services
parent0c15edd8310e2aae137b4b773613e61a51470436 (diff)
Remove logging from dispatchers
The way it is currently implemented, the default logging behavior from this extension could easily pollute the logs of large applications. Logging should be implemented by individual users if they need it.
Diffstat (limited to 'app/services')
-rw-r--r--app/services/solidus_subscriptions/dispatcher.rb23
-rw-r--r--app/services/solidus_subscriptions/failure_dispatcher.rb17
-rw-r--r--app/services/solidus_subscriptions/out_of_stock_dispatcher.rb13
-rw-r--r--app/services/solidus_subscriptions/payment_failed_dispatcher.rb20
-rw-r--r--app/services/solidus_subscriptions/success_dispatcher.rb14
5 files changed, 21 insertions, 66 deletions
diff --git a/app/services/solidus_subscriptions/dispatcher.rb b/app/services/solidus_subscriptions/dispatcher.rb
index b2162c0..0472f79 100644
--- a/app/services/solidus_subscriptions/dispatcher.rb
+++ b/app/services/solidus_subscriptions/dispatcher.rb
@@ -4,31 +4,20 @@ module SolidusSubscriptions
class Dispatcher
attr_reader :installments, :order
- # Get a new instance of the FailureDispatcher
+ # Returns a new instance of this dispatcher.
#
- # @param installments [Array<SolidusSubscriptions::Installment>] The
- # installments which have failed to be fulfilled
+ # @param installments [Array<SolidusSubscriptions::Installment>] The installments to process
+ # with this dispatcher
+ # @param order [Spree::Order] The order that was generated as a result of these installments
#
- # @return [SolidusSubscriptions::FailureDispatcher]
+ # @return [SolidusSubscriptions::Dispatcher]
def initialize(installments, order = nil)
@installments = installments
@order = order
end
def dispatch
- notify
- end
-
- private
-
- def notify
- Rails.logger.tagged('Event') do
- Rails.logger.info message.squish.tr("\n", ' ')
- end
- end
-
- def message
- raise 'A message should be set in subclasses of Dispatcher'
+ raise NotImplementedError
end
end
end
diff --git a/app/services/solidus_subscriptions/failure_dispatcher.rb b/app/services/solidus_subscriptions/failure_dispatcher.rb
index 4fdb828..c77d4b0 100644
--- a/app/services/solidus_subscriptions/failure_dispatcher.rb
+++ b/app/services/solidus_subscriptions/failure_dispatcher.rb
@@ -1,21 +1,14 @@
# frozen_string_literal: true
-# A handler for behaviour that should happen after installments are marked as
-# failures
+# Handles failed installments.
module SolidusSubscriptions
class FailureDispatcher < Dispatcher
def dispatch
- order.touch :completed_at
+ order.touch(:completed_at)
order.cancel
- installments.each { |i| i.failed!(order) }
- super
- end
-
- def message
- "
- Something went wrong processing installments: #{installments.map(&:id).join(', ')}.
- They have been marked for reprocessing.
- "
+ installments.each do |installment|
+ installment.failed!(order)
+ end
end
end
end
diff --git a/app/services/solidus_subscriptions/out_of_stock_dispatcher.rb b/app/services/solidus_subscriptions/out_of_stock_dispatcher.rb
index b9c181e..05484f4 100644
--- a/app/services/solidus_subscriptions/out_of_stock_dispatcher.rb
+++ b/app/services/solidus_subscriptions/out_of_stock_dispatcher.rb
@@ -1,21 +1,10 @@
# frozen_string_literal: true
-# This service class is intended to provide callback behaviour to handle
-# the case where an installment cannot be processed due to lack of stock.
+# Handles installments that cannot be processed for lack of stock.
module SolidusSubscriptions
class OutOfStockDispatcher < Dispatcher
def dispatch
installments.each(&:out_of_stock)
- super
- end
-
- private
-
- def message
- "
- The following installments cannot be fulfilled due to lack of stock:
- #{installments.map(&:id).join(', ')}.
- "
end
end
end
diff --git a/app/services/solidus_subscriptions/payment_failed_dispatcher.rb b/app/services/solidus_subscriptions/payment_failed_dispatcher.rb
index d404db0..562992b 100644
--- a/app/services/solidus_subscriptions/payment_failed_dispatcher.rb
+++ b/app/services/solidus_subscriptions/payment_failed_dispatcher.rb
@@ -1,24 +1,14 @@
# frozen_string_literal: true
-# This service class is intended to provide callback behaviour to handle
-# the case where a subscription order cannot be processed because a payment
-# failed
+# Handles payment failures for subscription installments.
module SolidusSubscriptions
class PaymentFailedDispatcher < Dispatcher
def dispatch
- order.touch :completed_at
+ order.touch(:completed_at)
order.cancel
- installments.each { |i| i.payment_failed!(order) }
- super
- end
-
- private
-
- def message
- "
- The following installments could not be processed due to payment
- authorization failure: #{installments.map(&:id).join(', ')}
- "
+ installments.each do |installment|
+ installment.payment_failed!(order)
+ end
end
end
end
diff --git a/app/services/solidus_subscriptions/success_dispatcher.rb b/app/services/solidus_subscriptions/success_dispatcher.rb
index ea4a8d3..4ac5e94 100644
--- a/app/services/solidus_subscriptions/success_dispatcher.rb
+++ b/app/services/solidus_subscriptions/success_dispatcher.rb
@@ -1,18 +1,12 @@
# frozen_string_literal: true
-# This service class is intended to provide callback behaviour to handle
-# an installment successfully being processed
+# Handles installments that are processed successfully.
module SolidusSubscriptions
class SuccessDispatcher < Dispatcher
def dispatch
- installments.each { |i| i.success!(order) }
- super
- end
-
- private
-
- def message
- "Successfully processed installments: #{installments.map(&:id).join(', ')}"
+ installments.each do |installment|
+ installment.success!(order)
+ end
end
end
end