class FlyAdmin::ConnectionApi

Public Class Methods

check_user(user) click to toggle source
# File lib/fly_admin/bornpay/connection_api.rb, line 4
def self.check_user(user)
  valid = true
  begin
    api_url = SiteConfig['wap_click_addr'] + "/api/check"
    api_url = 'http://0.0.0.0:3000/api/check' if Rails.env.eql? 'development'
    request = RestClient.get(api_url, :params => {:pass => user.customer_key})
    hash = JSON.parse request
    hash = hash.with_indifferent_access
    VALIDATION_LOG.info "status for user #{user.id}: #{hash.inspect}"
    valid = false unless hash[:status].eql? true
  rescue Exception => e
    VALIDATION_LOG.error "error check status for user #{user.id}: #{e.message}"
  end
  valid
end
get_customer_params(params, request) click to toggle source
# File lib/fly_admin/bornpay/connection_api.rb, line 20
def self.get_customer_params(params, request)
 if ENV["RAILS_ENV"] == 'test' || ENV['TEST'].present? || Rails.env.eql?('test')
    { key: 'fun_key', alias: 'imbs_domain.com', action_type: 'wap', 'status' => 'ok', country: 'az'}
 else
    url = SiteConfig['wap_click_addr'] + '/api/handle_customer'
    request_params = self.make_customer_request_params(request, params)
    if ENV['TEST']
      request_params[:remote_addr] = '83.149.9.19'
    end
    API_LOG.info "HTTP_USER_AGENT: #{request.env['HTTP_USER_AGENT']}"
    API_LOG.info "URL TO IMBS: #{url}?#{request_params.to_query}"
    begin
      response = RestClient.get(url, :params => request_params)
      API_LOG.info "RESPONSE FROM IMBS: #{response.inspect}"
      out_hash = JSON.parse(response)
      out_hash.with_indifferent_access
    rescue
      API_LOG.error "response: #{response.inspect}"
      {status: 'error'}
    end
 end
end
make_customer_request_params(request, params) click to toggle source
# File lib/fly_admin/bornpay/connection_api.rb, line 43
def self.make_customer_request_params(request, params)
  p = {}
  p[:customer_key] = params[:key]
  p[:sid]         = params[:sid]
  if p[:customer_key].blank?
    p[:remote_addr] = request.env['REMOTE_ADDR']
    p[:x_forwarded_for] = request.env['HTTP_X_FORWARDED_FOR']
  end
  p[:service_code] = SiteConfig['wc_service_code']

  p = p.delete_if { |k,v| v.blank? }

  concat =  p[:customer_key].to_s + p[:sid].to_s + p[:remote_addr].to_s + p[:x_forwarded_for].to_s + p[:service_code].to_s + SiteConfig['wc_service_salt'].to_s
  p[:hash] = Digest::MD5.hexdigest(concat)
  p
end