Class: Gateway::RobokassaController

Inherits:
Spree::BaseController
  • Object
show all
Defined in:
app/controllers/gateway/robokassa_controller.rb

Instance Method Summary collapse

Instance Method Details

#failObject



47
48
49
50
# File 'app/controllers/gateway/robokassa_controller.rb', line 47

def fail
  flash[:error] = t("payment_fail")
  redirect_to @order.blank? ? root_url : checkout_state_path("payment")
end

#resultObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/gateway/robokassa_controller.rb', line 21

def result
  if @order && @gateway && valid_signature?(@gateway.options[:password2])
    payment = @order.payments.build(:payment_method => @order.payment_method)
    payment.state = "completed"
    payment.amount = params["OutSum"].to_f
    payment.save
    @order.save!
    @order.next! until @order.state == "complete"
    @order.update!
    
    render :text => "OK#{@order.id}"
  else
    render :text => "Invalid Signature"
  end
end

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/gateway/robokassa_controller.rb', line 6

def show
  @order =  Order.find(params[:order_id])
  @gateway = @order.available_payment_methods.find{|x| x.id == params[:gateway_id].to_i }

  if @order.blank? || @gateway.blank?
    flash[:error] = I18n.t("invalid_arguments")
    redirect_to :back
  else
    @signature =  Digest::MD5.hexdigest([ @gateway.options[:mrch_login],
                                          @order.total, @order.id, @gateway.options[:password1]
                                        ].join(':')).upcase
    render :action => :show
  end
end

#successObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/gateway/robokassa_controller.rb', line 37

def success
  if @order && @gateway && valid_signature?(@gateway.options[:password1]) && @order.complete?
    session[:order_id] = nil
    redirect_to order_path(@order), :notice => I18n.t("payment_success")
  else
    flash[:error] =  t("payment_fail")
    redirect_to root_url
  end
end