Class: Supercharged::GatewayNotificationsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/supercharged/gateway_notifications_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
31
32
33
34
35
36
37
38
# File 'app/controllers/supercharged/gateway_notifications_controller.rb', line 5

def create
  persistent_logger.info("Notification for #{params[:gateway]}")
  persistent_logger.info("params = #{params.inspect}")

  @notification = GatewayNotification.create!(params: params, gateway: params[:gateway], raw_post: request.raw_post)
  @notification.logger = persistent_logger

  error = if !@notification.complete?
    "not_completed"
  elsif !@notification.acknowledge
    "acknowledge_failed"
  elsif !@notification.charge
    "charge not found"
  end

  if error
    persistent_logger.error("Error: #{error.inspect}")
    if @notification.charge
      @notification.charge.failed!
      @notification.charge.update_attribute(:error, error)
    end
    head :bad_request
  else
    persistent_logger.info("Success")
    @notification.approve
    if @notification.need_response?
      persistent_logger.info("Need need_response: #{@notification.success_response.inspect}")
      render text: @notification.success_response
    else
      persistent_logger.info("Redirecting")
      redirect_to root_url
    end
  end
end

#failObject



44
45
46
# File 'app/controllers/supercharged/gateway_notifications_controller.rb', line 44

def fail
  redirect_to root_url, error: "Fail"
end

#successObject



40
41
42
# File 'app/controllers/supercharged/gateway_notifications_controller.rb', line 40

def success
  redirect_to root_url, notice: "Success"
end