mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fix: When a user fires an event (eg. capture payment), take them back to where they came from
This commit is contained in:
committed by
Rob Harrington
parent
3ff051f238
commit
c47af55bb9
@@ -1,21 +1,31 @@
|
||||
Spree::Admin::PaymentsController.class_eval do
|
||||
# When a user fires an event, take them back to where they came from
|
||||
# Responder: http://guides.spreecommerce.com/developer/logic.html#overriding-controller-action-responses
|
||||
|
||||
# For some strange reason, adding PaymentsController.class_eval will cause gems/spree/app/controllers/spree/admin/payments_controller.rb:37 to error:
|
||||
# payments_url not defined.
|
||||
# This could be fixed by replacing line 37 with:
|
||||
# respond_with(@payment, location: admin_order_payments_url) { |format| format.html { redirect_to admin_order_payments_path(@order) } }
|
||||
respond_override :fire => { :html => { :success => lambda {
|
||||
redirect_to request.referer # Keeps any filter and sort prefs
|
||||
} } }
|
||||
|
||||
append_before_filter :filter_payment_methods
|
||||
|
||||
|
||||
# When a user fires an event, take them back to where they came from
|
||||
# (we can't use respond_override because Spree no longer uses respond_with)
|
||||
def fire
|
||||
return unless event = params[:e] and @payment.payment_source
|
||||
|
||||
# Because we have a transition method also called void, we do this to avoid conflicts.
|
||||
event = "void_transaction" if event == "void"
|
||||
if @payment.send("#{event}!")
|
||||
flash[:success] = t(:payment_updated)
|
||||
else
|
||||
flash[:error] = t(:cannot_perform_operation)
|
||||
end
|
||||
rescue Spree::Core::GatewayError => ge
|
||||
flash[:error] = "#{ge.message}"
|
||||
ensure
|
||||
redirect_to request.referer
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
# Only show payments for the order's distributor
|
||||
def filter_payment_methods
|
||||
@payment_methods = @payment_methods.select{ |pm| pm.has_distributor? @order.distributor}
|
||||
@payment_method ||= @payment_methods.first
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user