wirecardmapper 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ module WirecardMapper
2
2
  module Config
3
3
 
4
4
  class << self
5
- attr_accessor :mode, :entity_id, :server_uri, :login, :password
5
+ attr_accessor :mode, :entity_id, :server_uri, :login, :password, :product_id
6
6
  attr_writer :templates_path, :server_port
7
7
  end
8
8
 
@@ -1,3 +1,3 @@
1
1
  module WirecardMapper
2
- Version = '0.6.0'
2
+ Version = '0.7.0'
3
3
  end
@@ -1,38 +1,43 @@
1
1
  module WirecardMapper
2
2
  module Xml
3
- module InstanceMethods
4
-
5
- def main_xml
6
- xml = open_xml('main.xml')
7
- if xml
8
- xml.at_css("issuer-request")['mode'] = Config.mode
9
- xml.at_css("request-id").content = request_id
10
- xml.at_css("entity-id").content = Config.entity_id
11
- end
12
- return xml
3
+
4
+ def main_xml
5
+ xml = open_xml('main.xml')
6
+ if xml
7
+ xml.at_css("issuer-request")['mode'] = Config.mode
8
+ xml.at_css("request-id").content = request_id
9
+ xml.at_css("entity-id").content = Config.entity_id
13
10
  end
11
+ return xml
12
+ end
14
13
 
15
- def sub_xml(name)
16
- xml = open_xml(name)
17
- xml.at_css("card-id").content = self.card_id if xml.at_css("card-id")
18
- xml.at_css("product-id").content = self.number if xml.at_css("product-id")
19
- xml.at_css("amount").content = self.amount if xml.at_css("amount")
20
- yield xml
14
+ def sub_xml(name, params)
15
+ xml = open_xml(name)
16
+ xml.at_css("product-id").content = Config.product_id if xml.at_css("product-id")
17
+ params.each do |param, value|
18
+ if xml.at_css(param.to_s.gsub(/_/,'-'))
19
+ if value.kind_of?(Time)
20
+ xml.at_css(param.to_s.gsub(/_/,'-')).content = value.iso8601
21
+ else
22
+ xml.at_css(param.to_s.gsub(/_/,'-')).content = value
23
+ end
24
+ end
21
25
  end
26
+ yield xml
27
+ end
22
28
 
23
- private
29
+ private
24
30
 
25
- def request_id
26
- UUID.generate
27
- end
31
+ def request_id
32
+ UUID.generate
33
+ end
28
34
 
29
- def open_xml(file_name)
30
- xml_file = File.open(File.join(Config.templates_path, file_name))
31
- if xml_file
32
- return Nokogiri::XML(xml_file)
33
- end
35
+ def open_xml(file_name)
36
+ xml_file = File.open(File.join(Config.templates_path, file_name))
37
+ if xml_file
38
+ return Nokogiri::XML(xml_file)
34
39
  end
35
-
36
40
  end
41
+
37
42
  end
38
43
  end
@@ -9,21 +9,60 @@ require 'uuid'
9
9
  require 'wirecardmapper/net_http_monkeypatch'
10
10
 
11
11
  module WirecardMapper
12
- autoload :Plugins, 'wirecardmapper/plugins'
13
12
  autoload :Config, 'wirecardmapper/config'
14
-
15
13
  autoload :Xml, 'wirecardmapper/xml'
16
14
  autoload :Response, 'wirecardmapper/response'
17
- autoload :Request, 'wirecardmapper/request'
18
- autoload :Model, 'wirecardmapper/model'
19
15
 
20
- def self.included(model)
21
- model.class_eval do
22
- extend Plugins
16
+ extend Xml
23
17
 
24
- plugin WirecardMapper::Xml
25
- plugin WirecardMapper::Request
26
- plugin WirecardMapper::Model
18
+ def self.create_card(params = {})
19
+ request("create_card", params)
20
+ end
21
+
22
+ def self.update_card_info(params = {})
23
+ request("update_card_info", params)
24
+ end
25
+
26
+ def self.card_info(params = {})
27
+ request("get_card_info", params)
28
+ end
29
+
30
+ def self.submit_payment(params = {})
31
+ request("submit_payment", params)
32
+ end
33
+
34
+ def self.payment_info(params = {})
35
+ request("get_payment_info", params)
36
+ end
37
+
38
+ def self.request(xml_request_name, params)
39
+ main_xml = self.main_xml
40
+ if main_xml
41
+ sub_xml("#{xml_request_name}.xml", params) do |xml|
42
+ main_xml.at_css('issuer-request').add_child(xml.at(xml_request_name.to_s.gsub(/_/,'-')))
43
+ end
44
+ end
45
+ return post(main_xml.to_s)
46
+ end
47
+
48
+ def self.post(xml)
49
+ uri = URI.parse(Config.server_uri)
50
+ unless uri.nil?
51
+ http = Net::HTTP.new(uri.host, Config.server_port)
52
+ if http
53
+ http.use_ssl = true
54
+ request = Net::HTTP::Post.new(uri.path)
55
+ if request
56
+ request.content_type = "text/xml"
57
+ request.content_length = xml.size
58
+ request.basic_auth(Config.login, Config.password)
59
+ request.body = xml
60
+ response = http.request(request)
61
+ if response
62
+ return WirecardMapper::Response.new(response.body)
63
+ end
64
+ end
65
+ end
27
66
  end
28
67
  end
29
- end
68
+ end
@@ -1,13 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Model" do
4
-
5
- before(:each) do
6
- @card = Card.new
7
- end
3
+ describe 'Request' do
8
4
 
9
5
  it "should get cardinfo" do
10
- response = @card.get_card_info
6
+ response = WirecardMapper.card_info(:card_id => '47ae07020a010018157db66065da6e5c')
11
7
  response.ok?.should be_true
12
8
  response.card_id.should eql('47ae07020a010018157db66065da6e5c')
13
9
  response.card_number.should eql(5274569796581777)
@@ -15,7 +11,7 @@ describe "Model" do
15
11
  end
16
12
 
17
13
  it "should create card" do
18
- response = @card.create_card
14
+ response = WirecardMapper.create_card
19
15
  response.ok?.should be_true
20
16
  response.card_id.should_not be_empty
21
17
  response.card_number.should_not be_nil
@@ -24,24 +20,32 @@ describe "Model" do
24
20
  end
25
21
 
26
22
  it "should update card info" do
27
- response = @card.update_card_info
23
+ response = WirecardMapper.update_card_info(:card_id => '47ae07020a010018157db66065da6e5c')
28
24
  response.ok?.should be_true
29
25
  response.return_code.to_i.should eql(0)
30
26
  response.return_message.should eql('Successful system entry.')
31
27
  end
32
28
 
33
- it "should submit payment" do
34
- response = @card.submit_payment
29
+ it "should submit payment load" do
30
+ response = WirecardMapper.submit_payment(:card_id => '47ae07020a010018157db66065da6e5c', :amount => 10, :payment_comment => "Test Comment")
35
31
  response.ok?.should be_true
36
32
  response.return_code.to_i.should eql(0)
37
33
  response.return_message.should eql('Successful system entry.')
38
34
  end
39
35
 
40
- it "should get payment info" do
41
- response = @card.get_payment_info(Time.now - (24 * 3600), Time.now)
36
+ it "should submit payment unload" do
37
+ response = WirecardMapper.submit_payment(:card_id => '47ae07020a010018157db66065da6e5c', :amount => -10, :payment_comment => "Test Comment")
42
38
  response.ok?.should be_true
43
39
  response.return_code.to_i.should eql(0)
44
40
  response.return_message.should eql('Successful system entry.')
45
41
  end
46
42
 
43
+ it "should get payment info" do
44
+ response = WirecardMapper.payment_info(:card_id => '47ae07020a010018157db66065da6e5c', :from => Time.now - (24 * 3600), :to => Time.now)
45
+ response.ok?.should be_true
46
+ response.return_code.to_i.should eql(0)
47
+ response.return_message.should eql('Successful system entry.')
48
+ end
49
+
47
50
  end
51
+
data/spec/spec_helper.rb CHANGED
@@ -5,38 +5,14 @@ require 'wirecardmapper'
5
5
 
6
6
  FIXTURES_PATH = "#{File.dirname(__FILE__)}/fixtures"
7
7
 
8
- def klass(name=nil, &block)
9
- klass = Class.new do
10
- include WirecardMapper
11
-
12
- def card_id
13
- '47ae07020a010018157db66065da6e5c'
14
- end
15
-
16
- def number
17
- 11
18
- end
19
-
20
- def amount
21
- 10
22
- end
23
- end
24
-
25
- klass.class_eval(&block) if block_given?
26
- klass
27
- end
28
-
29
8
  WirecardMapper::Config.server_uri = "http://localhost/issuer/client"
30
9
  WirecardMapper::Config.server_port = 8080
31
10
  WirecardMapper::Config.login = "000000315ED21E8A";
32
11
  WirecardMapper::Config.password = "FDJqLhoRX";
33
12
  WirecardMapper::Config.mode = "test"
34
13
  WirecardMapper::Config.entity_id = "000000315ED21F74"
14
+ WirecardMapper::Config.product_id = 11
35
15
 
36
16
  RSpec.configure do |config|
37
17
 
38
- config.before(:suite) do
39
- Card = klass
40
- end
41
-
42
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wirecardmapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Klaiber
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-18 00:00:00 +01:00
18
+ date: 2010-12-02 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -64,19 +64,15 @@ files:
64
64
  - README.rdoc
65
65
  - Rakefile
66
66
  - lib/wirecardmapper.rb
67
- - lib/wirecardmapper/plugins.rb
68
67
  - lib/wirecardmapper/version.rb
69
68
  - lib/wirecardmapper/net_http_monkeypatch.rb
70
- - lib/wirecardmapper/request.rb
71
- - lib/wirecardmapper/model.rb
72
69
  - lib/wirecardmapper/xml.rb
73
70
  - lib/wirecardmapper/config.rb
74
71
  - lib/wirecardmapper/response.rb
75
72
  - spec/fixtures/create_card.xml
76
73
  - spec/unit/response_spec.rb
77
- - spec/unit/xml_spec.rb
78
74
  - spec/spec_helper.rb
79
- - spec/functional/model_spec.rb
75
+ - spec/functional/request_spec.rb
80
76
  - templates/get_card_info.xml
81
77
  - templates/create_card.xml
82
78
  - templates/update_card_info.xml
@@ -1,45 +0,0 @@
1
- module WirecardMapper
2
- module Model
3
- module InstanceMethods
4
-
5
- def self.xml_request_method(*args)
6
- args.each do |arg|
7
- define_method(arg) do
8
- request(self.send("#{arg}_xml").to_s)
9
- end
10
-
11
- define_method("#{arg}_xml") do
12
- main_xml = self.main_xml
13
- if main_xml
14
- sub_xml("#{arg}.xml") do |xml|
15
- main_xml.at_css('issuer-request').add_child(xml.at(arg.to_s.gsub(/_/,'-')))
16
- end
17
- end
18
- return main_xml
19
- end
20
- end
21
- end
22
-
23
- xml_request_method :get_card_info, :create_card, :submit_payment, :update_card_info
24
-
25
- public
26
-
27
- def get_payment_info(from, to)
28
- request(get_payment_info_xml(from, to).to_s)
29
- end
30
-
31
- def get_payment_info_xml(from, to)
32
- main_xml = self.main_xml
33
- if main_xml
34
- sub_xml("get_payment_info.xml") do |xml|
35
- xml.at_css("from").content = from.iso8601 if xml.at_css("from")
36
- xml.at_css("to").content = to.iso8601 if xml.at_css("to")
37
- main_xml.at_css('issuer-request').add_child(xml.at('get-payment-info'))
38
- end
39
- end
40
- return main_xml
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,13 +0,0 @@
1
- module WirecardMapper
2
- module Plugins
3
- def plugins
4
- @plugins ||= []
5
- end
6
-
7
- def plugin(mod)
8
- extend mod::ClassMethods if mod.const_defined?(:ClassMethods)
9
- include mod::InstanceMethods if mod.const_defined?(:InstanceMethods)
10
- plugins << mod
11
- end
12
- end
13
- end
@@ -1,28 +0,0 @@
1
- module WirecardMapper
2
- module Request
3
- module InstanceMethods
4
-
5
- def request(xml)
6
- uri = URI.parse(Config.server_uri)
7
- unless uri.nil?
8
- http = Net::HTTP.new(uri.host, Config.server_port)
9
- if http
10
- http.use_ssl = true
11
- request = Net::HTTP::Post.new(uri.path)
12
- if request
13
- request.content_type = "text/xml"
14
- request.content_length = xml.size
15
- request.basic_auth(Config.login, Config.password)
16
- request.body = xml
17
- response = http.request(request)
18
- if response
19
- return WirecardMapper::Response.new(response.body)
20
- end
21
- end
22
- end
23
- end
24
- end
25
-
26
- end
27
- end
28
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Xml' do
4
-
5
- before(:each) do
6
- @card = Card.new
7
- end
8
-
9
- it "should get main xml" do
10
- xml = @card.main_xml
11
- xml.at_css("issuer-request")['mode'].should eql(WirecardMapper::Config.mode)
12
- xml.at_css("entity-id").content.to_s.should eql(WirecardMapper::Config.entity_id)
13
- xml.at_css("request-id").content.to_s.should_not be_empty
14
- end
15
-
16
- it "should get cardinfo xml" do
17
- xml = @card.get_card_info_xml
18
- xml.at_css("card-id").content.should eql(@card.card_id)
19
- end
20
-
21
- it "should get create card xml" do
22
- xml = @card.create_card_xml
23
- xml.at_css("product-id").content.to_i.should eql(@card.number)
24
- end
25
-
26
- it "should get submit payment xml" do
27
- xml = @card.submit_payment_xml
28
- xml.at_css("card-id").content.should eql(@card.card_id)
29
- xml.at_css("amount").content.to_i.should eql(@card.amount)
30
- end
31
-
32
- it "should get update card xml" do
33
- xml = @card.update_card_info_xml
34
- xml.at_css("card-id").content.should eql(@card.card_id)
35
- end
36
-
37
- it "should get payment info xml" do
38
- xml = @card.get_payment_info_xml(Time.now - (24 * 3600), Time.now)
39
- xml.at_css("card-id").content.should eql(@card.card_id)
40
- end
41
- end