mpi_client 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,6 @@ module MPIClient
9
9
  self.server_url = 'http://mpi.server.com/'
10
10
 
11
11
  autoload :OptionTranslator, 'mpi_client/option_translator'
12
- autoload :ErrorParser, 'mpi_client/error_parser'
13
12
  autoload :BaseRequest, 'mpi_client/base_request'
14
13
  autoload :Verification, 'mpi_client/verification'
15
14
  autoload :AccountManagement, 'mpi_client/account_management'
@@ -19,7 +19,7 @@ module MPIClient
19
19
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
20
20
  xml.REQUEST(:type => request_type) do |xml|
21
21
  xml.Transaction(transaction_attrs) do |xml|
22
- options.each do |k,v|
22
+ options.each do |k,v|
23
23
  xml.send(OptionTranslator.to_server(k), v)
24
24
  end
25
25
  end
@@ -29,19 +29,9 @@ module MPIClient
29
29
  end
30
30
 
31
31
  def parse_response(response_data)
32
- doc = Nokogiri::XML(response_data)
33
-
34
- if error = doc.xpath("//Error").first
35
- response = {
36
- :error_message => error.text,
37
- :error_code => error[:code],
38
- :errors => ErrorParser.parse(error.text, error[:code]),
39
- }
40
- else
41
- response = Hash[*doc.xpath("//Transaction/*").collect{|a| [OptionTranslator.to_client(a.name.to_sym), a.text] }.flatten]
42
- end
43
-
44
- Response.new(response)
32
+ response = Response.new(response_data)
33
+ response.parse
34
+ response
45
35
  end
46
36
  end
47
37
  end
@@ -1,19 +1,71 @@
1
1
  module MPIClient
2
2
  module AccountManagement
3
3
  class Response
4
- attr_reader :data
4
+ attr_reader :response_source, :error_code, :error_message, :errors, \
5
+ :merchant_id, :site_name, :site_url, :certificate_subject, \
6
+ :acquirer_bin, :country_code, :password, :certificate,
7
+ :private_key, :directory_server_url, :brand, :response_url, \
8
+ :client_url, :term_url, :account_id
5
9
 
6
- def initialize(data = {})
7
- @data = data
10
+ def initialize(response_source)
11
+ @response_source = response_source
8
12
  end
9
13
 
10
14
  def success?
11
15
  error_code.nil? && error_message.nil?
12
16
  end
13
17
 
14
- def method_missing(method)
15
- data[method]
18
+ def parse
19
+ doc = Nokogiri::XML.parse(response_source)
20
+
21
+ if error = doc.xpath("//Error").first
22
+ @error_code = error[:code]
23
+ @error_message = error.text
24
+ @errors = errors_to_hash
25
+ else
26
+ set_account_attributes doc.xpath("//Transaction/*")
27
+ end
28
+
29
+ end
30
+
31
+ private
32
+
33
+ def errors_to_hash
34
+ contain_error_fields? ? error_fields : {:base => error_message}
35
+ end
36
+
37
+ def error_fields
38
+ {}.tap do |result|
39
+ extract_messages(error_message).each do |message|
40
+ key = OptionTranslator.to_client( field_name_from(message) )
41
+ result[key.to_sym] = error_description_from(message)
42
+ end
43
+ end
44
+ end
45
+
46
+ def field_name_from(message)
47
+ message.sub(/.+\[(.+)\].+/, '\1').to_sym
16
48
  end
49
+
50
+ def error_description_from(message)
51
+ message.sub /\s\[.+?\]/, ''
52
+ end
53
+
54
+ def extract_messages(message)
55
+ message.sub(/.*\((.+)\).*/, '\1').split(/\.\s*/)
56
+ end
57
+
58
+ def contain_error_fields?
59
+ error_code == 'C5'
60
+ end
61
+
62
+ def set_account_attributes(elements)
63
+ elements.each do |element|
64
+ name = OptionTranslator.to_client(element.name.to_sym)
65
+ instance_variable_set("@#{name}".to_sym, element.text)
66
+ end
67
+ end
68
+
17
69
  end
18
70
  end
19
71
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mpi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ hash: 5
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 13
10
+ version: 0.0.13
5
11
  platform: ruby
6
12
  authors:
7
13
  - Dmitry Plashchynski
@@ -10,39 +16,57 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2010-03-09 00:00:00 +02:00
19
+ date: 2010-11-15 00:00:00 +02:00
14
20
  default_executable:
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
23
  name: nokogiri
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
21
27
  requirements:
22
28
  - - ">="
23
29
  - !ruby/object:Gem::Version
30
+ hash: 31
31
+ segments:
32
+ - 1
33
+ - 3
34
+ - 2
24
35
  version: 1.3.2
25
- version:
36
+ type: :runtime
37
+ version_requirements: *id001
26
38
  - !ruby/object:Gem::Dependency
27
39
  name: alovak-network
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
31
43
  requirements:
32
44
  - - ">="
33
45
  - !ruby/object:Gem::Version
46
+ hash: 23
47
+ segments:
48
+ - 1
49
+ - 1
50
+ - 2
34
51
  version: 1.1.2
35
- version:
52
+ type: :runtime
53
+ version_requirements: *id002
36
54
  - !ruby/object:Gem::Dependency
37
55
  name: activesupport
38
- type: :runtime
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
41
59
  requirements:
42
60
  - - ">="
43
61
  - !ruby/object:Gem::Version
62
+ hash: 7
63
+ segments:
64
+ - 2
65
+ - 3
66
+ - 2
44
67
  version: 2.3.2
45
- version:
68
+ type: :runtime
69
+ version_requirements: *id003
46
70
  description:
47
71
  email: alovak@gmail.com
48
72
  executables: []
@@ -52,16 +76,15 @@ extensions: []
52
76
  extra_rdoc_files: []
53
77
 
54
78
  files:
55
- - lib/mpi_client/option_translator.rb
79
+ - lib/mpi_client.rb
56
80
  - lib/mpi_client/base_request.rb
57
- - lib/mpi_client/account_management.rb
58
- - lib/mpi_client/account_management/request.rb
59
- - lib/mpi_client/account_management/response.rb
60
- - lib/mpi_client/error_parser.rb
61
- - lib/mpi_client/verification/request.rb
81
+ - lib/mpi_client/option_translator.rb
62
82
  - lib/mpi_client/verification/response.rb
83
+ - lib/mpi_client/verification/request.rb
84
+ - lib/mpi_client/account_management.rb
63
85
  - lib/mpi_client/verification.rb
64
- - lib/mpi_client.rb
86
+ - lib/mpi_client/account_management/response.rb
87
+ - lib/mpi_client/account_management/request.rb
65
88
  has_rdoc: true
66
89
  homepage: http://github.com/alovak/mpi_client/
67
90
  licenses: []
@@ -72,21 +95,27 @@ rdoc_options: []
72
95
  require_paths:
73
96
  - lib
74
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
75
99
  requirements:
76
100
  - - ">="
77
101
  - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
78
105
  version: "0"
79
- version:
80
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
81
108
  requirements:
82
109
  - - ">="
83
110
  - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
84
114
  version: "0"
85
- version:
86
115
  requirements: []
87
116
 
88
117
  rubyforge_project:
89
- rubygems_version: 1.3.5
118
+ rubygems_version: 1.3.7
90
119
  signing_key:
91
120
  specification_version: 3
92
121
  summary: MPI client library
@@ -1,19 +0,0 @@
1
- module MPIClient
2
- module ErrorParser
3
- def self.get_base_message(error_message, error_code)
4
- error_message[/^(.*?)(?:\ \(|$)/, 1] unless error_code == 'C5'
5
- end
6
-
7
- def self.parse(error_message, error_code)
8
- result = Hash.new
9
- base_message = get_base_message(error_message, error_code)
10
- result[:base] = base_message if base_message
11
- error_message.scan(/(?:\ |\()([A-Z].*?)\./) do |error_field, second_field|
12
- field_name = error_field[/^.*\ \[(.*)\].*$/, 1]
13
- error_str = error_field.gsub(/\ \[.*\]/,'')
14
- result[OptionTranslator.to_client(field_name.to_sym)] = error_str
15
- end
16
- result
17
- end
18
- end
19
- end