mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Add reflex for capturing orders
This commit is contained in:
18
app/reflexes/admin/orders_reflex.rb
Normal file
18
app/reflexes/admin/orders_reflex.rb
Normal 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
|
||||
@@ -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')}
|
||||
|
||||
Reference in New Issue
Block a user