Add reflex for capturing orders

This commit is contained in:
Matt-Yorkley
2023-05-07 19:58:43 +01:00
parent 61849d84e7
commit e58a37f65b
2 changed files with 19 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
class Admin::OrdersReflex < ApplicationReflex
def capture
order = Spree::Order.find_by(id: element.dataset[:id])
authorize! :admin, order
payment_capture = OrderCaptureService.new(order)
if payment_capture.call
morph dom_id(order), render(partial: "spree/admin/orders/table_row",
locals: { order: order.reload, success: true })
else
flash[:error] = with_locale{ payment_capture.gateway_error || I18n.t(:payment_processing_failed) }
morph_admin_flashes
end
end
end

View File

@@ -45,4 +45,4 @@
- if order.ready_to_ship?
%button.icon-road.icon_link.with-tip.no-text{rel: 'nofollow', 'ofn-with-tip' => t('spree.admin.orders.index.ship')}
- if order.payment_required? && order.pending_payments.reject(&:requires_authorization?).any?
%button.icon-capture.icon_link.no-text{rel: 'nofollow', 'ofn-with-tip' => t('spree.admin.orders.index.capture')}
%button.icon-capture.icon_link.no-text{"data-reflex": "click->Admin::OrdersReflex#capture", "data-id": order.id.to_s, 'ofn-with-tip' => t('spree.admin.orders.index.capture')}