summaryrefslogtreecommitdiff
path: root/lib/solidus_subscriptions
diff options
context:
space:
mode:
authorAlessandro Desantis <desa.alessandro@gmail.com>2021-05-06 17:48:50 +0200
committerGitHub <noreply@github.com>2021-05-06 17:48:50 +0200
commit5e222ede6c90b9b6b5964d505cec76bd4f7af46b (patch)
treecd98c00af7f342d405925abaf944a437d6e78909 /lib/solidus_subscriptions
parentdafa723b228ec80dfb66a112d495114d29b43e9d (diff)
parentd6e36547107c741c7e0867531e1da22295980247 (diff)
Merge pull request #229 from solidusio-contrib/add-order-creation-serviceish-object
Introduce Installment OrderCreator configuration
Diffstat (limited to 'lib/solidus_subscriptions')
-rw-r--r--lib/solidus_subscriptions/checkout.rb11
-rw-r--r--lib/solidus_subscriptions/configuration.rb13
-rw-r--r--lib/solidus_subscriptions/order_creator.rb29
3 files changed, 40 insertions, 13 deletions
diff --git a/lib/solidus_subscriptions/checkout.rb b/lib/solidus_subscriptions/checkout.rb
index b71a7b2..7bed823 100644
--- a/lib/solidus_subscriptions/checkout.rb
+++ b/lib/solidus_subscriptions/checkout.rb
@@ -32,14 +32,7 @@ module SolidusSubscriptions
private
def create_order
- ::Spree::Order.create(
- user: installment.subscription.user,
- email: installment.subscription.user.email,
- store: installment.subscription.store || ::Spree::Store.default,
- subscription_order: true,
- subscription: installment.subscription,
- currency: installment.subscription.currency
- )
+ SolidusSubscriptions.configuration.order_creator_class.new(installment).call
end
def populate_order(order)
@@ -61,7 +54,7 @@ module SolidusSubscriptions
order.payments.create(
payment_method: installment.subscription.payment_method_to_use,
source: installment.subscription.payment_source_to_use,
- amount: order.total,
+ amount: order.total
)
end
diff --git a/lib/solidus_subscriptions/configuration.rb b/lib/solidus_subscriptions/configuration.rb
index 2606272..9d6c3d2 100644
--- a/lib/solidus_subscriptions/configuration.rb
+++ b/lib/solidus_subscriptions/configuration.rb
@@ -4,14 +4,14 @@ module SolidusSubscriptions
class Configuration
attr_accessor(
:maximum_total_skips, :maximum_reprocessing_time, :churn_buster_account_id,
- :churn_buster_api_key, :clear_past_installments, :processing_error_handler,
+ :churn_buster_api_key, :clear_past_installments, :processing_error_handler
)
attr_writer(
:success_dispatcher_class, :failure_dispatcher_class, :payment_failed_dispatcher_class,
:out_of_stock_dispatcher, :maximum_successive_skips, :reprocessing_interval,
:minimum_cancellation_notice, :processing_queue, :subscription_line_item_attributes,
- :subscription_attributes, :subscribable_class,
+ :subscription_attributes, :subscribable_class, :order_creator_class
)
def success_dispatcher_class
@@ -57,7 +57,7 @@ module SolidusSubscriptions
:subscribable_id,
:interval_length,
:interval_units,
- :end_date,
+ :end_date
]
end
@@ -69,7 +69,7 @@ module SolidusSubscriptions
{
shipping_address_attributes: Spree::PermittedAttributes.address_attributes,
billing_address_attributes: Spree::PermittedAttributes.address_attributes
- },
+ }
]
end
@@ -81,5 +81,10 @@ module SolidusSubscriptions
def churn_buster?
churn_buster_account_id.present? && churn_buster_api_key.present?
end
+
+ def order_creator_class
+ @order_creator_class ||= 'SolidusSubscriptions::OrderCreator'
+ @order_creator_class.constantize
+ end
end
end
diff --git a/lib/solidus_subscriptions/order_creator.rb b/lib/solidus_subscriptions/order_creator.rb
new file mode 100644
index 0000000..a2db8ce
--- /dev/null
+++ b/lib/solidus_subscriptions/order_creator.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module SolidusSubscriptions
+ class OrderCreator
+ def initialize(installment)
+ @installment = installment
+ end
+
+ def call
+ ::Spree::Order.create(
+ user: installment.subscription.user,
+ email: installment.subscription.user.email,
+ store: installment.subscription.store || ::Spree::Store.default,
+ subscription_order: true,
+ subscription: installment.subscription,
+ currency: installment.subscription.currency,
+ **extra_attributes
+ )
+ end
+
+ private
+
+ def extra_attributes
+ {}
+ end
+
+ attr_reader :installment
+ end
+end