diff --git a/app/controllers/spree/admin/payments_controller_decorator.rb b/app/controllers/spree/admin/payments_controller_decorator.rb index 23db5eca09..c608f8930c 100644 --- a/app/controllers/spree/admin/payments_controller_decorator.rb +++ b/app/controllers/spree/admin/payments_controller_decorator.rb @@ -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