Class: PaymentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/payments_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_terminal

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/payments_controller.rb', line 14

def create
  payment = Payment.build!(@terminal, Provider.find_by_keyword(params[:provider].to_s), params[:payment])

  if payment
    payment.check!

    render :json => {
      :id               => payment.id,
      :state            => payment.state,
      :requires_print   => payment.provider.requires_print,
      :limits           => Limit.for(payment, false).as_json(
                              :only => [:min, :max], :methods => [:weight]
                           ),
      :commissions      => Commission.for(payment, false).as_json(
                              :only => [:min, :max, :percent_fee, :static_fee, :payment_type],
                              :methods => [:weight]
                           ),
      :receipt_template => ProviderReceiptTemplate.for(payment).compile(payment)
    }
  else
    render :text => nil, :status => 406
  end
end

#enqueueObject



55
56
57
58
59
60
# File 'app/controllers/payments_controller.rb', line 55

def enqueue
  payment = @terminal.payments.find(params[:id])
  payment.enqueue!(params[:payment]) unless payment.queue?

  render :text => nil, :status => 200
end

#limitsObject



5
6
7
8
9
10
11
12
# File 'app/controllers/payments_controller.rb', line 5

def limits
  provider = Provider.find_by_keyword params[:provider]

  render :json => provider.limits.actual.
                    by_terminal_profile_and_agent_ids(@terminal.terminal_profile_id, @terminal.agent_id).
                    by_payment_type(params[:payment_type]).
                    as_json(:only => [:min, :max], :methods => [:weight])
end

#offlineObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/payments_controller.rb', line 38

def offline
  params[:payment].merge! :offline => true

  payment = Payment.build!(@terminal, Provider.find_by_keyword(params[:provider]), params[:payment])
  payment.check!
  payment.enqueue! if payment.checked?

  render_payment payment
end

#payObject



48
49
50
51
52
53
# File 'app/controllers/payments_controller.rb', line 48

def pay
  payment = @terminal.payments.find(params[:id])
  payment.pay!(params[:payment])

  render_payment payment
end

#showObject



62
63
64
65
66
# File 'app/controllers/payments_controller.rb', line 62

def show
  payment = @terminal.payments.find(params[:id])

  render_payment payment
end