Module: Paysto::Controller

Extended by:
ActiveSupport::Concern
Included in:
PaystoController
Defined in:
lib/paysto/controller.rb

Instance Method Summary collapse

Instance Method Details

#callbackObject

Second step of payment workflow: Payment creation. Render invoice ID if everything right or anything else if not.



23
24
25
26
27
28
29
30
31
32
# File 'lib/paysto/controller.rb', line 23

def callback
  invoice = Paysto.invoice_class.find_by(id: params['PAYSTO_INVOICE_ID'])
  if invoice && invoice.need_to_be_paid?(:paysto, params['PAYSTO_REQUEST_MODE'], params['PAYSTO_SUM']) && Paysto.ip_valid?(request.remote_ip) && Paysto.md5_valid?(params)
    invoice.notify(params, :paysto)
    invoice.send("create_#{Paysto.payment_class_name.underscore}", Paysto.get_payment_type(invoice.id), 'paysto', Paysto.real_amount(params['PAYSTO_SUM']))
    render text: invoice.id
  else
    render text: I18n.t('paysto.callback.fail')
  end
end

#checkObject

First step of payment workflow: Invoice, IP and MD5 verification. Render invoice ID if everything right or anything else if not.



12
13
14
15
16
17
18
19
# File 'lib/paysto/controller.rb', line 12

def check
  invoice = Paysto.invoice_class.find_by(id: params['PAYSTO_INVOICE_ID'])
  if Paysto.invoice_valid?(invoice) && Paysto.ip_valid?(request.remote_ip) && Paysto.md5_valid?(params)
    render text: invoice.id
  else
    render text: I18n.t('paysto.check.fail')
  end
end

#failObject

Fail callback.



41
42
43
44
# File 'lib/paysto/controller.rb', line 41

def fail
  flash[:alert] = I18n.t('paysto.fail')
  redirect_to root_path
end

#successObject

Success callback.



35
36
37
38
# File 'lib/paysto/controller.rb', line 35

def success
  flash[:success] = I18n.t('paysto.success')
  redirect_to root_path
end