Skip to content

Commit f1267d2

Browse files
Jonathan Tapiatvdeyen
authored andcommitted
Fix issue refunding uncompleted payments
1 parent fc44726 commit f1267d2

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

backend/app/views/spree/admin/payments/_list.html.erb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,19 @@
5656
</div>
5757
<div class="editing-hide">
5858
<% if payment.pending? %>
59-
<%= link_to_with_icon 'edit', t('spree.actions.edit'), nil, no_text: true, class: "js-edit", data: {action: 'edit'} %>
59+
<%= link_to_with_icon 'edit', t('spree.actions.edit'), nil, no_text: true, class: "js-edit", data: { action: 'edit' } %>
6060
<% end %>
61-
<% allowed_actions = payment.actions.select { |a| can?(a.to_sym, payment) } %>
62-
<% allowed_actions.each do |action| %>
61+
<% payment.actions.each do |action| %>
62+
<% next unless can?(action.to_sym, payment) %>
63+
6364
<% if action == 'credit' %>
64-
<%= link_to_with_icon 'mail-reply', t('spree.actions.refund'), new_admin_order_payment_refund_path(@order, payment), no_text: true %>
65-
<% elsif action == 'capture' && !@order.completed? %>
66-
<%# no capture prior to completion. payments get captured when the order completes. %>
65+
<% next if payment.invalid? || payment.failed? || payment.checkout? %>
66+
67+
<%= link_to_with_icon 'reply', t('spree.refund'), new_admin_order_payment_refund_path(@order, payment), no_text: true %>
6768
<% else %>
69+
<% next if action == 'capture' && !@order.completed? %>
70+
<% next if action == 'void' && (payment.invalid? || payment.failed?) %>
71+
6872
<%= link_to_with_icon action, t(action, scope: 'spree'), fire_admin_order_payment_path(@order, payment, e: action), method: :put, no_text: true, data: {action: action} %>
6973
<% end %>
7074
<% end %>

backend/spec/features/admin/orders/payments_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,21 @@
3737
click_icon(:capture)
3838
expect(page).not_to have_content('Cannot perform requested operation')
3939
expect(page).to have_content('Payment Updated')
40+
within_row(1) do
41+
expect(page).to have_selector('.fa-reply')
42+
end
4043
end
4144

4245
it 'voids a check payment from a new order' do
4346
click_icon(:void)
4447
expect(page).to have_content('Payment Updated')
4548
end
49+
50+
it 'voids refund option for incomplete payments' do
51+
within_row(1) do
52+
expect(page).not_to have_selector('.fa-reply')
53+
end
54+
end
4655
end
4756

4857
it 'should list all captures for a payment' do

0 commit comments

Comments
 (0)