Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processor and Checkout refactoring #172

Merged
merged 9 commits into from
Feb 5, 2021
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ RSpec/DescribeClass:
Exclude:
- spec/requests/**/*
- spec/features/**/*

Rails/SkipsModelValidations:
Enabled: false
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ This will associate a `SolidusSubscriptions::LineItem` to the line item being ad

The customer will not be charged for the subscription until it is processed. The subscription line
items should be shown to the user on the cart page by looping over
`Spree::Order#subscription_line_items`. `SolidusSubscriptions::LineItem#dummy_line_item` may be
useful to help you display the subscription line item with your existing cart infrastructure.
`Spree::Order#subscription_line_items`.

When the order is finalized, a `SolidusSubscriptions::Subscription` will be created for each group
of subscription line items which can be fulfilled by a single subscription.
Expand Down
11 changes: 11 additions & 0 deletions app/jobs/solidus_subscriptions/process_installment_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module SolidusSubscriptions
class ProcessInstallmentJob < ApplicationJob
queue_as { SolidusSubscriptions.configuration.processing_queue }

def perform(installment)
Checkout.new(installment).process
end
end
end
24 changes: 0 additions & 24 deletions app/jobs/solidus_subscriptions/process_installments_job.rb

This file was deleted.

7 changes: 0 additions & 7 deletions app/models/solidus_subscriptions/installment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ class Installment < ApplicationRecord
unfulfilled.where("#{table_name}.actionable_date <= ?", Time.zone.today)
end)

# Get the builder for the subscription_line_item. This will be an
# object that can generate the appropriate line item for the subscribable
# object
#
# @return [SolidusSubscriptions::LineItemBuilder]
delegate :line_item_builder, to: :subscription

# Mark this installment as out of stock.
#
# @return [SolidusSubscriptions::InstallmentDetail] The record of the failed
Expand Down
29 changes: 0 additions & 29 deletions app/models/solidus_subscriptions/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,5 @@ class LineItem < ApplicationRecord
validates :subscribable_id, presence: true
validates :quantity, numericality: { greater_than: 0 }
validates :interval_length, numericality: { greater_than: 0 }, unless: -> { subscription }

def as_json(**options)
options[:methods] ||= [:dummy_line_item]
super(options)
end

# Get a placeholder line item for calculating the values of future
# subscription orders. It is frozen and cannot be saved
def dummy_line_item
li = LineItemBuilder.new([self]).spree_line_items.first
return unless li

li.order = dummy_order
li.validate
li.freeze
end

private

# Get a placeholder order for calculating the values of future
# subscription orders. It is a frozen duplicate of the current order and
# cannot be saved
def dummy_order
order = spree_line_item ? spree_line_item.order.dup : ::Spree::Order.create
order.ship_address = subscription.shipping_address || subscription.user.ship_address if subscription
order.bill_address = subscription.billing_address || subscription.user.bill_address if subscription

order.freeze
end
end
end
9 changes: 0 additions & 9 deletions app/models/solidus_subscriptions/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,6 @@ def advance_actionable_date
actionable_date
end

# Get the builder for the subscription_line_item. This will be an
# object that can generate the appropriate line item for the subscribable
# object
#
# @return [SolidusSubscriptions::LineItemBuilder]
def line_item_builder
LineItemBuilder.new(line_items)
end

# The state of the last attempt to process an installment associated to
# this subscription
#
Expand Down
155 changes: 0 additions & 155 deletions app/services/solidus_subscriptions/checkout.rb

This file was deleted.

23 changes: 0 additions & 23 deletions app/services/solidus_subscriptions/dispatcher.rb

This file was deleted.

14 changes: 0 additions & 14 deletions app/services/solidus_subscriptions/failure_dispatcher.rb

This file was deleted.

36 changes: 0 additions & 36 deletions app/services/solidus_subscriptions/line_item_builder.rb

This file was deleted.

42 changes: 0 additions & 42 deletions app/services/solidus_subscriptions/order_builder.rb

This file was deleted.

Loading