Skip to content

Commit

Permalink
Perform refund during payment cancellation
Browse files Browse the repository at this point in the history
Previously the #cancel method relied on the after_create callback
performing the refund. Now it is explicitly called after the refund is
built.
  • Loading branch information
swively authored and kennyadsl committed May 29, 2020
1 parent 0755395 commit 2f7ec0f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/app/models/spree/payment/cancellation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def cancel(payment)
if response = payment.payment_method.try_void(payment)
payment.send(:handle_void_response, response)
else
payment.refunds.create!(amount: payment.credit_allowed, reason: refund_reason)
payment.refunds.create!(amount: payment.credit_allowed, reason: refund_reason).perform!
end
else
# For payment methods not yet implemeting `try_void`
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
let(:payment) { create(:payment, order: order, amount: payment_amount, state: 'completed') }

before do
create(:refund, payment: payment, amount: payment_amount)
create(:refund, payment: payment, amount: payment_amount).perform!
end

it "cancels the order" do
Expand Down Expand Up @@ -281,7 +281,7 @@
order.cancellations.short_ship([order.inventory_units.first])
expect(order.outstanding_balance).to be_negative
expect(order.payment_state).to eq('credit_owed')
create(:refund, amount: order.outstanding_balance.abs, payment: payment, transaction_id: nil)
create(:refund, amount: order.outstanding_balance.abs, payment: payment, transaction_id: nil).perform!
order.reload
expect(order.outstanding_balance).to eq(0)
expect(order.payment_state).to eq('paid')
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/payment/cancellation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
payment.refunds.create!(
amount: credit_amount,
reason: Spree::RefundReason.where(name: 'test').first_or_create
)
).perform!
end

it 'only refunds the allowed credit amount' do
Expand Down

0 comments on commit 2f7ec0f

Please sign in to comment.