diff --git a/backend/app/views/spree/admin/payments/_list.html.erb b/backend/app/views/spree/admin/payments/_list.html.erb index 3c5828d7deb..154cee0d787 100644 --- a/backend/app/views/spree/admin/payments/_list.html.erb +++ b/backend/app/views/spree/admin/payments/_list.html.erb @@ -56,15 +56,19 @@
<% if payment.pending? %> - <%= link_to_with_icon 'edit', t('spree.actions.edit'), nil, no_text: true, class: "js-edit", data: {action: 'edit'} %> + <%= link_to_with_icon 'edit', t('spree.actions.edit'), nil, no_text: true, class: "js-edit", data: { action: 'edit' } %> <% end %> - <% allowed_actions = payment.actions.select { |a| can?(a.to_sym, payment) } %> - <% allowed_actions.each do |action| %> + <% payment.actions.each do |action| %> + <% next unless can?(action.to_sym, payment) %> + <% if action == 'credit' %> - <%= link_to_with_icon 'mail-reply', t('spree.actions.refund'), new_admin_order_payment_refund_path(@order, payment), no_text: true %> - <% elsif action == 'capture' && !@order.completed? %> - <%# no capture prior to completion. payments get captured when the order completes. %> + <% next if payment.invalid? || payment.failed? || payment.checkout? %> + + <%= link_to_with_icon 'reply', t('spree.refund'), new_admin_order_payment_refund_path(@order, payment), no_text: true %> <% else %> + <% next if action == 'capture' && !@order.completed? %> + <% next if action == 'void' && (payment.invalid? || payment.failed?) %> + <%= 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} %> <% end %> <% end %> diff --git a/backend/spec/features/admin/orders/payments_spec.rb b/backend/spec/features/admin/orders/payments_spec.rb index 910d16d95e0..a94a94f616f 100644 --- a/backend/spec/features/admin/orders/payments_spec.rb +++ b/backend/spec/features/admin/orders/payments_spec.rb @@ -37,12 +37,21 @@ click_icon(:capture) expect(page).not_to have_content('Cannot perform requested operation') expect(page).to have_content('Payment Updated') + within_row(1) do + expect(page).to have_selector('.fa-reply') + end end it 'voids a check payment from a new order' do click_icon(:void) expect(page).to have_content('Payment Updated') end + + it 'voids refund option for incomplete payments' do + within_row(1) do + expect(page).not_to have_selector('.fa-reply') + end + end end it 'should list all captures for a payment' do