-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize hierarchy of dispatcher classes
- Loading branch information
1 parent
464fa3a
commit 16865d4
Showing
16 changed files
with
101 additions
and
91 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
16 changes: 16 additions & 0 deletions
16
app/services/solidus_subscriptions/dispatcher/failure_dispatcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/services/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
20 changes: 20 additions & 0 deletions
20
app/services/solidus_subscriptions/dispatcher/success_dispatcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
app/services/solidus_subscriptions/payment_failed_dispatcher.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../solidus_subscriptions/dispatcher_spec.rb → ...bscriptions/dispatcher/dispatcher_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
..._subscriptions/failure_dispatcher_spec.rb → ...ons/dispatcher/failure_dispatcher_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...criptions/out_of_stock_dispatcher_spec.rb → ...ispatcher/out_of_stock_dispatcher_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...iptions/payment_failed_dispatcher_spec.rb → ...patcher/payment_failed_dispatcher_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
..._subscriptions/success_dispatcher_spec.rb → ...ons/dispatcher/success_dispatcher_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters