2013-09-05 3 views
2

мне нужно переопределить метод rescue_from_spree_gateway_error от контроллера checkout_controller.rbSpree - Переопределить методы checkout_controller

Моего шлюз возвращает это:

Gateway Error --- !ruby/object:ActiveMerchant::Billing::Response params: success: false order_status: message: Autoriza��o negada amount: order: transaction: message: Autoriza��o negada success: false test: false authorization: fraud_review: avs_result: code: message: street_match: postal_match: cvv_result: code: message: 


Это мое переопределение, в /app/controllers/checkout_controller_decorator.rb

module Spree 
    CheckoutController.class_eval do 
    def rescue_from_spree_gateway_error(error) 
     puts "===========================================" 
     flash[:error] = error.message 
     render :edit 
    end 
    end 
end 


Я добавил puts, чтобы я мог Это было на консоли, но оно не было напечатано.


Я также добавил еще puts над объявлением метода и он печатает, когда я запустить сервер:

=> Booting WEBrick 
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000 
=> Call with -d to detach 
=> Ctrl-C to shutdown server 
!!!!!THIS IS ABOVE THE METHOD!!!!! [2013-09-05 16:33:31] INFO WEBrick 1.3.1 [2013-09-05 16:33:31] INFO ruby 1.9.3 (2013-06-27) [x86_64-linux] [2013-09-05 16:33:31] INFO WEBrick::HTTPServer#start: pid=21635 port=3000 


Так он показывает мне, что загружен класс, но метод никогда не вызывается как ошибка, возвращенная выше ActiveMerchant::Billing::Response, не является ошибкой шлюза.


checkout_controller имеет эту линию, вызывая метод, когда GatewayError происходит:

rescue_from Spree::Core::GatewayError, :with => :rescue_from_spree_gateway_error 
+0

Может быть, это потому, что метод в ядре без аргументов и ваш имеет Arg? – zrl3dx

+0

Я действительно не знаю, я следил за одним предложением от пользователя в группе писем: https://groups.google.com/forum/#!topic/spree-user/rRcIoDs-9Dc – Gerep

+0

@ zrl3dx Я просто попробовал он удалил аргумент и закодировал сообщение «flash [: error] =« Не авторизован », ничего не произошло =/ – Gerep

ответ

3

Версия Spree 2.0.3.

Чтобы сделать эту работу, мне пришлось отменить два файла, создавая их по адресу:

app/controllers/checkout_controller_decorator.rb

app/models/order_decorator.rb

checkout_controller_decorator.rb код:

module Spree 
    CheckoutController.class_eval do 
    def update 
     if @order.update_attributes(object_params) 
     fire_event('spree.checkout.update') 
     return if after_update_attributes 
     unless @order.next 
      flash[:error] = @order.errors[:base].join("\n") 
      redirect_to checkout_state_path(@order.state) and return 
     end 
     if @order.completed? 
      session[:order_id] = nil 
      flash.notice = Spree.t(:order_processed_successfully) 
      flash[:commerce_tracking] = "nothing special" 
      redirect_to completion_route 
     else 
      redirect_to checkout_state_path(@order.state) 
     end 
     else 
     render :edit 
     end 
    end 
    end 
end 

И order_decorator.rb код:

module Spree 
    Order.class_eval do 

    def process_payments! 
     if pending_payments.empty? 
     raise Core::GatewayError.new Spree.t(:no_pending_payments) 
     else 
     pending_payments.each do |payment| 
      break if payment_total >= total 

      payment.process! 

      if payment.completed? 
      self.payment_total += payment.amount 
      end 
     end 
     end 
     rescue Core::GatewayError => e 
     result = !!Spree::Config[:allow_checkout_on_gateway_error] 
     errors.add(:base, e.message) and return result 
     end 
    end 
    end 
end 

Проблема с версией 2.0.3, так что я должен был обновить эти два файла с теми, от версии 2.0.4 и проблема решена =)