solidus_core 3.2.5 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -2
  3. data/app/controllers/spree/base_controller.rb +1 -1
  4. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +4 -0
  5. data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
  6. data/app/models/concerns/spree/user_methods.rb +2 -2
  7. data/app/models/spree/address.rb +1 -1
  8. data/app/models/spree/calculator/flat_fee.rb +21 -0
  9. data/app/models/spree/country.rb +1 -1
  10. data/app/models/spree/credit_card.rb +1 -1
  11. data/app/models/spree/customer_return.rb +1 -1
  12. data/app/models/spree/line_item.rb +2 -2
  13. data/app/models/spree/option_type.rb +1 -1
  14. data/app/models/spree/option_value.rb +1 -1
  15. data/app/models/spree/order/number_generator.rb +7 -1
  16. data/app/models/spree/order.rb +4 -3
  17. data/app/models/spree/order_promotion.rb +1 -1
  18. data/app/models/spree/order_updater.rb +11 -2
  19. data/app/models/spree/payment/processing.rb +58 -55
  20. data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
  21. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
  22. data/app/models/spree/payment_method.rb +16 -10
  23. data/app/models/spree/price.rb +1 -1
  24. data/app/models/spree/product.rb +3 -3
  25. data/app/models/spree/product_property.rb +1 -1
  26. data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
  27. data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
  28. data/app/models/spree/promotion.rb +2 -2
  29. data/app/models/spree/promotion_code.rb +1 -1
  30. data/app/models/spree/property.rb +1 -1
  31. data/app/models/spree/return_authorization.rb +1 -1
  32. data/app/models/spree/shipment.rb +2 -2
  33. data/app/models/spree/state.rb +1 -1
  34. data/app/models/spree/stock_item.rb +1 -1
  35. data/app/models/spree/stock_location.rb +1 -1
  36. data/app/models/spree/stock_movement.rb +2 -2
  37. data/app/models/spree/store_credit_prioritizer.rb +17 -0
  38. data/app/models/spree/tax/tax_helpers.rb +2 -2
  39. data/app/models/spree/tax_calculator/default.rb +31 -0
  40. data/app/models/spree/tax_rate.rb +9 -3
  41. data/app/models/spree/taxon.rb +1 -1
  42. data/app/models/spree/taxonomy.rb +1 -1
  43. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
  44. data/app/models/spree/variant.rb +25 -5
  45. data/app/models/spree/zone.rb +1 -1
  46. data/config/locales/en.yml +17 -2
  47. data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
  48. data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
  49. data/db/seeds.rb +4 -1
  50. data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
  51. data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
  52. data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
  53. data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
  54. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
  55. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
  56. data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
  57. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
  58. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +11 -9
  59. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +8 -9
  60. data/lib/generators/solidus/install/install_generator.rb +213 -190
  61. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -4
  62. data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
  63. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
  64. data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
  65. data/lib/generators/spree/dummy/dummy_generator.rb +10 -8
  66. data/lib/generators/spree/dummy/templates/rails/database.yml +6 -12
  67. data/lib/spree/app_configuration.rb +23 -0
  68. data/lib/spree/core/controller_helpers/current_host.rb +5 -1
  69. data/lib/spree/core/engine.rb +1 -0
  70. data/lib/spree/core/search/base.rb +17 -8
  71. data/lib/spree/core/version.rb +2 -2
  72. data/lib/spree/core.rb +1 -20
  73. data/lib/spree/migrations.rb +12 -10
  74. data/lib/spree/permitted_attributes.rb +4 -1
  75. data/lib/spree/preferences/static_model_preferences.rb +25 -8
  76. data/lib/spree/rails_compatibility.rb +0 -17
  77. data/lib/spree/testing_support/common_rake.rb +7 -6
  78. data/lib/spree/testing_support/dummy_app.rb +2 -2
  79. data/lib/spree/testing_support/factories/address_factory.rb +9 -11
  80. data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
  81. data/lib/spree/testing_support/factories/country_factory.rb +1 -2
  82. data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
  83. data/lib/spree/testing_support/factories/state_factory.rb +8 -2
  84. data/lib/spree/testing_support/factory_bot.rb +1 -1
  85. data/lib/spree/testing_support/order_walkthrough.rb +1 -1
  86. data/lib/tasks/colorado_delivery_fee.rake +28 -0
  87. data/solidus_core.gemspec +2 -2
  88. metadata +33 -22
  89. data/lib/generators/solidus/install/install_generator/bundler_context.rb +0 -105
  90. data/lib/generators/solidus/install/install_generator/install_frontend.rb +0 -61
  91. data/lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb +0 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ca291cd7b979dea71a53e089ec1f5582fd29606135be6802668e6a249655295
4
- data.tar.gz: 35c97c39d287f13bd2330fef96e59eefa5d82869e49563a32706b827087a936a
3
+ metadata.gz: 6b882356a483b6ec07df20020cfdf2429122ed885165c9626384017479b26442
4
+ data.tar.gz: a840c6d60aab4097f5159588a9b648ac5baac0fba6704ea21e1928eb7dc1dd88
5
5
  SHA512:
6
- metadata.gz: dcd03d7fe00dade48a32ff5862579eed61115afe17e225e0378ea83fb1af3c502467dbef833619159742b2b7cef998e53d47cde357d6e2b57beb73daa80708f2
7
- data.tar.gz: cea864acea70b4d18b208481ffa8d0587ce5bc721f2de5d83c653b2125e7dbf1e9da81ef0cb211180d48df93a53daaf813e5d8d7ecd9181c5c0f9de2efd239ba
6
+ metadata.gz: fdcc5ba0f68af828dd0d0908c55e4f69fdf14b7ca12ad80ad63d0083c73a49924a3d575ddc60ab3786c240faa120f1543aafbeed01c037e7246161d129d2bb0b
7
+ data.tar.gz: fae363d934fae8f8bbfcb26ce5f9187984c4e1094c11d43ad9e3f956f0682414d284195f13e390cda73bd4791dfe8ea8ab2e81ef71a8831300b0d5b39beaabe3
data/Rakefile CHANGED
@@ -14,8 +14,12 @@ DummyApp::RakeTasks.new(
14
14
  lib_name: 'solidus_core'
15
15
  )
16
16
 
17
- require 'yard'
18
- YARD::Rake::YardocTask.new
17
+ require 'yard/rake/yardoc_task'
18
+ YARD::Rake::YardocTask.new(:yard)
19
+ # The following workaround can be removed
20
+ # once https://github.com/lsegal/yard/pull/1457 is merged.
21
+ task('yard:require') { require 'yard' }
22
+ task yard: 'yard:require'
19
23
 
20
24
  namespace :spec do
21
25
  task :isolated do
@@ -4,7 +4,7 @@ require 'cancan'
4
4
  require_dependency 'spree/core/controller_helpers/strong_parameters'
5
5
 
6
6
  class Spree::BaseController < ApplicationController
7
- include Spree::Core::ControllerHelpers::CurrentHost
7
+ include ActiveStorage::SetCurrent
8
8
  include Spree::Core::ControllerHelpers::Auth
9
9
  include Spree::Core::ControllerHelpers::Common
10
10
  include Spree::Core::ControllerHelpers::PaymentParameters
@@ -59,6 +59,10 @@ module Spree
59
59
  analyze unless analyzed?
60
60
 
61
61
  @attachment.metadata
62
+ rescue ActiveStorage::FileNotFoundError => error
63
+ logger.error("#{error} - Image id: #{attachment.record.id} is corrupted or cannot be found")
64
+
65
+ { identified: nil, width: nil, height: nil, analyzed: true }
62
66
  end
63
67
 
64
68
  def styles_to_transformations(styles)
@@ -3,8 +3,28 @@
3
3
  module Spree::RansackableAttributes
4
4
  extend ActiveSupport::Concern
5
5
  included do
6
- class_attribute :whitelisted_ransackable_associations
7
- class_attribute :whitelisted_ransackable_attributes
6
+ class_attribute :allowed_ransackable_associations, default: []
7
+ class_attribute :allowed_ransackable_attributes, default: []
8
+
9
+ def self.whitelisted_ransackable_associations
10
+ Spree::Deprecation.deprecation_warning(:whitelisted_ransackable_associations, 'use allowed_ransackable_associations instead')
11
+ allowed_ransackable_associations
12
+ end
13
+
14
+ def self.whitelisted_ransackable_associations=(new_value)
15
+ Spree::Deprecation.deprecation_warning(:whitelisted_ransackable_associations=, 'use allowed_ransackable_associations= instead')
16
+ self.allowed_ransackable_associations = new_value
17
+ end
18
+
19
+ def self.whitelisted_ransackable_attributes
20
+ Spree::Deprecation.deprecation_warning(:whitelisted_ransackable_attributes, 'use allowed_ransackable_attributes instead')
21
+ allowed_ransackable_attributes
22
+ end
23
+
24
+ def self.whitelisted_ransackable_attributes=(new_value)
25
+ Spree::Deprecation.deprecation_warning(:whitelisted_ransackable_attributes=, 'use allowed_ransackable_attributes= instead')
26
+ self.allowed_ransackable_attributes = new_value
27
+ end
8
28
 
9
29
  class_attribute :default_ransackable_attributes
10
30
  self.default_ransackable_attributes = %w[id]
@@ -12,11 +32,11 @@ module Spree::RansackableAttributes
12
32
 
13
33
  class_methods do
14
34
  def ransackable_associations(*_args)
15
- whitelisted_ransackable_associations || []
35
+ allowed_ransackable_associations
16
36
  end
17
37
 
18
38
  def ransackable_attributes(*_args)
19
- default_ransackable_attributes | (whitelisted_ransackable_attributes || [])
39
+ default_ransackable_attributes | allowed_ransackable_attributes
20
40
  end
21
41
  end
22
42
  end
@@ -32,8 +32,8 @@ module Spree
32
32
  include Spree::RansackableAttributes unless included_modules.include?(Spree::RansackableAttributes)
33
33
 
34
34
  ransack_alias :name, :addresses_name
35
- self.whitelisted_ransackable_associations = %w[addresses spree_roles]
36
- self.whitelisted_ransackable_attributes = %w[name id email created_at]
35
+ self.allowed_ransackable_associations = %w[addresses spree_roles]
36
+ self.allowed_ransackable_attributes = %w[name id email created_at]
37
37
  end
38
38
 
39
39
  def wallet
@@ -26,7 +26,7 @@ module Spree
26
26
  DB_ONLY_ATTRS = %w(id updated_at created_at).freeze
27
27
  TAXATION_ATTRS = %w(state_id country_id zipcode).freeze
28
28
 
29
- self.whitelisted_ransackable_attributes = %w[name]
29
+ self.allowed_ransackable_attributes = %w[name]
30
30
 
31
31
  scope :with_values, ->(attributes) do
32
32
  where(value_attributes(attributes))
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency 'spree/calculator'
4
+
5
+ module Spree
6
+ # Very simple tax rate calculator. Can be used to apply a flat fee to any
7
+ # type of item, including an order.
8
+ class Calculator::FlatFee < Calculator
9
+ alias_method :rate, :calculable
10
+
11
+ # Amount is fixed regardles of what it's being applied to.
12
+ def compute(_object)
13
+ rate.active? ? rate.amount : 0
14
+ end
15
+
16
+ alias_method :compute_order, :compute
17
+ alias_method :compute_shipment, :compute
18
+ alias_method :compute_line_item, :compute
19
+ alias_method :compute_shipping_rate, :compute
20
+ end
21
+ end
@@ -8,7 +8,7 @@ module Spree
8
8
 
9
9
  validates :name, :iso_name, presence: true
10
10
 
11
- self.whitelisted_ransackable_attributes = %w[name]
11
+ self.allowed_ransackable_attributes = %w[name]
12
12
 
13
13
  def self.default
14
14
  find_by!(iso: Spree::Config.default_country_iso)
@@ -97,7 +97,7 @@ module Spree
97
97
 
98
98
  # Sets the last digits field based on the assigned credit card number.
99
99
  def set_last_digits
100
- self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1)
100
+ self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..)
101
101
  end
102
102
 
103
103
  # @return [String] the credit card type if it can be determined from the
@@ -17,7 +17,7 @@ module Spree
17
17
 
18
18
  accepts_nested_attributes_for :return_items
19
19
 
20
- self.whitelisted_ransackable_attributes = ['number']
20
+ self.allowed_ransackable_attributes = ['number']
21
21
 
22
22
  extend DisplayMoney
23
23
  money_methods :total, :total_excluding_vat, :amount
@@ -43,8 +43,8 @@ module Spree
43
43
 
44
44
  attr_accessor :target_shipment, :price_currency
45
45
 
46
- self.whitelisted_ransackable_associations = ['variant']
47
- self.whitelisted_ransackable_attributes = ['variant_id']
46
+ self.allowed_ransackable_associations = ['variant']
47
+ self.allowed_ransackable_attributes = ['variant_id']
48
48
 
49
49
  # @return [BigDecimal] the amount of this line item, which is the line
50
50
  # item's price multiplied by its quantity.
@@ -25,7 +25,7 @@ module Spree
25
25
  after_touch :touch_all_products
26
26
  after_save :touch_all_products
27
27
 
28
- self.whitelisted_ransackable_attributes = %w[name]
28
+ self.allowed_ransackable_attributes = %w[name]
29
29
 
30
30
  def touch_all_products
31
31
  products.find_each(&:touch)
@@ -25,7 +25,7 @@ module Spree
25
25
  # TODO: Remove allow_nil once option_type is required on Solidus v4.0
26
26
  delegate :name, :presentation, to: :option_type, prefix: :option_type, allow_nil: true
27
27
 
28
- self.whitelisted_ransackable_attributes = %w[name presentation]
28
+ self.allowed_ransackable_attributes = %w[name presentation]
29
29
 
30
30
  # Updates the updated_at column on all the variants associated with this
31
31
  # option value.
@@ -35,11 +35,17 @@ module Spree
35
35
  # Use the random number if no other order exists with it.
36
36
  if Spree::Order.exists?(number: random)
37
37
  # If over half of all possible options are taken add another digit.
38
- @length += 1 if Spree::Order.count > (10**@length / 2)
38
+ @length += 1 if order_count > (10**@length / 2)
39
39
  else
40
40
  break random
41
41
  end
42
42
  end
43
43
  end
44
+
45
+ private
46
+
47
+ def order_count
48
+ @order_count ||= Spree::Order.count
49
+ end
44
50
  end
45
51
  end
@@ -62,8 +62,8 @@ module Spree
62
62
  go_to_state :confirm
63
63
  end
64
64
 
65
- self.whitelisted_ransackable_associations = %w[shipments user order_promotions promotions bill_address ship_address line_items]
66
- self.whitelisted_ransackable_attributes = %w[completed_at created_at email number state payment_state shipment_state total store_id]
65
+ self.allowed_ransackable_associations = %w[shipments user order_promotions promotions bill_address ship_address line_items]
66
+ self.allowed_ransackable_attributes = %w[completed_at created_at email number state payment_state shipment_state total store_id]
67
67
 
68
68
  attr_reader :coupon_code
69
69
  attr_accessor :temporary_address
@@ -596,8 +596,9 @@ module Spree
596
596
 
597
597
  if matching_store_credits.any?
598
598
  payment_method = Spree::PaymentMethod::StoreCredit.first
599
+ sorter = Spree::Config.store_credit_prioritizer_class.new(matching_store_credits, self)
599
600
 
600
- matching_store_credits.order_by_priority.each do |credit|
601
+ sorter.call.each do |credit|
601
602
  break if remaining_total.zero?
602
603
  next if credit.amount_remaining.zero?
603
604
 
@@ -16,7 +16,7 @@ module Spree
16
16
  validates :promotion, presence: true
17
17
  validates :promotion_code, presence: true, if: :require_promotion_code?
18
18
 
19
- self.whitelisted_ransackable_associations = %w[promotion_code]
19
+ self.allowed_ransackable_associations = %w[promotion_code]
20
20
 
21
21
  private
22
22
 
@@ -110,8 +110,7 @@ module Spree
110
110
  # http://www.hmrc.gov.uk/vat/managing/charging/discounts-etc.htm#1
111
111
  # It also fits the criteria for sales tax as outlined here:
112
112
  # http://www.boe.ca.gov/formspubs/pub113/
113
- update_item_promotions
114
- update_order_promotions
113
+ update_promotions
115
114
  update_taxes
116
115
  update_cancellations
117
116
  update_item_totals
@@ -163,6 +162,7 @@ module Spree
163
162
  order.included_tax_total = all_items.sum(&:included_tax_total) + order_tax_adjustments.select(&:included?).sum(&:amount)
164
163
  order.additional_tax_total = all_items.sum(&:additional_tax_total) + order_tax_adjustments.reject(&:included?).sum(&:amount)
165
164
 
165
+ # TODO: Delete this line in Solidus 4.0, when it is run in `update_promotions`.
166
166
  order.promo_total = all_items.sum(&:promo_total) + adjustments.select(&:eligible?).select(&:promotion?).sum(&:amount)
167
167
 
168
168
  update_order_total
@@ -196,6 +196,11 @@ module Spree
196
196
  end
197
197
  end
198
198
 
199
+ def update_promotions
200
+ Spree::Config.promotion_adjuster_class.new(order).call
201
+ end
202
+
203
+ # DEPRECATED; this functionality is handled in #update_promotions
199
204
  def update_item_promotions
200
205
  [*line_items, *shipments].each do |item|
201
206
  promotion_adjustments = item.adjustments.select(&:promotion?)
@@ -206,16 +211,20 @@ module Spree
206
211
  item.promo_total = promotion_adjustments.select(&:eligible?).sum(&:amount)
207
212
  end
208
213
  end
214
+ deprecate update_item_promotions: :update_promotions, deprecator: Spree::Deprecation
209
215
 
210
216
  # Update and select the best promotion adjustment for the order.
211
217
  # We don't update the order.promo_total yet. Order totals are updated later
212
218
  # in #update_adjustment_total since they include the totals from the order's
213
219
  # line items and/or shipments.
220
+ #
221
+ # DEPRECATED; this functionality is handled in #update_promotions
214
222
  def update_order_promotions
215
223
  promotion_adjustments = order.adjustments.select(&:promotion?)
216
224
  promotion_adjustments.each(&:recalculate)
217
225
  Spree::Config.promotion_chooser_class.new(promotion_adjustments).update
218
226
  end
227
+ deprecate update_order_promotions: :update_promotions, deprecator: Spree::Deprecation
219
228
 
220
229
  def update_taxes
221
230
  Spree::Config.tax_adjuster_class.new(order).adjust!
@@ -35,12 +35,36 @@ module Spree
35
35
  end
36
36
 
37
37
  def authorize!
38
- handle_payment_preconditions { process_authorization }
38
+ return unless check_payment_preconditions!
39
+
40
+ started_processing!
41
+
42
+ protect_from_connection_error do
43
+ response = payment_method.authorize(
44
+ money.money.cents,
45
+ source,
46
+ gateway_options,
47
+ )
48
+ pend! if handle_response(response)
49
+ end
39
50
  end
40
51
 
41
52
  # Captures the entire amount of a payment.
42
53
  def purchase!
43
- handle_payment_preconditions { process_purchase }
54
+ return unless check_payment_preconditions!
55
+
56
+ started_processing!
57
+
58
+ protect_from_connection_error do
59
+ response = payment_method.purchase(
60
+ money.money.cents,
61
+ source,
62
+ gateway_options,
63
+ )
64
+ complete! if handle_response(response)
65
+ end
66
+
67
+ capture_events.create!(amount: amount)
44
68
  end
45
69
 
46
70
  # Takes the amount in cents to capture.
@@ -62,7 +86,7 @@ module Spree
62
86
  money = ::Money.new(capture_amount, currency)
63
87
  capture_events.create!(amount: money.to_d)
64
88
  update!(amount: captured_amount)
65
- handle_response(response, :complete, :failure)
89
+ complete! if handle_response(response)
66
90
  end
67
91
  end
68
92
 
@@ -139,67 +163,46 @@ module Spree
139
163
 
140
164
  private
141
165
 
142
- def process_authorization
143
- started_processing!
144
- gateway_action(source, :authorize, :pend)
145
- end
166
+ # @raises Spree::Core::GatewayError
167
+ def check_payment_preconditions!
168
+ return if processing?
169
+ return unless payment_method
170
+ return unless payment_method.source_required?
146
171
 
147
- def process_purchase
148
- started_processing!
149
- gateway_action(source, :purchase, :complete)
150
- # This won't be called if gateway_action raises a GatewayError
151
- capture_events.create!(amount: amount)
152
- end
153
-
154
- def handle_payment_preconditions(&_block)
155
- unless block_given?
156
- raise ArgumentError.new("handle_payment_preconditions must be called with a block")
172
+ unless source
173
+ gateway_error(I18n.t('spree.payment_processing_failed'))
157
174
  end
158
175
 
159
- return if payment_method.nil?
160
- return if !payment_method.source_required?
161
-
162
- if source
163
- if !processing?
164
- if payment_method.supports?(source)
165
- yield
166
- else
167
- invalidate!
168
- raise Core::GatewayError.new(I18n.t('spree.payment_method_not_supported'))
169
- end
170
- end
171
- else
172
- raise Core::GatewayError.new(I18n.t('spree.payment_processing_failed'))
176
+ unless payment_method.supports?(source)
177
+ invalidate!
178
+ gateway_error(I18n.t('spree.payment_method_not_supported'))
173
179
  end
174
- end
175
180
 
176
- def gateway_action(source, action, success_state)
177
- protect_from_connection_error do
178
- response = payment_method.send(action, money.money.cents,
179
- source,
180
- gateway_options)
181
- handle_response(response, success_state, :failure)
182
- end
181
+ true
183
182
  end
184
183
 
185
- def handle_response(response, success_state, failure_state)
184
+ # @returns true if the response is successful
185
+ # @returns false (and calls #failure) if the response is not successful
186
+ def handle_response(response)
186
187
  record_response(response)
187
188
 
188
- if response.success?
189
- unless response.authorization.nil?
190
- self.response_code = response.authorization
191
- self.avs_response = response.avs_result['code']
192
-
193
- if response.cvv_result
194
- self.cvv_response_code = response.cvv_result['code']
195
- self.cvv_response_message = response.cvv_result['message']
196
- end
197
- end
198
- send("#{success_state}!")
199
- else
200
- send(failure_state)
189
+ unless response.success?
190
+ failure
201
191
  gateway_error(response)
192
+ return false
193
+ end
194
+
195
+ unless response.authorization.nil?
196
+ self.response_code = response.authorization
197
+ self.avs_response = response.avs_result['code']
198
+
199
+ if response.cvv_result
200
+ self.cvv_response_code = response.cvv_result['code']
201
+ self.cvv_response_message = response.cvv_result['message']
202
+ end
202
203
  end
204
+
205
+ true
203
206
  end
204
207
 
205
208
  def record_response(response)
@@ -207,9 +210,9 @@ module Spree
207
210
  end
208
211
 
209
212
  def protect_from_connection_error
210
- yield
213
+ yield
211
214
  rescue ActiveMerchant::ConnectionError => error
212
- gateway_error(error)
215
+ gateway_error(error)
213
216
  end
214
217
 
215
218
  def gateway_error(error)
@@ -57,13 +57,12 @@ module Spree
57
57
  end
58
58
  end
59
59
 
60
- def void(_response_code, _credit_card, _options = {})
61
- ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
62
- end
63
-
64
- # @see Spree::PaymentMethod#try_void
65
- def try_void(_payment)
66
- ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
60
+ def void(_response_code, _credit_card, options = {})
61
+ if options[:originator].completed?
62
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
63
+ else
64
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
65
+ end
67
66
  end
68
67
 
69
68
  def test?
@@ -22,5 +22,13 @@ module Spree
22
22
  ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, message: FAILURE_MESSAGE, test: true)
23
23
  end
24
24
  end
25
+
26
+ def void(_response_code, options = {})
27
+ if options[:originator].completed?
28
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
29
+ else
30
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
31
+ end
32
+ end
25
33
  end
26
34
  end
@@ -173,16 +173,22 @@ module Spree
173
173
  # Return +false+ or +nil+ if the void is not possible anymore - because it was already processed by the bank.
174
174
  # Solidus will refund the amount of the payment in this case.
175
175
  #
176
- # @return [ActiveMerchant::Billing::Response] with +true+ if the void succeeded
177
- # @return [ActiveMerchant::Billing::Response] with +false+ if the void failed
178
- # @return [false] if it can't be voided at this time
179
- #
180
- def try_void(_payment)
181
- raise ::NotImplementedError,
182
- "You need to implement `try_void` for #{self.class.name}. In that " \
183
- 'return a ActiveMerchant::Billing::Response object if the void succeeds '\
184
- 'or `false|nil` if the void is not possible anymore. ' \
185
- 'Solidus will refund the amount of the payment then.'
176
+ # This default implementation will void the payment if void succeeds,
177
+ # otherwise it returns false.
178
+ #
179
+ # @api public
180
+ # @param payment [Spree::Payment] the payment to void
181
+ # @return [ActiveMerchant::Billing::Response|FalseClass]
182
+ def try_void(payment)
183
+ void_attempt = if payment.payment_method.payment_profiles_supported?
184
+ void(payment.transaction_id, payment.source, { originator: payment })
185
+ else
186
+ void(payment.transaction_id, { originator: payment })
187
+ end
188
+
189
+ return void_attempt if void_attempt.success?
190
+
191
+ false
186
192
  end
187
193
 
188
194
  def store_credit?
@@ -30,7 +30,7 @@ module Spree
30
30
  money_methods :amount, :price
31
31
  alias_method :money, :display_amount
32
32
 
33
- self.whitelisted_ransackable_attributes = %w(amount variant_id currency country_iso)
33
+ self.allowed_ransackable_attributes = %w(amount variant_id currency country_iso)
34
34
 
35
35
  # An alias for #amount
36
36
  def price
@@ -131,11 +131,11 @@ module Spree
131
131
 
132
132
  alias :options :product_option_types
133
133
 
134
- self.whitelisted_ransackable_associations = %w[stores variants_including_master master variants]
135
- self.whitelisted_ransackable_attributes = %w[name slug]
134
+ self.allowed_ransackable_associations = %w[stores variants_including_master master variants]
135
+ self.allowed_ransackable_attributes = %w[name slug]
136
136
 
137
137
  def self.ransackable_scopes(_auth_object = nil)
138
- %i(with_discarded with_variant_sku_cont with_all_variant_sku_cont with_kept_variant_sku_cont)
138
+ %i(available with_discarded with_variant_sku_cont with_all_variant_sku_cont with_kept_variant_sku_cont)
139
139
  end
140
140
 
141
141
  # @return [Boolean] true if there are any variants
@@ -9,6 +9,6 @@ module Spree
9
9
  belongs_to :product, touch: true, class_name: 'Spree::Product', inverse_of: :product_properties, optional: true
10
10
  belongs_to :property, class_name: 'Spree::Property', inverse_of: :product_properties, optional: true
11
11
 
12
- self.whitelisted_ransackable_attributes = ['value']
12
+ self.allowed_ransackable_attributes = ['value']
13
13
  end
14
14
  end
@@ -7,6 +7,7 @@ module Spree
7
7
  def perform(payload = {})
8
8
  order = payload[:order]
9
9
  promotion_code = payload[:promotion_code]
10
+ return false unless promotion.eligible? order
10
11
 
11
12
  created_adjustments = order.shipments.map do |shipment|
12
13
  next if promotion_credit_exists?(shipment)