Class: Poli::POLi

Inherits:
Object
  • Object
show all
Defined in:
lib/poli/poli.rb

Class Method Summary collapse

Class Method Details

.get_financialInstitutionsObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/poli/poli.rb', line 31

def get_financialInstitutions
  body = build_financialInstitutions_xml
  response = HTTParty.post @settings['get_financial_institutions'], :body => body, :headers => {'Content-type' => 'text/xml'}
  institutions = response.parsed_response["GetFinancialInstitutionsResponse"]
  banks = []
  if institutions and institutions["FinancialInstitutionList"] and institutions["FinancialInstitutionList"]["FinancialInstitution"]
    institutions["FinancialInstitutionList"]["FinancialInstitution"].each do |institute|
      banks << institute["FinancialInstitutionName"]
    end
  end
  banks
end

.get_transaction(token) ⇒ Object



51
52
53
54
55
56
# File 'lib/poli/poli.rb', line 51

def get_transaction(token)
  body = build_transaction_xml(token)
  response = HTTParty.post @settings['get_transaction'], :body => body, :headers => {'Content-type' => 'text/xml'}
  poli_transaction = response.parsed_response["GetTransactionResponse"]
  return [poli_transaction["Errors"], poli_transaction["TransactionStatusCode"], poli_transaction["Transaction"]] if poli_transaction
end

.initiate_transaction(amount, merchant_ref, ip) ⇒ Object



44
45
46
47
48
49
# File 'lib/poli/poli.rb', line 44

def initiate_transaction(amount, merchant_ref, ip)
  body = build_initiate_xml(amount, merchant_ref, ip)
  response = HTTParty.post @settings['initiate_transaction'], :body => body, :headers => {'Content-type' => 'text/xml'}
  poli_transfer = response.parsed_response["InitiateTransactionResponse"]
  poli_transfer["Transaction"] if poli_transfer
end

.load_config(config_file = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/poli/poli.rb', line 10

def load_config(config_file = nil)
  unless config_file
    if defined? Rails
      config_file = "#{Rails.root}/config/poli.yml"
    else
      config_file = File.join(Dir.pwd, 'config/poli.yml')
      unless File.file?(config_file)
        config_file = File.join(Dir.pwd, 'poli.yml')
      end
    end
    raise "poli.yml not found, generate one with 'poli generate [path]'." unless File.file?(config_file)
  end

  @settings = YAML.load_file(config_file)
  @settings = (defined? Rails) ? @settings[Rails.env] : @settings["defaults"]
end

.settingsObject



27
28
29
# File 'lib/poli/poli.rb', line 27

def settings
  @settings.dup
end