wirecardmapper 0.2.0 → 0.6.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.
data/LICENSE CHANGED
@@ -1,3 +1,20 @@
1
- == wirecardmapper
1
+ Copyright (c) 2010 Alexander Klaiber
2
2
 
3
- Put appropriate LICENSE for your project here.
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -18,8 +18,6 @@ A Ruby Object Mapper for Wirecard XML interface
18
18
 
19
19
  ssh tunnelserver1 -L localhost:8080:wirecardserver:443
20
20
 
21
- == Problems or Questions?
22
-
23
21
  == Copyright
24
22
 
25
23
  See LICENSE for details.
data/Rakefile CHANGED
@@ -1,35 +1,12 @@
1
1
  require 'rubygems'
2
+
2
3
  require 'rake'
3
- require 'rake/clean'
4
- require 'rake/gempackagetask'
5
4
  require 'rake/rdoctask'
6
- require 'rake/testtask'
7
- require 'spec/rake/spectask'
8
-
9
- require File.expand_path('../lib/wirecardmapper/version', __FILE__)
10
5
 
11
- spec = Gem::Specification.new do |s|
12
- s.name = 'wirecardmapper'
13
- s.homepage = 'http://github.com/aklaiber/wirecardmapper'
14
- s.version = WirecardMapper::Version
15
- s.has_rdoc = false
16
- s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
17
- s.summary = 'A Ruby Object Mapper for Wirecard XML interface'
18
- s.description = s.summary
19
- s.author = 'Alexander Klaiber'
20
- s.email = 'alex.klaiber@gmail.com'
21
- s.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{lib,spec,templates}/**/*")
22
- s.require_path = "lib"
23
-
24
- s.add_dependency 'nokogiri', '>= 1.4.2'
25
- s.add_dependency 'uuid', '>= 2.3.1'
26
- end
6
+ require "rspec"
7
+ require "rspec/core/rake_task"
27
8
 
28
- Rake::GemPackageTask.new(spec) do |p|
29
- p.gem_spec = spec
30
- p.need_tar = true
31
- p.need_zip = true
32
- end
9
+ require File.expand_path('../lib/wirecardmapper/version', __FILE__)
33
10
 
34
11
  Rake::RDocTask.new do |rdoc|
35
12
  files =['README.rdoc', 'LICENSE', 'lib/**/*.rb']
@@ -40,15 +17,26 @@ Rake::RDocTask.new do |rdoc|
40
17
  rdoc.options << '--line-numbers'
41
18
  end
42
19
 
43
- Spec::Rake::SpecTask.new do |t|
44
- t.spec_files = FileList['spec/**/*.rb']
45
- t.libs << Dir["lib"]
20
+ Rspec::Core::RakeTask.new(:spec) do |spec|
21
+ spec.pattern = "spec/**/*_spec.rb"
22
+ end
23
+
24
+ namespace :wirecard do
25
+ desc 'Open ssh tunnel to wirecard test server'
26
+ task :ssh_tunnel do
27
+ sh "ssh test.freecent.com -L localhost:8080:c3-test.wirecard.com:443"
28
+ end
29
+ end
30
+
31
+ desc 'Builds the gem'
32
+ task :build do
33
+ sh "gem build wirecardmapper.gemspec"
46
34
  end
47
35
 
48
36
  desc 'Tags version, pushes to remote, and pushes gem'
49
- task :release => [:spec, :gem] do
37
+ task :release => [:spec, :build] do
50
38
  sh "git tag v#{WirecardMapper::Version}"
51
39
  sh "git push origin master"
52
40
  sh "git push origin v#{WirecardMapper::Version}"
53
- sh "gem push pkg/wirecardmapper-#{WirecardMapper::Version}.gem"
54
- end
41
+ sh "gem push wirecardmapper-#{WirecardMapper::Version}.gem"
42
+ end
@@ -1,3 +1,6 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
1
4
  require 'net/https'
2
5
  require "base64"
3
6
  require 'nokogiri'
@@ -6,8 +9,21 @@ require 'uuid'
6
9
  require 'wirecardmapper/net_http_monkeypatch'
7
10
 
8
11
  module WirecardMapper
12
+ autoload :Plugins, 'wirecardmapper/plugins'
9
13
  autoload :Config, 'wirecardmapper/config'
14
+
15
+ autoload :Xml, 'wirecardmapper/xml'
10
16
  autoload :Response, 'wirecardmapper/response'
11
17
  autoload :Request, 'wirecardmapper/request'
12
18
  autoload :Model, 'wirecardmapper/model'
19
+
20
+ def self.included(model)
21
+ model.class_eval do
22
+ extend Plugins
23
+
24
+ plugin WirecardMapper::Xml
25
+ plugin WirecardMapper::Request
26
+ plugin WirecardMapper::Model
27
+ end
28
+ end
13
29
  end
@@ -1,82 +1,45 @@
1
1
  module WirecardMapper
2
2
  module Model
3
+ module InstanceMethods
3
4
 
4
- def self.xml_request_method(*args)
5
- args.each do |arg|
6
- define_method(arg) do
7
- request(self.send("#{arg}_xml").to_s)
8
- end
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
9
10
 
10
- define_method("#{arg}_xml") do
11
- main_xml = self.main_xml
12
- if main_xml
13
- xml = open_xml("#{arg}.xml")
14
- if xml
15
- xml.at_css("card-id").content = self.card_id if xml.at_css("card-id")
16
- xml.at_css("product-id").content = self.number if xml.at_css("product-id")
17
- xml.at_css("amount").content = self.amount if xml.at_css("amount")
18
- main_xml.at_css('issuer-request').add_child(xml.at(arg.to_s.gsub(/_/,'-')))
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
19
17
  end
18
+ return main_xml
20
19
  end
21
- return main_xml
22
20
  end
23
21
  end
24
- end
25
22
 
26
- xml_request_method :get_card_info, :create_card, :submit_payment, :update_card_info, :get_payment_info
27
-
28
- def request_id
29
- UUID.generate
30
- end
23
+ xml_request_method :get_card_info, :create_card, :submit_payment, :update_card_info
31
24
 
32
- def open_xml(file_name)
33
- xml_file = File.open(File.join(Config.templates_path, file_name))
34
- if xml_file
35
- return Nokogiri::XML(xml_file)
36
- end
37
- end
25
+ public
38
26
 
39
- def main_xml
40
- xml = open_xml('main.xml')
41
- if xml
42
- xml.at_css("issuer-request")['mode'] = Config.mode
43
- xml.at_css("request-id").content = self.request_id
44
- xml.at_css("entity-id").content = Config.entity_id
27
+ def get_payment_info(from, to)
28
+ request(get_payment_info_xml(from, to).to_s)
45
29
  end
46
- return xml
47
- end
48
30
 
49
- def request(xml)
50
- uri = URI.parse(Config.server_uri)
51
- unless uri.nil?
52
- http = Net::HTTP.new(uri.host, Config.server_port)
53
- if http
54
- http.use_ssl = true
55
- request = Net::HTTP::Post.new(uri.path)
56
- if request
57
- request.content_type = "text/xml"
58
- request.content_length = xml.size
59
- request.basic_auth(Config.login, Config.password)
60
- request.body = xml
61
- response = http.request(request)
62
- if response
63
- return WirecardMapper::Response.new(response.body)
64
- end
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'))
65
38
  end
66
39
  end
40
+ return main_xml
67
41
  end
68
- end
69
42
 
70
- def respone(xml)
71
- return WirecardMapper::Response.new(xml)
72
43
  end
73
-
74
- def print_request(request)
75
- request.each_header do |key, value|
76
- puts "#{key} : #{value}"
77
- end
78
- puts request.body
79
- end
80
-
81
44
  end
82
45
  end
@@ -0,0 +1,13 @@
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,5 +1,28 @@
1
1
  module WirecardMapper
2
2
  module Request
3
-
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
4
27
  end
5
- end
28
+ end
@@ -4,7 +4,7 @@ module WirecardMapper
4
4
  def self.node_reader(*args)
5
5
  args.each do |arg|
6
6
  define_method(arg) do
7
- return @doc.at_css(arg.to_s.gsub(/_/,'-')).content
7
+ return parse(@doc.at_css(arg.to_s.gsub(/_/,'-')).content)
8
8
  end
9
9
  end
10
10
  end
@@ -15,7 +15,7 @@ module WirecardMapper
15
15
  :status_code, :status_message, :expiration_month, :expiration_year,
16
16
  :card_security_code, :card_level, :card_comment, :issuing_date,
17
17
  :bank_code, :account_number, :currency, :first_name, :last_name,
18
- :issuer_consumer_id
18
+ :issuer_consumer_id, :balance
19
19
 
20
20
  def initialize(xml)
21
21
  @doc = Nokogiri::XML(xml)
@@ -25,5 +25,19 @@ module WirecardMapper
25
25
  @doc.to_s
26
26
  end
27
27
 
28
+ def ok?
29
+ return_code.to_i.eql?(0)
30
+ end
31
+
32
+ private
33
+
34
+ def parse(value)
35
+ begin
36
+ return Integer(value)
37
+ rescue
38
+ return value
39
+ end
40
+ end
41
+
28
42
  end
29
43
  end
@@ -1,3 +1,3 @@
1
1
  module WirecardMapper
2
- Version = '0.2.0'
3
- end
2
+ Version = '0.6.0'
3
+ end
@@ -0,0 +1,38 @@
1
+ module WirecardMapper
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
13
+ end
14
+
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
21
+ end
22
+
23
+ private
24
+
25
+ def request_id
26
+ UUID.generate
27
+ end
28
+
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
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -3,43 +3,43 @@ require 'spec_helper'
3
3
  describe "Model" do
4
4
 
5
5
  before(:each) do
6
- @card = Model do
7
- class << self
8
- def card_id
9
- '47ae07020a010018157db66065da6e5c'
10
- end
11
-
12
- def number
13
- 11
14
- end
15
-
16
- def amount
17
- 10
18
- end
19
- end
20
- end
6
+ @card = Card.new
21
7
  end
22
8
 
23
9
  it "should get cardinfo" do
24
10
  response = @card.get_card_info
11
+ response.ok?.should be_true
25
12
  response.card_id.should eql('47ae07020a010018157db66065da6e5c')
26
- response.card_number.should eql('5274569796581777')
13
+ response.card_number.should eql(5274569796581777)
14
+ response.balance.should eql(200)
27
15
  end
28
16
 
29
17
  it "should create card" do
30
18
  response = @card.create_card
19
+ response.ok?.should be_true
31
20
  response.card_id.should_not be_empty
32
- response.card_number.should_not be_empty
21
+ response.card_number.should_not be_nil
22
+ response.status_message.should eql('Active card')
23
+ response.status_code.should eql('activated')
33
24
  end
34
25
 
35
26
  it "should update card info" do
36
27
  response = @card.update_card_info
28
+ response.ok?.should be_true
37
29
  response.return_code.to_i.should eql(0)
38
30
  response.return_message.should eql('Successful system entry.')
39
31
  end
40
32
 
41
33
  it "should submit payment" do
42
34
  response = @card.submit_payment
35
+ response.ok?.should be_true
36
+ response.return_code.to_i.should eql(0)
37
+ response.return_message.should eql('Successful system entry.')
38
+ end
39
+
40
+ it "should get payment info" do
41
+ response = @card.get_payment_info(Time.now - (24 * 3600), Time.now)
42
+ response.ok?.should be_true
43
43
  response.return_code.to_i.should eql(0)
44
44
  response.return_message.should eql('Successful system entry.')
45
45
  end
data/spec/spec_helper.rb CHANGED
@@ -5,19 +5,38 @@ require 'wirecardmapper'
5
5
 
6
6
  FIXTURES_PATH = "#{File.dirname(__FILE__)}/fixtures"
7
7
 
8
- def Model(name=nil, &block)
8
+ def klass(name=nil, &block)
9
9
  klass = Class.new do
10
- extend WirecardMapper::Model
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
11
23
  end
12
24
 
13
25
  klass.class_eval(&block) if block_given?
14
26
  klass
15
27
  end
16
28
 
17
- #WirecardMapper::Config.server_uri = "https://c3-test.wirecard.com/issuer/client"
18
29
  WirecardMapper::Config.server_uri = "http://localhost/issuer/client"
19
30
  WirecardMapper::Config.server_port = 8080
20
31
  WirecardMapper::Config.login = "000000315ED21E8A";
21
32
  WirecardMapper::Config.password = "FDJqLhoRX";
22
33
  WirecardMapper::Config.mode = "test"
23
34
  WirecardMapper::Config.entity_id = "000000315ED21F74"
35
+
36
+ RSpec.configure do |config|
37
+
38
+ config.before(:suite) do
39
+ Card = klass
40
+ end
41
+
42
+ end
@@ -6,21 +6,21 @@ describe "Response" do
6
6
  File.open("#{FIXTURES_PATH}/create_card.xml") do |file|
7
7
  response = WirecardMapper::Response.new(file)
8
8
  response.card_id.should eql('47ae07020a010018157db66065da6e5c')
9
- response.card_number.should eql('5274569796581777')
9
+ response.card_number.should eql(5274569796581777)
10
10
  response.status_code.should eql('activated')
11
11
  response.status_message.should eql('Active card')
12
12
  response.expiration_month.should eql('08')
13
- response.expiration_year.should eql('2011')
14
- response.card_security_code.should eql('618')
13
+ response.expiration_year.should eql(2011)
14
+ response.card_security_code.should eql(618)
15
15
  response.card_level.should eql('P')
16
16
  response.card_comment.should eql('This is a test card')
17
17
  response.issuing_date.should eql('2010-08-06')
18
- response.bank_code.should eql('51230800')
19
- response.account_number.should eql('2345')
18
+ response.bank_code.should eql(51230800)
19
+ response.account_number.should eql(2345)
20
20
  response.currency.should eql('EUR')
21
21
  response.first_name.should eql('WD SCP Test')
22
22
  response.last_name.should eql('WD SCP Test')
23
- response.issuer_consumer_id.should eql('2345')
23
+ response.issuer_consumer_id.should eql(2345)
24
24
  end
25
25
  end
26
26
 
@@ -1,23 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Model" do
4
-
3
+ describe 'Xml' do
4
+
5
5
  before(:each) do
6
- @card = Model do
7
- class << self
8
- def card_id
9
- '47ae07020a010018157db66065da6e5c'
10
- end
11
-
12
- def number
13
- 5274569796581777
14
- end
15
-
16
- def amount
17
- 10.10
18
- end
19
- end
20
- end
6
+ @card = Card.new
21
7
  end
22
8
 
23
9
  it "should get main xml" do
@@ -40,7 +26,7 @@ describe "Model" do
40
26
  it "should get submit payment xml" do
41
27
  xml = @card.submit_payment_xml
42
28
  xml.at_css("card-id").content.should eql(@card.card_id)
43
- xml.at_css("amount").content.to_f.should eql(@card.amount)
29
+ xml.at_css("amount").content.to_i.should eql(@card.amount)
44
30
  end
45
31
 
46
32
  it "should get update card xml" do
@@ -49,7 +35,7 @@ describe "Model" do
49
35
  end
50
36
 
51
37
  it "should get payment info xml" do
52
- xml = @card.get_payment_info_xml
38
+ xml = @card.get_payment_info_xml(Time.now - (24 * 3600), Time.now)
53
39
  xml.at_css("card-id").content.should eql(@card.card_id)
54
40
  end
55
41
  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: 23
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 6
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.6.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-08-09 00:00:00 +02:00
18
+ date: 2010-11-18 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -63,24 +63,26 @@ files:
63
63
  - LICENSE
64
64
  - README.rdoc
65
65
  - Rakefile
66
- - lib/wirecardmapper/model.rb
67
- - lib/wirecardmapper/response.rb
68
- - lib/wirecardmapper/request.rb
69
- - lib/wirecardmapper/net_http_monkeypatch.rb
66
+ - lib/wirecardmapper.rb
67
+ - lib/wirecardmapper/plugins.rb
70
68
  - lib/wirecardmapper/version.rb
69
+ - lib/wirecardmapper/net_http_monkeypatch.rb
70
+ - lib/wirecardmapper/request.rb
71
+ - lib/wirecardmapper/model.rb
72
+ - lib/wirecardmapper/xml.rb
71
73
  - lib/wirecardmapper/config.rb
72
- - lib/wirecardmapper.rb
73
- - spec/spec_helper.rb
74
+ - lib/wirecardmapper/response.rb
74
75
  - spec/fixtures/create_card.xml
75
- - spec/unit/model.rb
76
- - spec/unit/response.rb
77
- - spec/functional/model.rb
76
+ - spec/unit/response_spec.rb
77
+ - spec/unit/xml_spec.rb
78
+ - spec/spec_helper.rb
79
+ - spec/functional/model_spec.rb
80
+ - templates/get_card_info.xml
78
81
  - templates/create_card.xml
79
- - templates/main.xml
82
+ - templates/update_card_info.xml
80
83
  - templates/submit_payment.xml
84
+ - templates/main.xml
81
85
  - templates/get_payment_info.xml
82
- - templates/update_card_info.xml
83
- - templates/get_card_info.xml
84
86
  has_rdoc: true
85
87
  homepage: http://github.com/aklaiber/wirecardmapper
86
88
  licenses: []