Class: Spree::OmnikassaPaymentsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/spree/omnikassa_payments_controller.rb

Instance Method Summary collapse

Instance Method Details

#homecomingObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/spree/omnikassa_payments_controller.rb', line 5

def homecoming
  @payment_response = payment_response_from_params(params)
  @order = @payment_response.order

  if not @payment_response.valid?
    flash[:error] = "Invalid request"
    redirect_to(root_url) and return
  end

  case @payment_response.response_level
  when :success
    flash[:info] = "Success!"
  when :pending
    flash[:info] = "Still pending. You will recieve a message"
  when :cancelled
    flash[:error] = "Order cancelled"
  when :failed
    flash[:error] = "Error occurred"
  else
    flash[:error] = "Unknown Error occurred"
  end

  session[:order_id] = nil

  redirect_to(root_url) and return
end

#replyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/spree/omnikassa_payments_controller.rb', line 32

def reply
  @payment_response = payment_response_from_params(params)
  @order = @payment_response.order
  add_payment_if_not_exists
  message = "OmnikassaPaymentResponse posted: payment: # @payment_response.payment.id}; params: #{params.inspect}"

  if @payment_response.valid?
    case @payment_response.response_level
    when :success
      Rails.logger.info message
      @payment_response.payment.complete!
      advance_order_status :complete
    when :pending
      Rails.logger.info message
      @payment_response.payment.pend!
      advance_order_status :payment
    when :cancelled
      Rails.logger.info message
      @payment_response.payment.failure!
      @payment_response.order.cancel
    when :failed
      Rails.logger.error message
      @payment_response.payment.failure!
      @payment_response.order.cancel
    else
      Rails.logger.error message
      @payment_response.payment.pend!
      @payment_response.order.cancel
    end
  else
    Rails.logger.error message
    @payment_response.payment.pend!
  end
  render :text => @payment_response.response_level.to_s
end