summaryrefslogtreecommitdiff
path: root/app/services/solidus_subscriptions
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/solidus_subscriptions')
-rw-r--r--app/services/solidus_subscriptions/dispatcher.rb23
-rw-r--r--app/services/solidus_subscriptions/dispatcher/base.rb25
-rw-r--r--app/services/solidus_subscriptions/dispatcher/failure_dispatcher.rb16
-rw-r--r--app/services/solidus_subscriptions/dispatcher/out_of_stock_dispatcher.rb (renamed from app/services/solidus_subscriptions/out_of_stock_dispatcher.rb)8
-rw-r--r--app/services/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb22
-rw-r--r--app/services/solidus_subscriptions/dispatcher/success_dispatcher.rb20
-rw-r--r--app/services/solidus_subscriptions/failure_dispatcher.rb14
-rw-r--r--app/services/solidus_subscriptions/payment_failed_dispatcher.rb20
-rw-r--r--app/services/solidus_subscriptions/success_dispatcher.rb18
9 files changed, 88 insertions, 78 deletions
diff --git a/app/services/solidus_subscriptions/dispatcher.rb b/app/services/solidus_subscriptions/dispatcher.rb
deleted file mode 100644
index 0472f79..0000000
--- a/app/services/solidus_subscriptions/dispatcher.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-module SolidusSubscriptions
- class Dispatcher
- attr_reader :installments, :order
-
- # Returns a new instance of this dispatcher.
- #
- # @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::Dispatcher]
- def initialize(installments, order = nil)
- @installments = installments
- @order = order
- end
-
- def dispatch
- raise NotImplementedError
- end
- end
-end
diff --git a/app/services/solidus_subscriptions/dispatcher/base.rb b/app/services/solidus_subscriptions/dispatcher/base.rb
new file mode 100644
index 0000000..84b8710
--- /dev/null
+++ b/app/services/solidus_subscriptions/dispatcher/base.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module SolidusSubscriptions
+ module Dispatcher
+ class Base
+ attr_reader :installments, :order
+
+ # Returns a new instance of this dispatcher.
+ #
+ # @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::Dispatcher]
+ def initialize(installments, order = nil)
+ @installments = installments
+ @order = order
+ end
+
+ def dispatch
+ raise NotImplementedError
+ end
+ end
+ end
+end
diff --git a/app/services/solidus_subscriptions/dispatcher/failure_dispatcher.rb b/app/services/solidus_subscriptions/dispatcher/failure_dispatcher.rb
new file mode 100644
index 0000000..286a4c9
--- /dev/null
+++ b/app/services/solidus_subscriptions/dispatcher/failure_dispatcher.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+# Handles failed installments.
+module SolidusSubscriptions
+ module Dispatcher
+ class FailureDispatcher < Base
+ def dispatch
+ order.touch(:completed_at)
+ order.cancel
+ installments.each do |installment|
+ installment.failed!(order)
+ end
+ end
+ end
+ end
+end
diff --git a/app/services/solidus_subscriptions/out_of_stock_dispatcher.rb b/app/services/solidus_subscriptions/dispatcher/out_of_stock_dispatcher.rb
index 05484f4..ef79f84 100644
--- a/app/services/solidus_subscriptions/out_of_stock_dispatcher.rb
+++ b/app/services/solidus_subscriptions/dispatcher/out_of_stock_dispatcher.rb
@@ -2,9 +2,11 @@
# Handles installments that cannot be processed for lack of stock.
module SolidusSubscriptions
- class OutOfStockDispatcher < Dispatcher
- def dispatch
- installments.each(&:out_of_stock)
+ module Dispatcher
+ class OutOfStockDispatcher < Base
+ def dispatch
+ installments.each(&:out_of_stock)
+ end
end
end
end
diff --git a/app/services/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb b/app/services/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb
new file mode 100644
index 0000000..74bee88
--- /dev/null
+++ b/app/services/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+# Handles payment failures for subscription installments.
+module SolidusSubscriptions
+ module Dispatcher
+ class PaymentFailedDispatcher < Base
+ def dispatch
+ order.touch(:completed_at)
+ order.cancel
+ installments.each do |installment|
+ installment.payment_failed!(order)
+ end
+
+ ::Spree::Event.fire(
+ 'solidus_subscriptions.installments_failed_payment',
+ installments: installments,
+ order: order,
+ )
+ end
+ end
+ end
+end
diff --git a/app/services/solidus_subscriptions/dispatcher/success_dispatcher.rb b/app/services/solidus_subscriptions/dispatcher/success_dispatcher.rb
new file mode 100644
index 0000000..78563a4
--- /dev/null
+++ b/app/services/solidus_subscriptions/dispatcher/success_dispatcher.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+# Handles installments that are processed successfully.
+module SolidusSubscriptions
+ module Dispatcher
+ class SuccessDispatcher < Base
+ def dispatch
+ installments.each do |installment|
+ installment.success!(order)
+ end
+
+ ::Spree::Event.fire(
+ 'solidus_subscriptions.installments_succeeded',
+ installments: installments,
+ order: order,
+ )
+ end
+ end
+ end
+end
diff --git a/app/services/solidus_subscriptions/failure_dispatcher.rb b/app/services/solidus_subscriptions/failure_dispatcher.rb
deleted file mode 100644
index c77d4b0..0000000
--- a/app/services/solidus_subscriptions/failure_dispatcher.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-# Handles failed installments.
-module SolidusSubscriptions
- class FailureDispatcher < Dispatcher
- def dispatch
- order.touch(:completed_at)
- order.cancel
- installments.each do |installment|
- installment.failed!(order)
- end
- end
- end
-end
diff --git a/app/services/solidus_subscriptions/payment_failed_dispatcher.rb b/app/services/solidus_subscriptions/payment_failed_dispatcher.rb
deleted file mode 100644
index 29eb291..0000000
--- a/app/services/solidus_subscriptions/payment_failed_dispatcher.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-# Handles payment failures for subscription installments.
-module SolidusSubscriptions
- class PaymentFailedDispatcher < Dispatcher
- def dispatch
- order.touch(:completed_at)
- order.cancel
- installments.each do |installment|
- installment.payment_failed!(order)
- end
-
- ::Spree::Event.fire(
- 'solidus_subscriptions.installments_failed_payment',
- installments: installments,
- order: order,
- )
- end
- end
-end
diff --git a/app/services/solidus_subscriptions/success_dispatcher.rb b/app/services/solidus_subscriptions/success_dispatcher.rb
deleted file mode 100644
index ce55266..0000000
--- a/app/services/solidus_subscriptions/success_dispatcher.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-# Handles installments that are processed successfully.
-module SolidusSubscriptions
- class SuccessDispatcher < Dispatcher
- def dispatch
- installments.each do |installment|
- installment.success!(order)
- end
-
- ::Spree::Event.fire(
- 'solidus_subscriptions.installments_succeeded',
- installments: installments,
- order: order,
- )
- end
- end
-end