Class: Atos

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Atos

Returns a new instance of Atos.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/atos.rb', line 7

def initialize(*args)

  args.empty? ? paths = {} : paths = args.first
  
  # You may override those default paths on Class instanciation 
  paths[:root_path]     ? @root_path     = paths[:root_path]     : @root_path     = "#{Rails.root}/lib/atos"
  paths[:request_path]  ? @request_path  = paths[:request_path]  : @request_path  = "#{self.root_path}/bin/request"
  paths[:response_path] ? @response_path = paths[:response_path] : @response_path = "#{self.root_path}/bin/response"
  paths[:pathfile_path] ? @pathfile_path = paths[:pathfile_path] : @pathfile_path = "#{self.root_path}/param/pathfile"  

end

Instance Attribute Details

#pathfile_pathObject

Returns the value of attribute pathfile_path.



5
6
7
# File 'lib/atos.rb', line 5

def pathfile_path
  @pathfile_path
end

#request_pathObject

Returns the value of attribute request_path.



5
6
7
# File 'lib/atos.rb', line 5

def request_path
  @request_path
end

#response_pathObject

Returns the value of attribute response_path.



5
6
7
# File 'lib/atos.rb', line 5

def response_path
  @response_path
end

#root_pathObject

Returns the value of attribute root_path.



5
6
7
# File 'lib/atos.rb', line 5

def root_path
  @root_path
end

Instance Method Details

#request(datas) ⇒ Object

Call the request binary



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/atos.rb', line 20

def request(datas)

  ExceptionHandler.before(datas)
      
  # Default parameters if nothing given
  datas[:merchant_country] ||= "fr"                # => French shop
  datas[:language]         ||= "fr"                # => French locale
  datas[:currency_code]    ||= "978"               # => Euro
  datas[:pathfile]         ||= "#{@pathfile_path}" # => Path to the Atos "pathfile"
       
  args = ''
  datas.each do |key, value|
    args << "#{key.to_s}=#{value} "
  end        
  
  response_array = ExceptionHandler.on_launch(`#{self.request_path} #{args}`)

  # If everything goes fine, should now respond an HTML form 
  response_array[3]
  
end

#response(datas) ⇒ Object

Decrypt bank response, then return a hash



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/atos.rb', line 43

def response(datas)

  response_array = ExceptionHandler.on_launch(`#{self.response_path} pathfile=#{self.pathfile_path} message=#{datas}`)

  { 
    :code                   => response_array[1],
    :error                  => response_array[2],
    :merchant_id            => response_array[3],
    :merchant_country       => response_array[4],
    :amount                 => response_array[5],
    :transaction_id         => response_array[6],
    :payment_means          => response_array[7],
    :transmission_date      => response_array[8],
    :payment_time           => response_array[9],
    :payment_date           => response_array[10],
    :response_code          => response_array[11],
    :payment_certificate    => response_array[12],
    :authorisation_id       => response_array[13],
    :currency_code          => response_array[14],
    :card_number            => response_array[15],
    :cvv_flag               => response_array[16],
    :cvv_response_code      => response_array[17],
    :bank_response_code     => response_array[18],
    :complementary_code     => response_array[19],
    :complementary_info     => response_array[20],
    :return_context         => response_array[21],
    :caddie                 => response_array[22],
    :receipt_complement     => response_array[23],
    :merchant_language      => response_array[24],
    :language               => response_array[25],
    :customer_id            => response_array[26],
    :order_id               => response_array[27],
    :customer_email         => response_array[28],
    :customer_ip_address    => response_array[29],
    :capture_day            => response_array[30],
    :capture_mode           => response_array[31],
    :data                   => response_array[32]
  }      
  
end