mpi_client 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ module MPIClient
2
+ class OptionTranslator
3
+ OPTION_MAP = {
4
+ :merchant_id => :Id,
5
+ :site_name => :Name,
6
+ :site_url => :URL,
7
+ :certificate_subject => :IP,
8
+ :acquirer_bin => :AcquirerBIN,
9
+ :country_code => :CountryCode,
10
+ :password => :Password,
11
+ :certificate => :PublicCertificate,
12
+ :private_key => :PrivateKey,
13
+ :directory_server_url => :DirectoryServerURL,
14
+ :country_code => :CountryCode,
15
+ :brand => :CardType,
16
+ :response_url => :ResponseURL,
17
+ :client_url => :ClientURL,
18
+ :term_url => :TermURL,
19
+ :account_id => :AccountId,
20
+ :error => :Error,
21
+ :card_number => :CardNumber,
22
+ :status => :status
23
+ }
24
+
25
+ def self.to_client(option)
26
+ OPTION_MAP.invert[option]
27
+ end
28
+
29
+ def self.to_server(option)
30
+ OPTION_MAP[option]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,47 @@
1
+ module MPIClient
2
+ class Request
3
+ CLIENT_METHODS = %w(create_account get_account_info update_account delete_account verify)
4
+
5
+ def initialize
6
+ @connection = Network::Connection.new(MPIClient.server_url)
7
+ end
8
+
9
+ def method_missing(method, *args)
10
+ submit_request(method, *args) if CLIENT_METHODS.include?(method.to_s)
11
+ end
12
+
13
+ private
14
+ def submit_request(request_type, *args)
15
+ parse_response(@connection.post(prepare_request_data(request_type, *args)))
16
+ end
17
+
18
+ def prepare_request_data(request_type, options, transaction_attrs = {})
19
+ options = options.dup
20
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
21
+ xml.REQUEST(:type => request_type) do |xml|
22
+ xml.Transaction(transaction_attrs) do |xml|
23
+ options.each do |k,v|
24
+ xml.send(OptionTranslator.to_server(k), v)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ builder.to_xml
30
+ end
31
+
32
+ def parse_response(response_data)
33
+ doc = Nokogiri::XML(response_data)
34
+
35
+ if error = doc.xpath("//Error").first
36
+ response = {
37
+ :error_message => error.text,
38
+ :error_code => 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)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ module MPIClient
2
+ class Response
3
+ attr_reader :data
4
+
5
+ def initialize(data = {})
6
+ @data = data
7
+ end
8
+
9
+ def success?
10
+ error_code.nil? && error_message.nil?
11
+ end
12
+
13
+ def method_missing(method)
14
+ data[method]
15
+ end
16
+ end
17
+ end
@@ -1,4 +1,4 @@
1
- module MPI
1
+ module MPIClient
2
2
  module Verification
3
3
  class Request
4
4
  PARAMS_MAP = {
@@ -27,7 +27,7 @@ module MPI
27
27
 
28
28
  private
29
29
  def post(xml_request)
30
- Network.post(MPI.server_url, xml_request)
30
+ Network.post(MPIClient.server_url, xml_request)
31
31
  end
32
32
 
33
33
  def build_xml
@@ -1,4 +1,4 @@
1
- module MPI
1
+ module MPIClient
2
2
  module Verification
3
3
  class Response
4
4
  attr_reader :xml, :error_code, :error_message, :status, :url
@@ -0,0 +1,6 @@
1
+ module MPIClient
2
+ module Verification
3
+ autoload :Request, 'mpi_client/verification/request'
4
+ autoload :Response,'mpi_client/verification/response'
5
+ end
6
+ end
data/lib/mpi_client.rb CHANGED
@@ -3,53 +3,12 @@ require 'network'
3
3
  require 'nokogiri'
4
4
  require 'active_support/core_ext/module/attribute_accessors'
5
5
 
6
- require 'mpi'
7
-
8
- require 'mpi/option_translator'
9
- require 'mpi/response'
10
-
11
- class MPIClient
12
- CLIENT_METHODS = %w(create_account get_account_info update_account delete_account verify)
13
-
14
- def initialize(server_url)
15
- @connection = Network::Connection.new(server_url)
16
- end
17
-
18
- def method_missing(method, *args)
19
- submit_request(method, *args) if CLIENT_METHODS.include?(method.to_s)
20
- end
21
-
22
- private
23
- def submit_request(request_type, *args)
24
- parse_response(@connection.post(prepare_request_data(request_type, *args)))
25
- end
26
-
27
- def prepare_request_data(request_type, options, transaction_attrs = {})
28
- options = options.dup
29
- builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
30
- xml.REQUEST(:type => request_type) do |xml|
31
- xml.Transaction(transaction_attrs) do |xml|
32
- options.each do |k,v|
33
- xml.send(OptionTranslator.to_server(k), v)
34
- end
35
- end
36
- end
37
- end
38
- builder.to_xml
39
- end
40
-
41
- def parse_response(response_data)
42
- doc = Nokogiri::XML(response_data)
43
-
44
- if error = doc.xpath("//Error").first
45
- response = {
46
- :error_message => error.text,
47
- :error_code => error[:code]
48
- }
49
- else
50
- response = Hash[*doc.xpath("//Transaction/*").collect{|a| [OptionTranslator.to_client(a.name.to_sym), a.text] }.flatten]
51
- end
52
-
53
- MPIResponse.new(response)
54
- end
6
+ module MPIClient
7
+ mattr_accessor :server_url
8
+ self.server_url = 'http://mpi.server.com/'
9
+
10
+ autoload :OptionTranslator, 'mpi_client/option_translator'
11
+ autoload :Request, 'mpi_client/request'
12
+ autoload :Response, 'mpi_client/response'
13
+ autoload :Verification, 'mpi_client/verification'
55
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mpi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Plashchynski
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-22 00:00:00 +03:00
13
+ date: 2009-10-26 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -52,12 +52,12 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
 
54
54
  files:
55
- - lib/mpi/option_translator.rb
56
- - lib/mpi/response.rb
57
- - lib/mpi/verification/request.rb
58
- - lib/mpi/verification/response.rb
59
- - lib/mpi/verification.rb
60
- - lib/mpi.rb
55
+ - lib/mpi_client/option_translator.rb
56
+ - lib/mpi_client/request.rb
57
+ - lib/mpi_client/response.rb
58
+ - lib/mpi_client/verification/request.rb
59
+ - lib/mpi_client/verification/response.rb
60
+ - lib/mpi_client/verification.rb
61
61
  - lib/mpi_client.rb
62
62
  has_rdoc: true
63
63
  homepage: http://github.com/plashchynski/mpi_client/
@@ -1,31 +0,0 @@
1
- class OptionTranslator
2
- OPTION_MAP = {
3
- :merchant_id => :Id,
4
- :site_name => :Name,
5
- :site_url => :URL,
6
- :certificate_subject => :IP,
7
- :acquirer_bin => :AcquirerBIN,
8
- :country_code => :CountryCode,
9
- :password => :Password,
10
- :certificate => :PublicCertificate,
11
- :private_key => :PrivateKey,
12
- :directory_server_url => :DirectoryServerURL,
13
- :country_code => :CountryCode,
14
- :brand => :CardType,
15
- :response_url => :ResponseURL,
16
- :client_url => :ClientURL,
17
- :term_url => :TermURL,
18
- :account_id => :AccountId,
19
- :error => :Error,
20
- :card_number => :CardNumber,
21
- :status => :status
22
- }
23
-
24
- def self.to_client(option)
25
- OPTION_MAP.invert[option]
26
- end
27
-
28
- def self.to_server(option)
29
- OPTION_MAP[option]
30
- end
31
- end
data/lib/mpi/response.rb DELETED
@@ -1,15 +0,0 @@
1
- class MPIResponse
2
- attr_reader :data
3
-
4
- def initialize(data = {})
5
- @data = data
6
- end
7
-
8
- def success?
9
- error_code.nil? && error_message.nil?
10
- end
11
-
12
- def method_missing(method)
13
- data[method]
14
- end
15
- end
@@ -1,6 +0,0 @@
1
- module MPI
2
- module Verification
3
- autoload :Request, 'mpi/verification/request'
4
- autoload :Response,'mpi/verification/response'
5
- end
6
- end
data/lib/mpi.rb DELETED
@@ -1,6 +0,0 @@
1
- module MPI
2
- mattr_accessor :server_url
3
- self.server_url = 'http://mpi.server.com/'
4
-
5
- autoload :Verification, 'mpi/verification'
6
- end