solidus_core 4.7.3 → 4.7.4
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.
- checksums.yaml +4 -4
- data/app/helpers/spree/core/controller_helpers/order.rb +2 -1
- data/app/helpers/spree/core/controller_helpers/payment_parameters.rb +12 -0
- data/app/models/spree/ability.rb +3 -0
- data/app/models/spree/core/state_machines/order/class_methods.rb +2 -0
- data/app/models/spree/order.rb +38 -1
- data/app/models/spree/payment.rb +40 -0
- data/app/models/spree/payment_method/check.rb +4 -0
- data/app/models/spree/payment_method/credit_card.rb +4 -0
- data/app/models/spree/payment_method.rb +11 -0
- data/app/models/spree/permission_sets/user_management.rb +1 -1
- data/app/models/spree/return_item.rb +10 -0
- data/config/locales/en.yml +2 -0
- data/lib/spree/app_configuration.rb +38 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/permitted_attributes.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f06b973c756f7c5335159cbef0349cf4611428ea8e9a8e8a52efab8b82ae993a
|
|
4
|
+
data.tar.gz: aa2d704a151b44f176e8eaa63ac76b675c00a7172fec542f435694a77b67fb47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 862b7232c4aa01624a1a50e12c58c164083854d26d7cb54d7135a0b903bef60cb1cc133961baef3fa125eab3acdc066e1c2dea5e815848ba2c22d2d99d8a2c17
|
|
7
|
+
data.tar.gz: e81be3b1e8defc525eb390f5ca3d4cb2f0ab0f3e378ea9878336254f17bee5d5fe1e9773bc13d3de16d69c5b2ef6f8b9f7938d386e25578cea2db012333e9bf6
|
|
@@ -62,7 +62,8 @@ module Spree
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def new_order_params
|
|
65
|
-
current_order_params.merge(last_ip_address: ip_address)
|
|
65
|
+
order_params = current_order_params.merge(last_ip_address: ip_address)
|
|
66
|
+
spree_current_user ? order_params.except(:guest_token) : order_params
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
def find_order_by_token_or_user(options = {})
|
|
@@ -117,6 +117,12 @@ module Spree
|
|
|
117
117
|
params
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
+
# @deprecated This method is deprecated and will be removed in Solidus 5.0.0.
|
|
121
|
+
#
|
|
122
|
+
# This behaviour is no longer needed since the amount is no longer a
|
|
123
|
+
# permitted attribute. Instead, payment amounts are set automatically in an
|
|
124
|
+
# after_create callback for payments with an amount of zero.
|
|
125
|
+
#
|
|
120
126
|
# This is a strange thing to do since an order can have multiple payments
|
|
121
127
|
# but we always assume that it only has a single payment and that its
|
|
122
128
|
# amount should be the current order total after store credit is applied.
|
|
@@ -160,5 +166,11 @@ module Spree
|
|
|
160
166
|
|
|
161
167
|
params
|
|
162
168
|
end
|
|
169
|
+
deprecate set_payment_parameters_amount: <<~MSG.squish, deprecator: Spree.deprecator
|
|
170
|
+
Remove this call from your controllers. Payment amounts are no longer
|
|
171
|
+
permitted parameters, so the amount it sets is ignored. New checkout
|
|
172
|
+
payments are now set to the order's remaining balance automatically (see
|
|
173
|
+
`Spree::Config.balance_checkout_payment_on_create`).
|
|
174
|
+
MSG
|
|
163
175
|
end
|
|
164
176
|
end
|
data/app/models/spree/ability.rb
CHANGED
|
@@ -29,6 +29,9 @@ module Spree
|
|
|
29
29
|
def initialize(current_user)
|
|
30
30
|
@user = current_user || Spree.user_class.new
|
|
31
31
|
|
|
32
|
+
alias_action :admin, :create, to: :admin_create
|
|
33
|
+
alias_action :admin, :update, to: :admin_update
|
|
34
|
+
|
|
32
35
|
activate_permission_sets
|
|
33
36
|
register_extension_abilities
|
|
34
37
|
end
|
|
@@ -97,6 +97,8 @@ module Spree
|
|
|
97
97
|
before_transition to: :complete, do: :ensure_line_item_variants_are_not_deleted
|
|
98
98
|
before_transition to: :complete, do: :ensure_inventory_units
|
|
99
99
|
if states[:payment]
|
|
100
|
+
before_transition to: :complete, do: :balance_checkout_payment_amount
|
|
101
|
+
before_transition to: :complete, do: :ensure_payments_match_order_total
|
|
100
102
|
before_transition to: :complete, do: :process_payments_before_complete
|
|
101
103
|
end
|
|
102
104
|
|
data/app/models/spree/order.rb
CHANGED
|
@@ -626,7 +626,16 @@ module Spree
|
|
|
626
626
|
if remaining_total.zero?
|
|
627
627
|
other_payments.each(&:invalidate!)
|
|
628
628
|
elsif other_payments.size == 1
|
|
629
|
-
other_payments.first
|
|
629
|
+
payment = other_payments.first
|
|
630
|
+
|
|
631
|
+
if payment.amount < remaining_total && !payment.payment_method.allows_amount_changes?
|
|
632
|
+
payment.invalidate!
|
|
633
|
+
payments.reset
|
|
634
|
+
errors.add(:base, I18n.t("spree.payment_insufficient"))
|
|
635
|
+
return false
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
payment.update!(amount: remaining_total)
|
|
630
639
|
end
|
|
631
640
|
|
|
632
641
|
payments.reset
|
|
@@ -742,6 +751,34 @@ module Spree
|
|
|
742
751
|
|
|
743
752
|
private
|
|
744
753
|
|
|
754
|
+
def balance_checkout_payment_amount
|
|
755
|
+
return unless Spree::Config.balance_checkout_payment_before_complete
|
|
756
|
+
return unless payment_required?
|
|
757
|
+
|
|
758
|
+
payment = payments.select { |payment| payment.checkout? && !payment.store_credit? }.max_by(&:id)
|
|
759
|
+
return unless payment
|
|
760
|
+
|
|
761
|
+
if payment.payment_method.allows_amount_changes?
|
|
762
|
+
payment.balance_amount!
|
|
763
|
+
elsif payment.insufficient?
|
|
764
|
+
payment.invalidate!
|
|
765
|
+
payment_failed! if can_payment_failed?
|
|
766
|
+
errors.add(:base, I18n.t("spree.payment_insufficient"))
|
|
767
|
+
false
|
|
768
|
+
end
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
def ensure_payments_match_order_total
|
|
772
|
+
return unless Spree::Config.require_payments_to_match_order_total
|
|
773
|
+
return unless payment_required?
|
|
774
|
+
|
|
775
|
+
valid_payments = payments.valid
|
|
776
|
+
return if valid_payments.empty? || valid_payments.sum(:amount) == total
|
|
777
|
+
|
|
778
|
+
errors.add(:base, I18n.t("spree.payment_total_mismatch"))
|
|
779
|
+
false
|
|
780
|
+
end
|
|
781
|
+
|
|
745
782
|
def process_payments_before_complete
|
|
746
783
|
return if !payment_required?
|
|
747
784
|
|
data/app/models/spree/payment.rb
CHANGED
|
@@ -34,6 +34,7 @@ module Spree
|
|
|
34
34
|
|
|
35
35
|
# invalidate previously entered payments
|
|
36
36
|
after_create :invalidate_old_payments
|
|
37
|
+
after_create :balance_checkout_amount
|
|
37
38
|
|
|
38
39
|
attr_accessor :request_env
|
|
39
40
|
|
|
@@ -150,6 +151,23 @@ module Spree
|
|
|
150
151
|
payment_method.try!(:store_credit?)
|
|
151
152
|
end
|
|
152
153
|
|
|
154
|
+
# Used to set the amount of a payment to the remaining balance of the order
|
|
155
|
+
# after store credit is applied. This is used in a before transition to
|
|
156
|
+
# complete callback to ensure the order is not underpaid. Most of the time
|
|
157
|
+
# this should be a no-op.
|
|
158
|
+
def balance_amount!
|
|
159
|
+
new_amount = balanced_amount
|
|
160
|
+
return if amount == new_amount
|
|
161
|
+
|
|
162
|
+
update!(amount: new_amount)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# @return [Boolean] true when this payment's amount is less than what is
|
|
166
|
+
# left to pay on the order after store credit and other valid payments
|
|
167
|
+
def insufficient?
|
|
168
|
+
amount < balanced_amount
|
|
169
|
+
end
|
|
170
|
+
|
|
153
171
|
private
|
|
154
172
|
|
|
155
173
|
def source_actions
|
|
@@ -190,6 +208,28 @@ module Spree
|
|
|
190
208
|
gateway_error error
|
|
191
209
|
end
|
|
192
210
|
|
|
211
|
+
def balanced_amount
|
|
212
|
+
other_payments_total = order.payments.valid.not_store_credits.where.not(id:).sum(:amount)
|
|
213
|
+
|
|
214
|
+
[order.order_total_after_store_credit - other_payments_total, 0].max
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Used to help ensure payments will cover the order total when they're
|
|
218
|
+
# initially created. We won't balance any payments with a non-zero amount or
|
|
219
|
+
# store credits. And our logic will skip any payments created after the
|
|
220
|
+
# order is completed.
|
|
221
|
+
#
|
|
222
|
+
# This replaces our previous logic that would set the amount of the first
|
|
223
|
+
# payment during some checkout calls by injecting it into the attributes.
|
|
224
|
+
def balance_checkout_amount
|
|
225
|
+
return unless Spree::Config.balance_checkout_payment_on_create
|
|
226
|
+
return if store_credit? || !amount.zero? || !checkout? || order.completed?
|
|
227
|
+
|
|
228
|
+
# Need to use update_column to avoid after_save callbacks. Which would
|
|
229
|
+
# trigger extra calls to create_payment_profile.
|
|
230
|
+
update_column(:amount, balanced_amount)
|
|
231
|
+
end
|
|
232
|
+
|
|
193
233
|
def invalidate_old_payments
|
|
194
234
|
if !store_credit? && !["invalid", "failed"].include?(state)
|
|
195
235
|
order.payments.select { |payment|
|
|
@@ -141,6 +141,17 @@ module Spree
|
|
|
141
141
|
type.demodulize.underscore
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
+
# Whether the amount of a payment using this payment method can be changed
|
|
145
|
+
# after the customer has submitted it. Only return true if the payment
|
|
146
|
+
# gateway charges the amount it is sent when the payment is processed, not
|
|
147
|
+
# an amount the customer approved earlier.
|
|
148
|
+
#
|
|
149
|
+
# @see Spree::AppConfiguration#balance_checkout_payment_before_complete
|
|
150
|
+
# @return [Boolean] whether the amount can be changed (default: +false+)
|
|
151
|
+
def allows_amount_changes?
|
|
152
|
+
false
|
|
153
|
+
end
|
|
154
|
+
|
|
144
155
|
def payment_profiles_supported?
|
|
145
156
|
false
|
|
146
157
|
end
|
|
@@ -23,7 +23,7 @@ module Spree
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def activate!
|
|
26
|
-
can [:admin, :read, :create, :update, :save_in_address_book, :remove_from_address_book, :addresses, :orders, :items], Spree.user_class
|
|
26
|
+
can [:admin, :admin_create, :admin_update, :read, :create, :update, :save_in_address_book, :remove_from_address_book, :addresses, :orders, :items], Spree.user_class
|
|
27
27
|
|
|
28
28
|
# NOTE: This does not work with accessible_by.
|
|
29
29
|
# See https://github.com/solidusio/solidus/pull/1263
|
|
@@ -42,6 +42,7 @@ module Spree
|
|
|
42
42
|
validate :eligible_exchange_variant
|
|
43
43
|
validate :belongs_to_same_customer_order
|
|
44
44
|
validate :belongs_to_return_authorization_order, if: -> { inventory_unit_id_changed? || return_authorization_id_changed? }
|
|
45
|
+
validate :inventory_unit_stays_on_same_order, on: :update, if: :inventory_unit_id_changed?
|
|
45
46
|
validate :validate_acceptance_status_for_reimbursement
|
|
46
47
|
validate :validate_no_other_completed_return_items
|
|
47
48
|
|
|
@@ -235,6 +236,15 @@ module Spree
|
|
|
235
236
|
end
|
|
236
237
|
end
|
|
237
238
|
|
|
239
|
+
def inventory_unit_stays_on_same_order
|
|
240
|
+
previous_inventory_unit = Spree::InventoryUnit.find_by(id: inventory_unit_id_was)
|
|
241
|
+
return unless previous_inventory_unit && inventory_unit
|
|
242
|
+
|
|
243
|
+
if previous_inventory_unit.order_id != inventory_unit.order_id
|
|
244
|
+
errors.add(:base, I18n.t("spree.return_items_cannot_be_associated_with_multiple_orders"))
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
238
248
|
def eligible_exchange_variant
|
|
239
249
|
return unless exchange_variant && exchange_variant_id_changed?
|
|
240
250
|
unless eligible_exchange_variants.include?(exchange_variant)
|
data/config/locales/en.yml
CHANGED
|
@@ -1942,6 +1942,7 @@ en:
|
|
|
1942
1942
|
payment_could_not_be_created: Payment could not be created.
|
|
1943
1943
|
payment_identifier: Payment Identifier
|
|
1944
1944
|
payment_information: Payment Information
|
|
1945
|
+
payment_insufficient: The order total has changed. Please submit your payment again.
|
|
1945
1946
|
payment_method: Payment Method
|
|
1946
1947
|
payment_method_not_supported: That payment method is unsupported. Please choose another one.
|
|
1947
1948
|
payment_method_settings_warning: If you are changing the payment method type, you must save first before you can edit the payment method settings
|
|
@@ -1961,6 +1962,7 @@ en:
|
|
|
1961
1962
|
pending: Pending
|
|
1962
1963
|
processing: Processing
|
|
1963
1964
|
void: Void
|
|
1965
|
+
payment_total_mismatch: Payment total does not match order total
|
|
1964
1966
|
payment_updated: Payment Updated
|
|
1965
1967
|
payments: Payments
|
|
1966
1968
|
payments_failed_count:
|
|
@@ -64,6 +64,38 @@ module Spree
|
|
|
64
64
|
# @return [Boolean] When false, customers must create an account to complete an order (default: +true+)
|
|
65
65
|
preference :allow_guest_checkout, :boolean, default: true
|
|
66
66
|
|
|
67
|
+
# @!attribute [rw] balance_checkout_payment_on_create
|
|
68
|
+
# @return [Boolean] When true, this will have non-store-credit checkout
|
|
69
|
+
# payments with an initial amount of zero set to the remaining balance of
|
|
70
|
+
# the order on create. (default: +true+)
|
|
71
|
+
#
|
|
72
|
+
# Customers can't set payment amounts, so when this is false, checkout
|
|
73
|
+
# payments keep an amount of zero unless your store sets them some other
|
|
74
|
+
# way. If you disable this, also enable
|
|
75
|
+
# +require_payments_to_match_order_total+ so that underpaid orders can't
|
|
76
|
+
# be completed.
|
|
77
|
+
preference :balance_checkout_payment_on_create, :boolean, default: true
|
|
78
|
+
|
|
79
|
+
# @!attribute [rw] balance_checkout_payment_before_complete
|
|
80
|
+
# @return [Boolean] When true, the most recent non-store-credit checkout
|
|
81
|
+
# payment is set to the remaining balance of the order just before the
|
|
82
|
+
# order transitions to complete. This catches changes to the order total
|
|
83
|
+
# made after the payment was created. (default: +true+)
|
|
84
|
+
#
|
|
85
|
+
# This applies whatever the payment's amount is, including amounts set
|
|
86
|
+
# by admins, for example a partial payment entered in the backend before
|
|
87
|
+
# the order is completed.
|
|
88
|
+
#
|
|
89
|
+
# Payments whose payment method doesn't allow amount changes (see
|
|
90
|
+
# {Spree::PaymentMethod#allows_amount_changes?}) are never changed.
|
|
91
|
+
# Instead, if the payment doesn't cover the remaining balance, it is
|
|
92
|
+
# invalidated and the order is not completed.
|
|
93
|
+
#
|
|
94
|
+
# If you disable this, also enable
|
|
95
|
+
# +require_payments_to_match_order_total+ so that orders whose total
|
|
96
|
+
# changed after payment can't be completed underpaid.
|
|
97
|
+
preference :balance_checkout_payment_before_complete, :boolean, default: true
|
|
98
|
+
|
|
67
99
|
# @!attribute [rw] guest_token_cookie_options
|
|
68
100
|
# @return [Hash] Add additional guest_token cookie options here (ie. domain or path)
|
|
69
101
|
preference :guest_token_cookie_options, :hash, default: {}
|
|
@@ -254,6 +286,12 @@ module Spree
|
|
|
254
286
|
# @return [Boolean] Require a price on the master variant of a product (default: +true+)
|
|
255
287
|
preference :require_master_price, :boolean, default: true
|
|
256
288
|
|
|
289
|
+
# @!attribute [rw] require_payments_to_match_order_total
|
|
290
|
+
# @return [Boolean] Whether the order total must match the sum of its payments.
|
|
291
|
+
# When this is enabled, it will prevent checkout unless the total of the valid payments on the order is equal to the total.
|
|
292
|
+
# (default: +false+)
|
|
293
|
+
versioned_preference :require_payments_to_match_order_total, :boolean, initial_value: false, boundaries: {"5.0.0.alpha" => true}
|
|
294
|
+
|
|
257
295
|
# @!attribute [rw] require_payment_to_ship
|
|
258
296
|
# @return [Boolean] Allows shipments to be ready to ship regardless of the order being paid if false (default: +true+)
|
|
259
297
|
preference :require_payment_to_ship, :boolean, default: true # Allows shipments to be ready to ship regardless of the order being paid if false
|
data/lib/spree/core/version.rb
CHANGED
|
@@ -12,6 +12,7 @@ module Spree
|
|
|
12
12
|
:checkout_delivery_attributes,
|
|
13
13
|
:checkout_payment_attributes,
|
|
14
14
|
:checkout_confirm_attributes,
|
|
15
|
+
:checkout_shipment_attributes,
|
|
15
16
|
:credit_card_update_attributes,
|
|
16
17
|
:customer_return_attributes,
|
|
17
18
|
:customer_metadata_attributes,
|
|
@@ -158,14 +159,18 @@ module Spree
|
|
|
158
159
|
ship_address_attributes: address_attributes
|
|
159
160
|
]
|
|
160
161
|
|
|
162
|
+
@@checkout_shipment_attributes = [
|
|
163
|
+
:special_instructions, :id, :selected_shipping_rate_id,
|
|
164
|
+
customer_metadata: {}
|
|
165
|
+
]
|
|
166
|
+
|
|
161
167
|
@@checkout_delivery_attributes = [
|
|
162
168
|
:special_instructions,
|
|
163
|
-
shipments_attributes:
|
|
169
|
+
shipments_attributes: checkout_shipment_attributes
|
|
164
170
|
]
|
|
165
171
|
|
|
166
172
|
@@checkout_payment_attributes = [
|
|
167
173
|
payments_attributes: payment_attributes + [
|
|
168
|
-
:amount,
|
|
169
174
|
source_attributes:
|
|
170
175
|
]
|
|
171
176
|
]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solidus_core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.7.
|
|
4
|
+
version: 4.7.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Solidus Team
|
|
@@ -1121,7 +1121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
1121
1121
|
- !ruby/object:Gem::Version
|
|
1122
1122
|
version: 1.8.23
|
|
1123
1123
|
requirements: []
|
|
1124
|
-
rubygems_version: 4.0.
|
|
1124
|
+
rubygems_version: 4.0.20
|
|
1125
1125
|
specification_version: 4
|
|
1126
1126
|
summary: Essential models, mailers, and classes for the Solidus e-commerce project.
|
|
1127
1127
|
test_files: []
|