From bd65229d0675d68ed6453fe0be1bfdeb76645e1e Mon Sep 17 00:00:00 2001 From: Jonathan Tapia Date: Fri, 31 Jan 2025 16:50:56 -0600 Subject: [PATCH] Fix issue refunding uncompleted payments --- .../views/spree/admin/payments/_list.html.erb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 %>