Skip to content

Commit

Permalink
Merge pull request #69 from bonobos/fix-pending-store-credit-cancella…
Browse files Browse the repository at this point in the history
…tion

Fix payment cancellation for pending store credits
  • Loading branch information
athal7 committed May 29, 2015
2 parents f904ac8 + 9f31e49 commit 3c52126
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 3c52126

Please sign in to comment.