Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CannotRebuildShipments < StandardError; end
belongs_to :store, class_name: 'Spree::Store'
has_many :state_changes, as: :stateful
has_many :line_items, -> { order(:created_at, :id) }, dependent: :destroy, inverse_of: :order
has_many :payments, dependent: :destroy
has_many :payments, dependent: :destroy, inverse_of: :order
has_many :return_authorizations, dependent: :destroy, inverse_of: :order
has_many :reimbursements, inverse_of: :order
has_many :adjustments, -> { order(:created_at) }, as: :adjustable, inverse_of: :adjustable, dependent: :destroy
Expand Down
23 changes: 8 additions & 15 deletions core/app/models/spree/order_capturing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,15 @@ def capture_payments
Spree::OrderMutex.with_lock!(@order) do
uncaptured_amount = @order.display_total.cents

begin
sorted_payments(@order).each do |payment|
amount = [uncaptured_amount, payment.money.cents].min

if amount > 0
payment.capture!(amount)
uncaptured_amount -= amount
elsif Spree::OrderCapturing.void_unused_payments
payment.void_transaction!
end
sorted_payments(@order).each do |payment|
amount = [uncaptured_amount, payment.money.cents].min

if amount > 0
payment.capture!(amount)
uncaptured_amount -= amount
elsif Spree::OrderCapturing.void_unused_payments
payment.void_transaction!
end
ensure
# FIXME: Adding the inverse_of on the payments relation for orders -should- fix this,
# however it only appears to make it worse (calling with changes three times instead of once.
# Warrants an investigation. Reloading for now.
@order.reload.update!
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/order_capturing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
describe '#capture_payments' do
subject { Spree::OrderCapturing.new(order, payment_methods).capture_payments }

# Regression for the order.update! in the ensure block.
# See the comment there.
# Regression for https://github.com/solidusio/solidus/pull/407
# See also https://github.com/solidusio/solidus/pull/1406
context "updating the order" do
let(:order) { create :completed_order_with_totals }
let(:payment_methods) { [] }
Expand Down