solidus_core 2.11.10 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree.js.erb +0 -51
- data/app/helpers/spree/store_helper.rb +0 -11
- data/app/mailers/spree/carton_mailer.rb +1 -5
- data/app/models/concerns/spree/adjustment_source.rb +0 -15
- data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
- data/app/models/concerns/spree/soft_deletable.rb +2 -4
- data/app/models/concerns/spree/user_address_book.rb +0 -37
- data/app/models/concerns/spree/user_methods.rb +2 -11
- data/app/models/spree/ability.rb +0 -37
- data/app/models/spree/address/name.rb +2 -20
- data/app/models/spree/address.rb +8 -186
- data/app/models/spree/adjustment.rb +0 -28
- data/app/models/spree/base.rb +0 -53
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +0 -7
- data/app/models/spree/country.rb +1 -6
- data/app/models/spree/credit_card.rb +0 -27
- data/app/models/spree/customer_return.rb +1 -4
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +2 -45
- data/app/models/spree/order.rb +4 -137
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_updater.rb +2 -11
- data/app/models/spree/payment/cancellation.rb +1 -1
- data/app/models/spree/payment.rb +0 -3
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method.rb +2 -103
- data/app/models/spree/product/scopes.rb +0 -27
- data/app/models/spree/product.rb +0 -40
- data/app/models/spree/promotion/actions/create_adjustment.rb +0 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/rules/taxon.rb +2 -15
- data/app/models/spree/promotion.rb +2 -6
- data/app/models/spree/promotion_action.rb +2 -9
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/refund.rb +0 -52
- data/app/models/spree/reimbursement.rb +3 -41
- data/app/models/spree/reimbursement_performer.rb +2 -8
- data/app/models/spree/reimbursement_type/credit.rb +1 -4
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
- data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
- data/app/models/spree/return_authorization.rb +1 -4
- data/app/models/spree/return_item.rb +3 -22
- data/app/models/spree/shipment.rb +1 -54
- data/app/models/spree/shipping_method.rb +0 -25
- data/app/models/spree/shipping_rate.rb +0 -2
- data/app/models/spree/state.rb +0 -4
- data/app/models/spree/stock/simple_coordinator.rb +6 -15
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +1 -7
- data/app/models/spree/store.rb +0 -12
- data/app/models/spree/store_credit_category.rb +0 -32
- data/app/models/spree/tax_calculator/shipping_rate.rb +1 -12
- data/app/models/spree/tax_rate.rb +0 -27
- data/app/models/spree/taxon/active_storage_attachment.rb +0 -5
- data/app/models/spree/taxon/paperclip_attachment.rb +0 -5
- data/app/models/spree/taxon.rb +0 -11
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/variant.rb +2 -46
- data/config/locales/en.yml +0 -8
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
- data/lib/generators/solidus/install/install_generator.rb +12 -1
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -39
- data/lib/generators/spree/dummy/dummy_generator.rb +2 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
- data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
- data/lib/spree/app_configuration.rb +6 -65
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -14
- data/lib/spree/core/controller_helpers/order.rb +2 -22
- data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
- data/lib/spree/core/controller_helpers/pricing.rb +0 -8
- data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +0 -35
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/product_filters.rb +0 -40
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +0 -26
- data/lib/spree/core/state_machines.rb +2 -11
- data/lib/spree/core/validators/email.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +9 -8
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/event/configuration.rb +0 -5
- data/lib/spree/event/subscriber.rb +0 -18
- data/lib/spree/event/subscriber_registry.rb +3 -1
- data/lib/spree/event.rb +0 -31
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permitted_attributes.rb +9 -54
- data/lib/spree/testing_support/capybara_ext.rb +0 -30
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
- data/lib/spree/testing_support/dummy_app.rb +7 -14
- data/lib/spree/testing_support/factories/order_factory.rb +0 -1
- data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
- data/lib/spree/testing_support/order_walkthrough.rb +0 -3
- data/lib/spree/testing_support/preferences.rb +0 -25
- data/lib/tasks/upgrade.rake +7 -5
- data/solidus_core.gemspec +2 -5
- metadata +8 -49
- data/app/mailers/spree/test_mailer.rb +0 -13
- data/app/models/concerns/spree/user_payment_source.rb +0 -26
- data/app/models/spree/calculator/free_shipping.rb +0 -22
- data/app/models/spree/calculator/percent_per_item.rb +0 -51
- data/app/models/spree/calculator/price_sack.rb +0 -28
- data/app/models/spree/gateway/bogus.rb +0 -13
- data/app/models/spree/gateway/bogus_simple.rb +0 -13
- data/app/models/spree/gateway.rb +0 -14
- data/app/models/spree/order/checkout.rb +0 -244
- data/app/models/spree/order_capturing.rb +0 -50
- data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
- data/lib/generators/spree/install/install_generator.rb +0 -15
- data/lib/solidus/migrations/rename_gateways.rb +0 -41
- data/lib/spree/core/current_store.rb +0 -24
- data/lib/spree/paranoia_deprecations.rb +0 -41
- data/lib/spree/promo/environment.rb +0 -12
- data/lib/spree/testing_support/bar_ability.rb +0 -19
- data/lib/tasks/core.rake +0 -104
- data/lib/tasks/email.rake +0 -12
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
- data/lib/tasks/migrations/migrate_address_names.rake +0 -158
- data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
- data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
- data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
- data/lib/tasks/migrations/rename_gateways.rake +0 -23
- data/lib/tasks/order_capturing.rake +0 -27
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
class TestMailer < BaseMailer
|
5
|
-
def test_email(email)
|
6
|
-
Spree::Deprecation.warn("Spree::TestMailer has been deprecated and will be removed with Solidus 3.0")
|
7
|
-
|
8
|
-
store = Spree::Store.default
|
9
|
-
subject = "#{store.name} #{t('.subject')}"
|
10
|
-
mail(to: email, from: from_address(store), subject: subject)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
module UserPaymentSource
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
def default_credit_card
|
8
|
-
Spree::Deprecation.warn(
|
9
|
-
"user.default_credit_card is deprecated. Please use user.wallet.default_wallet_payment_source instead.",
|
10
|
-
caller
|
11
|
-
)
|
12
|
-
default = wallet.default_wallet_payment_source
|
13
|
-
if default && default.payment_source.is_a?(Spree::CreditCard)
|
14
|
-
default.payment_source
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def payment_sources
|
19
|
-
Spree::Deprecation.warn(
|
20
|
-
"user.payment_sources is deprecated. Please use user.wallet.wallet_payment_sources instead.",
|
21
|
-
caller
|
22
|
-
)
|
23
|
-
credit_cards.with_payment_profile
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_dependency 'spree/calculator'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
# @deprecated This calculator will be removed in future versions of Spree.
|
7
|
-
# The only case where it was used was for Free Shipping Promotions. There is
|
8
|
-
# now a Promotion Action which deals with these types of promotions instead.
|
9
|
-
class Calculator::FreeShipping < Calculator
|
10
|
-
def compute(object)
|
11
|
-
Spree::Deprecation.warn('This method is deprecated, because it is no longer used')
|
12
|
-
if object.is_a?(Array)
|
13
|
-
return if object.empty?
|
14
|
-
order = object.first.order
|
15
|
-
else
|
16
|
-
order = object
|
17
|
-
end
|
18
|
-
|
19
|
-
order.ship_total
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_dependency 'spree/calculator'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
# A calculator for promotions that calculates a percent-off discount
|
7
|
-
# for all matching products in an order. This should not be used as a
|
8
|
-
# shipping calculator since it would be the same thing as a flat percent
|
9
|
-
# off the entire order.
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# TODO Should be deprecated now that we have adjustments at the line item level in spree core
|
13
|
-
|
14
|
-
class Calculator::PercentPerItem < Calculator
|
15
|
-
preference :percent, :decimal, default: 0
|
16
|
-
|
17
|
-
def compute(object = nil)
|
18
|
-
Spree::Deprecation.warn('This method is deprecated, please use adjustments at line item level')
|
19
|
-
|
20
|
-
return 0 if object.nil?
|
21
|
-
object.line_items.sum { |line_item|
|
22
|
-
value_for_line_item(line_item)
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
# Returns all products that match this calculator, but only if the calculator
|
29
|
-
# is attached to a promotion. If attached to a ShippingMethod, nil is returned.
|
30
|
-
# Copied from per_item.rb
|
31
|
-
def matching_products
|
32
|
-
if compute_on_promotion?
|
33
|
-
calculable.promotion.rules.flat_map do |rule|
|
34
|
-
rule.respond_to?(:products) ? rule.products : []
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def value_for_line_item(line_item)
|
40
|
-
if compute_on_promotion?
|
41
|
-
return 0 unless matching_products.blank? || matching_products.include?(line_item.product)
|
42
|
-
end
|
43
|
-
((line_item.price * line_item.quantity) * preferred_percent) / 100
|
44
|
-
end
|
45
|
-
|
46
|
-
# Determines wether or not the calculable object is a promotion
|
47
|
-
def compute_on_promotion?
|
48
|
-
@compute_on_promotion ||= calculable.respond_to?(:promotion)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_dependency 'spree/calculator'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
class Calculator::PriceSack < Calculator
|
7
|
-
preference :minimal_amount, :decimal, default: 0
|
8
|
-
preference :normal_amount, :decimal, default: 0
|
9
|
-
preference :discount_amount, :decimal, default: 0
|
10
|
-
preference :currency, :string, default: ->{ Spree::Config[:currency] }
|
11
|
-
|
12
|
-
# as object we always get line items, as calculable we have Coupon, ShippingMethod
|
13
|
-
def compute(object)
|
14
|
-
Spree::Deprecation.warn('This method is deprecated, please use adjustments at line item level')
|
15
|
-
if object.is_a?(Array)
|
16
|
-
base = object.sum { |element| element.respond_to?(:amount) ? element.amount : BigDecimal(element.to_s) }
|
17
|
-
else
|
18
|
-
base = object.respond_to?(:amount) ? object.amount : BigDecimal(object.to_s)
|
19
|
-
end
|
20
|
-
|
21
|
-
if base < preferred_minimal_amount
|
22
|
-
preferred_normal_amount
|
23
|
-
else
|
24
|
-
preferred_discount_amount
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
# @deprecated Use Spree::PaymentMethod::BogusCreditCard instead
|
5
|
-
class Gateway::Bogus < PaymentMethod::BogusCreditCard
|
6
|
-
def initialize(*args)
|
7
|
-
Spree::Deprecation.warn \
|
8
|
-
'Spree::Gateway::Bogus is deprecated. ' \
|
9
|
-
'Please use Spree::PaymentMethod::BogusCreditCard instead'
|
10
|
-
super
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
# @deprecated Use Spree::PaymentMethod::SimpleBogusCreditCard instead
|
5
|
-
class Gateway::BogusSimple < Spree::PaymentMethod::SimpleBogusCreditCard
|
6
|
-
def initialize(*args)
|
7
|
-
Spree::Deprecation.warn \
|
8
|
-
'Spree::Gateway::BogusSimple is deprecated. ' \
|
9
|
-
'Please use Spree::PaymentMethod::SimpleBogusCreditCard instead'
|
10
|
-
super
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/app/models/spree/gateway.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
# @deprecated Use Spree::PaymentMethod::CreditCard or Spree::PaymentMethod instead
|
5
|
-
class Gateway < PaymentMethod::CreditCard
|
6
|
-
def initialize(*args)
|
7
|
-
Spree::Deprecation.warn \
|
8
|
-
"Using Spree::Gateway as parent class of payment methods is deprecated. " \
|
9
|
-
"Please use Spree::PaymentMethod::CreditCard for credit card based payment methods " \
|
10
|
-
"or Spree::PaymentMethod for non credit card payment methods instead."
|
11
|
-
super
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,244 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
class Order < Spree::Base
|
5
|
-
module Checkout
|
6
|
-
def self.included(klass)
|
7
|
-
klass.extend ClassMethods
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
attr_accessor :previous_states
|
12
|
-
attr_writer :next_event_transitions
|
13
|
-
attr_writer :checkout_steps
|
14
|
-
attr_writer :removed_transitions
|
15
|
-
|
16
|
-
def checkout_flow(&block)
|
17
|
-
if block_given?
|
18
|
-
@checkout_flow = block
|
19
|
-
define_state_machine!
|
20
|
-
else
|
21
|
-
@checkout_flow
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def define_state_machine!
|
26
|
-
self.checkout_steps = {}
|
27
|
-
self.next_event_transitions = []
|
28
|
-
self.previous_states = [:cart]
|
29
|
-
self.removed_transitions = []
|
30
|
-
|
31
|
-
# Build the checkout flow using the checkout_flow defined either
|
32
|
-
# within the Order class, or a decorator for that class.
|
33
|
-
#
|
34
|
-
# This method may be called multiple times depending on if the
|
35
|
-
# checkout_flow is re-defined in a decorator or not.
|
36
|
-
instance_eval(&checkout_flow)
|
37
|
-
|
38
|
-
klass = self
|
39
|
-
|
40
|
-
# To avoid multiple occurrences of the same transition being defined
|
41
|
-
# On first definition, state_machines will not be defined
|
42
|
-
state_machines.clear if respond_to?(:state_machines)
|
43
|
-
state_machine :state, initial: :cart, use_transactions: false do
|
44
|
-
klass.next_event_transitions.each { |state| transition(state.merge(on: :next)) }
|
45
|
-
|
46
|
-
# Persist the state on the order
|
47
|
-
after_transition do |order, transition|
|
48
|
-
order.state = order.state
|
49
|
-
order.state_changes.create(
|
50
|
-
previous_state: transition.from,
|
51
|
-
next_state: transition.to,
|
52
|
-
name: 'order',
|
53
|
-
user_id: order.user_id
|
54
|
-
)
|
55
|
-
order.save
|
56
|
-
end
|
57
|
-
|
58
|
-
event :cancel do
|
59
|
-
transition to: :canceled, if: :allow_cancel?
|
60
|
-
end
|
61
|
-
|
62
|
-
event :return do
|
63
|
-
transition to: :returned, from: [:returned, :complete, :awaiting_return, :canceled], if: :all_inventory_units_returned?
|
64
|
-
end
|
65
|
-
|
66
|
-
event :resume do
|
67
|
-
transition to: :resumed, from: :canceled, if: :canceled?
|
68
|
-
end
|
69
|
-
|
70
|
-
event :authorize_return do
|
71
|
-
transition to: :awaiting_return
|
72
|
-
end
|
73
|
-
|
74
|
-
event :complete do
|
75
|
-
transition to: :complete, from: :confirm
|
76
|
-
end
|
77
|
-
|
78
|
-
if states[:payment]
|
79
|
-
event :payment_failed do
|
80
|
-
transition to: :payment, from: :confirm
|
81
|
-
end
|
82
|
-
|
83
|
-
after_transition to: :complete, do: :add_payment_sources_to_wallet
|
84
|
-
before_transition to: :payment, do: :add_default_payment_from_wallet
|
85
|
-
before_transition to: :payment, do: :ensure_billing_address
|
86
|
-
|
87
|
-
before_transition to: :confirm, do: :add_store_credit_payments
|
88
|
-
|
89
|
-
# see also process_payments_before_complete below which needs to
|
90
|
-
# be added in the correct sequence.
|
91
|
-
end
|
92
|
-
|
93
|
-
before_transition from: :cart, do: :ensure_line_items_present
|
94
|
-
|
95
|
-
if states[:address]
|
96
|
-
before_transition to: :address, do: :assign_default_user_addresses
|
97
|
-
before_transition from: :address, do: :persist_user_address!
|
98
|
-
end
|
99
|
-
|
100
|
-
if states[:delivery]
|
101
|
-
before_transition to: :delivery, do: :ensure_shipping_address
|
102
|
-
before_transition to: :delivery, do: :create_proposed_shipments
|
103
|
-
before_transition to: :delivery, do: :ensure_available_shipping_rates
|
104
|
-
before_transition from: :delivery, do: :apply_shipping_promotions
|
105
|
-
end
|
106
|
-
|
107
|
-
before_transition to: :resumed, do: :ensure_line_item_variants_are_not_deleted
|
108
|
-
before_transition to: :resumed, do: :validate_line_item_availability
|
109
|
-
|
110
|
-
# Sequence of before_transition to: :complete
|
111
|
-
# calls matter so that we do not process payments
|
112
|
-
# until validations have passed
|
113
|
-
before_transition to: :complete, do: :validate_line_item_availability
|
114
|
-
before_transition to: :complete, do: :ensure_promotions_eligible
|
115
|
-
before_transition to: :complete, do: :ensure_line_item_variants_are_not_deleted
|
116
|
-
before_transition to: :complete, do: :ensure_inventory_units
|
117
|
-
if states[:payment]
|
118
|
-
before_transition to: :complete, do: :process_payments_before_complete
|
119
|
-
end
|
120
|
-
|
121
|
-
after_transition to: :complete, do: :finalize!
|
122
|
-
after_transition to: :resumed, do: :after_resume
|
123
|
-
after_transition to: :canceled, do: :after_cancel
|
124
|
-
|
125
|
-
after_transition from: any - :cart, to: any - [:confirm, :complete] do |order|
|
126
|
-
order.recalculate
|
127
|
-
end
|
128
|
-
|
129
|
-
after_transition do |order, transition|
|
130
|
-
order.logger.debug "Order #{order.number} transitioned from #{transition.from} to #{transition.to} via #{transition.event}"
|
131
|
-
end
|
132
|
-
|
133
|
-
after_failure do |order, transition|
|
134
|
-
order.logger.debug "Order #{order.number} halted transition on event #{transition.event} state #{transition.from}: #{order.errors.full_messages.join}"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def go_to_state(name, options = {})
|
140
|
-
checkout_steps[name] = options
|
141
|
-
previous_states.each do |state|
|
142
|
-
add_transition({ from: state, to: name }.merge(options))
|
143
|
-
end
|
144
|
-
if options[:if]
|
145
|
-
previous_states << name
|
146
|
-
else
|
147
|
-
self.previous_states = [name]
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def insert_checkout_step(name, options = {})
|
152
|
-
before = options.delete(:before)
|
153
|
-
after = options.delete(:after) unless before
|
154
|
-
after = checkout_steps.keys.last unless before || after
|
155
|
-
|
156
|
-
cloned_steps = checkout_steps.clone
|
157
|
-
cloned_removed_transitions = removed_transitions.clone
|
158
|
-
checkout_flow do
|
159
|
-
cloned_steps.each_pair do |key, value|
|
160
|
-
go_to_state(name, options) if key == before
|
161
|
-
go_to_state(key, value)
|
162
|
-
go_to_state(name, options) if key == after
|
163
|
-
end
|
164
|
-
cloned_removed_transitions.each do |transition|
|
165
|
-
remove_transition(transition)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def remove_checkout_step(name)
|
171
|
-
cloned_steps = checkout_steps.clone
|
172
|
-
cloned_removed_transitions = removed_transitions.clone
|
173
|
-
checkout_flow do
|
174
|
-
cloned_steps.each_pair do |key, value|
|
175
|
-
go_to_state(key, value) unless key == name
|
176
|
-
end
|
177
|
-
cloned_removed_transitions.each do |transition|
|
178
|
-
remove_transition(transition)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def remove_transition(options = {})
|
184
|
-
removed_transitions << options
|
185
|
-
next_event_transitions.delete(find_transition(options))
|
186
|
-
end
|
187
|
-
|
188
|
-
def find_transition(options = {})
|
189
|
-
return nil if options.nil? || !options.include?(:from) || !options.include?(:to)
|
190
|
-
next_event_transitions.detect do |transition|
|
191
|
-
transition[options[:from].to_sym] == options[:to].to_sym
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
def next_event_transitions
|
196
|
-
@next_event_transitions ||= []
|
197
|
-
end
|
198
|
-
|
199
|
-
def checkout_steps
|
200
|
-
@checkout_steps ||= {}
|
201
|
-
end
|
202
|
-
|
203
|
-
def checkout_step_names
|
204
|
-
checkout_steps.keys
|
205
|
-
end
|
206
|
-
|
207
|
-
def add_transition(options)
|
208
|
-
next_event_transitions << { options.delete(:from) => options.delete(:to) }.merge(options)
|
209
|
-
end
|
210
|
-
|
211
|
-
def removed_transitions
|
212
|
-
@removed_transitions ||= []
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
def checkout_steps
|
217
|
-
steps = self.class.checkout_steps.each_with_object([]) { |(step, options), checkout_steps|
|
218
|
-
next if options.include?(:if) && !options[:if].call(self)
|
219
|
-
checkout_steps << step
|
220
|
-
}.map(&:to_s)
|
221
|
-
# Ensure there is always a complete step
|
222
|
-
steps << "complete" unless steps.include?("complete")
|
223
|
-
steps
|
224
|
-
end
|
225
|
-
|
226
|
-
def has_checkout_step?(step)
|
227
|
-
step.present? && checkout_steps.include?(step)
|
228
|
-
end
|
229
|
-
|
230
|
-
def passed_checkout_step?(step)
|
231
|
-
has_checkout_step?(step) && checkout_step_index(step) < checkout_step_index(state)
|
232
|
-
end
|
233
|
-
|
234
|
-
def checkout_step_index(step)
|
235
|
-
checkout_steps.index(step).to_i
|
236
|
-
end
|
237
|
-
|
238
|
-
def can_go_to_state?(state)
|
239
|
-
return false unless has_checkout_step?(self.state) && has_checkout_step?(state)
|
240
|
-
checkout_step_index(state) > checkout_step_index(self.state)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Spree::OrderCapturing
|
4
|
-
# Allows for prioritizing payment methods in the order to be captured
|
5
|
-
class_attribute :sorted_payment_method_classes
|
6
|
-
self.sorted_payment_method_classes = []
|
7
|
-
|
8
|
-
# Allows your store to void unused payments and release auths
|
9
|
-
class_attribute :void_unused_payments
|
10
|
-
self.void_unused_payments = false
|
11
|
-
|
12
|
-
class_attribute :failure_handler
|
13
|
-
self.failure_handler = ->(failures) { raise Spree::OrderCapturingFailures.new(failures.to_json) }
|
14
|
-
|
15
|
-
def initialize(order, sorted_payment_method_classes = nil)
|
16
|
-
Spree::Deprecation.warn "Spree::OrderCapturing is deprecated and will be removed without replacement. " \
|
17
|
-
"Please implement your own automated capturing logic in your store."
|
18
|
-
@order = order
|
19
|
-
@sorted_payment_method_classes = sorted_payment_method_classes || Spree::OrderCapturing.sorted_payment_method_classes
|
20
|
-
end
|
21
|
-
|
22
|
-
def capture_payments
|
23
|
-
return if @order.paid?
|
24
|
-
|
25
|
-
Spree::OrderMutex.with_lock!(@order) do
|
26
|
-
uncaptured_amount = @order.display_total.cents
|
27
|
-
|
28
|
-
sorted_payments(@order).each do |payment|
|
29
|
-
amount = [uncaptured_amount, payment.money.cents].min
|
30
|
-
|
31
|
-
if amount > 0
|
32
|
-
payment.capture!(amount)
|
33
|
-
uncaptured_amount -= amount
|
34
|
-
elsif Spree::OrderCapturing.void_unused_payments
|
35
|
-
payment.void_transaction!
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def sorted_payments(order)
|
44
|
-
order.payments.pending.sort_by do |payment|
|
45
|
-
[@sorted_payment_method_classes.index(payment.payment_method.class), payment.id]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class Spree::OrderCapturingFailures < StandardError; end
|