mpi_client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ class OptionTranslator
10
10
  :certificate => :PublicCertificate,
11
11
  :private_key => :PrivateKey,
12
12
  :directory_server_url => :DirectoryServerURL,
13
+ :country_code => :CountryCode,
13
14
  :brand => :CardType,
14
15
  :response_url => :ResponseURL,
15
16
  :client_url => :ClientURL,
File without changes
@@ -0,0 +1,48 @@
1
+ module MPI
2
+ module Verification
3
+ class Request
4
+ PARAMS_MAP = {
5
+ 'AccountId' => :account_id,
6
+ 'Amount' => :amount, #in cents
7
+ 'CardNumber' => :card_number,
8
+ 'Description' => :description,
9
+ 'DisplayAmount' => :display_amount,
10
+ 'CurrencyCode' => :currency,
11
+ 'ExpY' => :exp_year,
12
+ 'ExpM' => :exp_month,
13
+ 'URL' => :termination_url,
14
+ }
15
+
16
+ REQUEST_TYPE = 'vereq'
17
+
18
+ attr_reader :options, :transaction_id
19
+
20
+ def initialize(options, transaction_id)
21
+ @options, @transaction_id = options, transaction_id
22
+ end
23
+
24
+ def process
25
+ Response.parse(post(build_xml))
26
+ end
27
+
28
+ private
29
+ def post(xml_request)
30
+ Network.post(MPI.server_url, xml_request)
31
+ end
32
+
33
+ def build_xml
34
+ xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8')
35
+
36
+ xml.REQUEST(:type => REQUEST_TYPE) do |xml|
37
+ xml.Transaction(:id => transaction_id) do |xml|
38
+ PARAMS_MAP.each_pair do |key, value|
39
+ xml.send(key, options[value])
40
+ end
41
+ end
42
+ end
43
+
44
+ xml.to_xml
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
1
+ module MPI
2
+ module Verification
3
+ class Response
4
+ attr_reader :xml, :error_code, :error_message, :status, :url
5
+
6
+ def initialize(xml)
7
+ @xml = xml
8
+ end
9
+
10
+ def successful?
11
+ !(error_message || error_code)
12
+ end
13
+
14
+ def parse
15
+ doc = Nokogiri::XML(xml)
16
+
17
+ unless (doc.xpath("//Transaction")).empty?
18
+ @status = doc.xpath("//Transaction").attr('status')
19
+ @url = doc.xpath("//Transaction/URL").text
20
+ else
21
+ get_error(doc)
22
+ end
23
+ end
24
+
25
+
26
+ def self.parse(xml)
27
+ response = self.new(xml)
28
+ response.parse
29
+ response
30
+ end
31
+
32
+ private
33
+ def get_error(doc)
34
+ unless (error = doc.xpath("//Error")).empty?
35
+ @error_message = error.text
36
+ @error_code = error.attr('code')
37
+ else
38
+ @error_message = 'Unknown response was received from MPI'
39
+ @error_code = ''
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,6 @@
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 ADDED
@@ -0,0 +1,6 @@
1
+ module MPI
2
+ mattr_accessor :server_url
3
+ self.server_url = 'http://mpi.server.com/'
4
+
5
+ autoload :Verification, 'mpi/verification'
6
+ end
data/lib/mpi_client.rb CHANGED
@@ -1,14 +1,15 @@
1
1
  require 'rubygems'
2
2
  require 'network'
3
3
  require 'nokogiri'
4
+ require 'active_support/core_ext/module/attribute_accessors'
4
5
 
5
- $:.unshift File.dirname(__FILE__)
6
+ require 'mpi'
6
7
 
7
- require 'mpi_client/option_translator'
8
- require 'mpi_client/mpi_response'
8
+ require 'mpi/option_translator'
9
+ require 'mpi/response'
9
10
 
10
11
  class MPIClient
11
- CLIENT_METHODS = %w(create_account get_account_info update_account delete_account enrolled)
12
+ CLIENT_METHODS = %w(create_account get_account_info update_account delete_account verify)
12
13
 
13
14
  def initialize(server_url)
14
15
  @connection = Network::Connection.new(server_url)
@@ -28,11 +29,12 @@ class MPIClient
28
29
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
29
30
  xml.REQUEST(:type => request_type) do |xml|
30
31
  xml.Transaction(transaction_attrs) do |xml|
31
- options.each { |k,v| xml.send(OptionTranslator.to_server(k), v) }
32
+ options.each do |k,v|
33
+ xml.send(OptionTranslator.to_server(k), v)
34
+ end
32
35
  end
33
36
  end
34
37
  end
35
-
36
38
  builder.to_xml
37
39
  end
38
40
 
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.3
4
+ version: 0.0.4
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-15 00:00:00 +03:00
13
+ date: 2009-10-22 00:00:00 +03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -33,6 +33,16 @@ dependencies:
33
33
  - !ruby/object:Gem::Version
34
34
  version: 1.1.2
35
35
  version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: activesupport
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.3.2
45
+ version:
36
46
  description:
37
47
  email: plashchynski@gmail.com
38
48
  executables: []
@@ -42,13 +52,13 @@ extensions: []
42
52
  extra_rdoc_files: []
43
53
 
44
54
  files:
45
- - lib/mpi_client/mpi_response.rb
46
- - lib/mpi_client/option_translator.rb
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
47
61
  - lib/mpi_client.rb
48
- - remote_spec/mpi_client_spec.rb
49
- - spec/mpi_client_spec.rb
50
- - spec/mpi_response_spec.rb
51
- - spec/option_translator_spec.rb
52
62
  has_rdoc: true
53
63
  homepage: http://github.com/plashchynski/mpi_client/
54
64
  licenses: []
@@ -73,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
83
  requirements: []
74
84
 
75
85
  rubyforge_project:
76
- rubygems_version: 1.3.5
86
+ rubygems_version: 1.3.4
77
87
  signing_key:
78
88
  specification_version: 3
79
89
  summary: MPI client library
@@ -1,49 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/mpi_client.rb'
2
-
3
- MPI_SERVER_URL = 'http://192.168.65.11/xml'
4
-
5
- describe "MPIClient requests" do
6
- before(:each) do
7
- @mpi_client = MPIClient.new(MPI_SERVER_URL)
8
- end
9
-
10
- it "should create account, update, get_info and delete" do
11
- options = {
12
- :id => 'some id',
13
- :site_name => 'site name',
14
- :url => 'http://siteurl/',
15
- :cert_subject => '*',
16
- :acquirer_bin => '3213',
17
- :country_code => '432',
18
- :password => 'qwerty',
19
- :directory_server_url => 'http://www.visa.com/ds/',
20
- :brand => '1',
21
- :response_url => 'http://www.response.com/gk/',
22
- :client_url => 'http://www.client.com/',
23
- :term_url => 'http://www.term.com/',
24
- }
25
-
26
- account_id = @mpi_client.create_account(options).account_id
27
-
28
- options.merge!({:account_id => account_id, :site_name => 'new_site_name'})
29
-
30
- @mpi_client.update_account(options).account_id.should == account_id
31
- @mpi_client.get_account_info({ :account_id => account_id }).site_name.should == options[:site_name]
32
- @mpi_client.delete_account({ :account_id => account_id }).account_id.should == account_id
33
- end
34
-
35
- describe "card enrollment check" do
36
- it "should return Y if card is enrolled" do
37
- enrollment_response('4012001037141112').status.should == 'Y'
38
- end
39
-
40
- it "should return N if card isn't enrolled" do
41
- enrollment_response('4012001038443335').status.should == 'N'
42
- end
43
-
44
- def enrollment_response(card_number)
45
- @mpi_client.enrolled({:account_id=> '0'*32, :card_number=> card_number})
46
- end
47
- end
48
-
49
- end
@@ -1,66 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/mpi_client.rb'
2
-
3
- describe "MPIClient" do
4
- before(:each) do
5
- @client = MPIClient.new('http://127.0.0.1/3ds/')
6
- end
7
-
8
- describe "requests" do
9
- it "should call submit_request and return it's result" do
10
- response = MPIResponse.new({:account_id => 'b1adc7af83a302be94891cf17014c98a'})
11
- options = mock
12
- @client.should_receive(:submit_request).with(:create_account, options).and_return(response)
13
- @client.create_account(options).should == response
14
- end
15
- end
16
-
17
- it "should prepare request data from request_type and options" do
18
- options = { :merchant_id => 'one', :account_id => 'account id' }
19
- request_type = :some_type
20
- result = @client.send(:prepare_request_data, request_type, options)
21
- result.should match %r{<REQUEST type="#{request_type}">}
22
-
23
- options.each do |k,v|
24
- key = OptionTranslator.to_server(k)
25
- result.should match %r{<#{key}>#{v}</#{key}>}
26
- end
27
- end
28
-
29
- it "should prepare transaction attributes" do
30
- id = 10
31
- result = @client.send(:prepare_request_data, 'any', {}, {:id => id} )
32
- result.should match %r{<Transaction id="#{id}".?>}
33
- end
34
-
35
- it "should parse input XML to MPIResponse and convert keys to client format" do
36
- response = <<-RESPONSE
37
- <REQUEST type=\"update_account\">
38
- <Transaction>
39
- <AccountId>9933fab999fd3fd0651df2c73bd6f12e</AccountId>
40
- <Id>231</Id>
41
- </Transaction>
42
- </REQUEST>
43
- RESPONSE
44
-
45
- result = @client.send(:parse_response, response)
46
-
47
- result.data.should == {
48
- :account_id => '9933fab999fd3fd0651df2c73bd6f12e',
49
- :merchant_id => '231'
50
- }
51
- result.should be_success
52
- end
53
-
54
- it "should return not success response, when response data contain Error field." do
55
- response = <<-RESPONSE
56
- <REQUEST type=\"update_account\">
57
- <Error code="C2">Format XML-request is not valid</Error>
58
- </REQUEST>
59
- RESPONSE
60
-
61
- result = @client.send(:parse_response, response)
62
- result.should_not be_success
63
- result.error_message.should == 'Format XML-request is not valid'
64
- result.error_code.should == 'C2'
65
- end
66
- end
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/mpi_client.rb'
2
-
3
- describe "MPIResponse" do
4
- it "should contain data" do
5
- response_data = {:a => 1, :b => 2}
6
- MPIResponse.new(response_data).data.should == response_data
7
- end
8
-
9
- describe "automatic accessors" do
10
- it "should return 'data' hash value" do
11
- response = MPIResponse.new({:status => 'Y'})
12
- response.status.should == response.data[:status]
13
- end
14
-
15
- it "should return nil if there is no value in 'data' hash" do
16
- response = MPIResponse.new()
17
- response.status.should be_nil
18
- end
19
- end
20
-
21
- describe "success?" do
22
- it "should be true if error code and error message is nil" do
23
- MPIResponse.new.should be_success
24
- end
25
-
26
- it "should be false if error code or error message not nil" do
27
- response = MPIResponse.new(:error_code => "C3", :error_message => 'Somthing went wrong.')
28
- response.should_not be_success
29
- end
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/mpi_client.rb'
2
-
3
- describe "OptionTranslator" do
4
- it "should translate options" do
5
- { :merchant_id => :Id,
6
- :site_name => :Name,
7
- :site_url => :URL,
8
- :certificate_subject => :IP,
9
- :acquirer_bin => :AcquirerBIN,
10
- :country_code => :CountryCode,
11
- :password => :Password,
12
- :certificate => :PublicCertificate,
13
- :private_key => :PrivateKey,
14
- :directory_server_url => :DirectoryServerURL,
15
- :brand => :CardType,
16
- :response_url => :ResponseURL,
17
- :client_url => :ClientURL,
18
- :term_url => :TermURL,
19
- :account_id => :AccountId
20
- }.each do |client_option, server_option|
21
- OptionTranslator.to_client(server_option).should == client_option
22
- OptionTranslator.to_server(client_option).should == server_option
23
- end
24
- end
25
- end