solidus_core 4.8.1 → 4.8.2
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: 4585446a89e9d7c2aedc1ea8ef011b730f9f4192459f67adc349dfeac87c7cd8
|
|
4
|
+
data.tar.gz: e5104523249d1b1172a34d2d29a5bcbee28e3f4cd52a3062dd575c5a6014814d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2bef8c8f1cbdf43b031017fc41489deb6b413e87c36087b99b2727e1ec315ac73f468e293d12bc17f665e4767d84818fa577bb45007ce5d566d7127916b47bad
|
|
7
|
+
data.tar.gz: af30c594eaa9aed68246d44abea0bf65e1d22506a0f3b2b38ed08d09d2694cf26253fb2a8cf9ab37d8cb7394b147dbfa1aeab9011f819a0c4d466404ef1af07c
|
|
@@ -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
|
@@ -624,7 +624,16 @@ module Spree
|
|
|
624
624
|
if remaining_total.zero?
|
|
625
625
|
other_payments.each(&:invalidate!)
|
|
626
626
|
elsif other_payments.size == 1
|
|
627
|
-
other_payments.first
|
|
627
|
+
payment = other_payments.first
|
|
628
|
+
|
|
629
|
+
if payment.amount < remaining_total && !payment.payment_method.allows_amount_changes?
|
|
630
|
+
payment.invalidate!
|
|
631
|
+
payments.reset
|
|
632
|
+
errors.add(:base, I18n.t("spree.payment_insufficient"))
|
|
633
|
+
return false
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
payment.update!(amount: remaining_total)
|
|
628
637
|
end
|
|
629
638
|
|
|
630
639
|
payments.reset
|
|
@@ -740,6 +749,34 @@ module Spree
|
|
|
740
749
|
|
|
741
750
|
private
|
|
742
751
|
|
|
752
|
+
def balance_checkout_payment_amount
|
|
753
|
+
return unless Spree::Config.balance_checkout_payment_before_complete
|
|
754
|
+
return unless payment_required?
|
|
755
|
+
|
|
756
|
+
payment = payments.select { |payment| payment.checkout? && !payment.store_credit? }.max_by(&:id)
|
|
757
|
+
return unless payment
|
|
758
|
+
|
|
759
|
+
if payment.payment_method.allows_amount_changes?
|
|
760
|
+
payment.balance_amount!
|
|
761
|
+
elsif payment.insufficient?
|
|
762
|
+
payment.invalidate!
|
|
763
|
+
payment_failed! if can_payment_failed?
|
|
764
|
+
errors.add(:base, I18n.t("spree.payment_insufficient"))
|
|
765
|
+
false
|
|
766
|
+
end
|
|
767
|
+
end
|
|
768
|
+
|
|
769
|
+
def ensure_payments_match_order_total
|
|
770
|
+
return unless Spree::Config.require_payments_to_match_order_total
|
|
771
|
+
return unless payment_required?
|
|
772
|
+
|
|
773
|
+
valid_payments = payments.valid
|
|
774
|
+
return if valid_payments.empty? || valid_payments.sum(:amount) == total
|
|
775
|
+
|
|
776
|
+
errors.add(:base, I18n.t("spree.payment_total_mismatch"))
|
|
777
|
+
false
|
|
778
|
+
end
|
|
779
|
+
|
|
743
780
|
def process_payments_before_complete
|
|
744
781
|
return if !payment_required?
|
|
745
782
|
|
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
|
@@ -1953,6 +1953,7 @@ en:
|
|
|
1953
1953
|
payment_could_not_be_created: Payment could not be created.
|
|
1954
1954
|
payment_identifier: Payment Identifier
|
|
1955
1955
|
payment_information: Payment Information
|
|
1956
|
+
payment_insufficient: The order total has changed. Please submit your payment again.
|
|
1956
1957
|
payment_is_not_refundable: This payment cannot be refunded in its current state.
|
|
1957
1958
|
payment_method: Payment Method
|
|
1958
1959
|
payment_method_not_supported: That payment method is unsupported. Please choose another one.
|
|
@@ -1973,6 +1974,7 @@ en:
|
|
|
1973
1974
|
pending: Pending
|
|
1974
1975
|
processing: Processing
|
|
1975
1976
|
void: Void
|
|
1977
|
+
payment_total_mismatch: Payment total does not match order total
|
|
1976
1978
|
payment_updated: Payment Updated
|
|
1977
1979
|
payments: Payments
|
|
1978
1980
|
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: {}
|
|
@@ -293,6 +325,12 @@ module Spree
|
|
|
293
325
|
# @return [Boolean] Require a price on the master variant of a product (default: +true+)
|
|
294
326
|
preference :require_master_price, :boolean, default: true
|
|
295
327
|
|
|
328
|
+
# @!attribute [rw] require_payments_to_match_order_total
|
|
329
|
+
# @return [Boolean] Whether the order total must match the sum of its payments.
|
|
330
|
+
# When this is enabled, it will prevent checkout unless the total of the valid payments on the order is equal to the total.
|
|
331
|
+
# (default: +false+)
|
|
332
|
+
versioned_preference :require_payments_to_match_order_total, :boolean, initial_value: false, boundaries: {"5.0.0.alpha" => true}
|
|
333
|
+
|
|
296
334
|
# @!attribute [rw] require_refundable_payment_state
|
|
297
335
|
# @return [Boolean] Whether creating a refund for a payment outside Spree::Config.refundable_payment_states is a validation error rather than a deprecation warning (default: +false+)
|
|
298
336
|
versioned_preference :require_refundable_payment_state, :boolean, initial_value: false, boundaries: {"5.0.0.alpha" => true}
|
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,
|
|
@@ -159,14 +160,18 @@ module Spree
|
|
|
159
160
|
ship_address_attributes: address_attributes
|
|
160
161
|
]
|
|
161
162
|
|
|
163
|
+
@@checkout_shipment_attributes = [
|
|
164
|
+
:special_instructions, :id, :selected_shipping_rate_id,
|
|
165
|
+
customer_metadata: {}
|
|
166
|
+
]
|
|
167
|
+
|
|
162
168
|
@@checkout_delivery_attributes = [
|
|
163
169
|
:special_instructions,
|
|
164
|
-
shipments_attributes:
|
|
170
|
+
shipments_attributes: checkout_shipment_attributes
|
|
165
171
|
]
|
|
166
172
|
|
|
167
173
|
@@checkout_payment_attributes = [
|
|
168
174
|
payments_attributes: payment_attributes + [
|
|
169
|
-
:amount,
|
|
170
175
|
source_attributes:
|
|
171
176
|
]
|
|
172
177
|
]
|
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.8.
|
|
4
|
+
version: 4.8.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Solidus Team
|
|
@@ -1123,7 +1123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
1123
1123
|
- !ruby/object:Gem::Version
|
|
1124
1124
|
version: 1.8.23
|
|
1125
1125
|
requirements: []
|
|
1126
|
-
rubygems_version: 4.0.
|
|
1126
|
+
rubygems_version: 4.0.20
|
|
1127
1127
|
specification_version: 4
|
|
1128
1128
|
summary: Essential models, mailers, and classes for the Solidus e-commerce project.
|
|
1129
1129
|
test_files: []
|