Skip to content

Commit ceadf35

Browse files
authored
Merge pull request #6094 from jtapia/bugfix/admin-payment-action-options
[Backend] Fix issue refunding uncompleted payments
2 parents 92431a9 + 3670ead commit ceadf35

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

admin/spec/features/return_reasons_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
expect(page).to be_axe_clean
8080
end
8181

82-
it "closing the modal keeps query params" do
82+
it "closing the modal keeps query params", :flaky do
8383
within("dialog") { click_on "Cancel" }
8484
expect(page).not_to have_selector("dialog")
8585
expect(page.current_url).to include(query)

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)