Skip to content

Commit

Permalink
Fix payment cancellation for pending store credits
Browse files Browse the repository at this point in the history
This fixes store credit payment cancellation when auto-capture is
turned off.

When auto-capture is turned off an order can be canceled with its
store credit payments "authorized" but not "captured". The old code
was marking the payments as voided but not actually voiding them
and releasing the authorization.
  • Loading branch information
jordan-brough authored and athal7 committed May 28, 2015
1 parent e63145d commit 9f31e49
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def ensure_available_shipping_rates
def after_cancel
shipments.each { |shipment| shipment.cancel! }
payments.completed.each { |payment| payment.cancel! }
payments.store_credits.pending.each { |payment| payment.void! }
payments.store_credits.pending.each { |payment| payment.void_transaction! }

send_cancel_email
self.update!
Expand Down
41 changes: 41 additions & 0 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1337,5 +1337,46 @@ def compute(computable)
expect(subject.display_store_credit_remaining_after_capture.money.cents).to eq (amount_remaining * 100.0)
end
end

context 'when not capturing at order completion' do
let!(:store_credit_payment_method) do
create(
:store_credit_payment_method,
auto_capture: false, # not capturing at completion time
)
end

describe '#after_cancel' do
let(:user) { create(:user) }
let!(:store_credit) do
create(:store_credit, amount: 100, user: user)
end
let(:order) do
create(
:order_with_line_items,
user: user,
line_items_count: 1,
# order will be $20 total:
line_items_price: 10,
shipment_cost: 10,
)
end

before do
order.contents.advance
order.complete!
end

it 'releases the pending store credit authorization' do
expect {
order.cancel!
}.to change {
store_credit.reload.amount_authorized
}.from(20).to(0)

expect(store_credit.amount_remaining).to eq 100
end
end
end
end
end

0 comments on commit 9f31e49

Please sign in to comment.