wirecardmapper 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -14,6 +14,10 @@ A Ruby Object Mapper for Wirecard XML interface
14
14
 
15
15
  $ gem install wirecardmapper
16
16
 
17
+ == Port Tunnel
18
+
19
+ ssh tunnelserver1 -L localhost:8080:wirecardserver:443
20
+
17
21
  == Problems or Questions?
18
22
 
19
23
  == Copyright
data/Rakefile CHANGED
@@ -18,10 +18,8 @@ spec = Gem::Specification.new do |s|
18
18
  s.description = s.summary
19
19
  s.author = 'Alexander Klaiber'
20
20
  s.email = 'alex.klaiber@gmail.com'
21
- # s.executables = ['your_executable_here']
22
- s.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{lib,spec}/**/*")
21
+ s.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{lib,spec,templates}/**/*")
23
22
  s.require_path = "lib"
24
- # s.bindir = "bin"
25
23
 
26
24
  s.add_dependency 'nokogiri', '>= 1.4.2'
27
25
  s.add_dependency 'uuid', '>= 2.3.1'
@@ -42,10 +40,6 @@ Rake::RDocTask.new do |rdoc|
42
40
  rdoc.options << '--line-numbers'
43
41
  end
44
42
 
45
- #Rake::TestTask.new do |t|
46
- # t.test_files = FileList['test/**/*.rb']
47
- #end
48
-
49
43
  Spec::Rake::SpecTask.new do |t|
50
44
  t.spec_files = FileList['spec/**/*.rb']
51
45
  t.libs << Dir["lib"]
@@ -2,12 +2,16 @@ module WirecardMapper
2
2
  module Config
3
3
 
4
4
  class << self
5
- attr_accessor :mode, :entity_id
6
- attr_writer :templates_path
5
+ attr_accessor :mode, :entity_id, :server_uri, :login, :password
6
+ attr_writer :templates_path, :server_port
7
7
  end
8
8
 
9
9
  def self.templates_path
10
- @templates_path ||= "templates/"
10
+ @templates_path ||= "#{File.dirname(__FILE__)}/../../templates/"
11
+ end
12
+
13
+ def self.server_port
14
+ @server_port ||= 443
11
15
  end
12
16
 
13
17
  end
@@ -1,6 +1,30 @@
1
1
  module WirecardMapper
2
2
  module Model
3
3
 
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
9
+
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(/_/,'-')))
19
+ end
20
+ end
21
+ return main_xml
22
+ end
23
+ end
24
+ end
25
+
26
+ xml_request_method :get_card_info, :create_card, :submit_payment, :update_card_info, :get_payment_info
27
+
4
28
  def request_id
5
29
  UUID.generate
6
30
  end
@@ -22,16 +46,36 @@ module WirecardMapper
22
46
  return xml
23
47
  end
24
48
 
25
- def get_cardinfo_xml
26
- main_xml = self.main_xml
27
- if main_xml
28
- xml = open_xml('get_card_info.xml')
29
- if xml
30
- xml.at_css("card-id").content = self.card_id
31
- main_xml.at_css('issuer-request').add_child(xml.at('get-card-info'))
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
65
+ end
32
66
  end
33
67
  end
34
- return main_xml
68
+ end
69
+
70
+ def respone(xml)
71
+ return WirecardMapper::Response.new(xml)
72
+ end
73
+
74
+ def print_request(request)
75
+ request.each_header do |key, value|
76
+ puts "#{key} : #{value}"
77
+ end
78
+ puts request.body
35
79
  end
36
80
 
37
81
  end
@@ -0,0 +1,8 @@
1
+ class Net::HTTP
2
+ alias_method :old_initialize, :initialize
3
+ def initialize(*args)
4
+ old_initialize(*args)
5
+ @ssl_context = OpenSSL::SSL::SSLContext.new
6
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module WirecardMapper
2
+ module Request
3
+
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ module WirecardMapper
2
+ class Response
3
+
4
+ def self.node_reader(*args)
5
+ args.each do |arg|
6
+ define_method(arg) do
7
+ return @doc.at_css(arg.to_s.gsub(/_/,'-')).content
8
+ end
9
+ end
10
+ end
11
+
12
+ public
13
+
14
+ node_reader :card_id, :card_number, :return_code, :return_message,
15
+ :status_code, :status_message, :expiration_month, :expiration_year,
16
+ :card_security_code, :card_level, :card_comment, :issuing_date,
17
+ :bank_code, :account_number, :currency, :first_name, :last_name,
18
+ :issuer_consumer_id
19
+
20
+ def initialize(xml)
21
+ @doc = Nokogiri::XML(xml)
22
+ end
23
+
24
+ def to_s
25
+ @doc.to_s
26
+ end
27
+
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module WirecardMapper
2
- Version = '0.0.1'
2
+ Version = '0.2.0'
3
3
  end
@@ -1,7 +1,13 @@
1
+ require 'net/https'
2
+ require "base64"
1
3
  require 'nokogiri'
2
4
  require 'uuid'
3
5
 
6
+ require 'wirecardmapper/net_http_monkeypatch'
7
+
4
8
  module WirecardMapper
5
9
  autoload :Config, 'wirecardmapper/config'
10
+ autoload :Response, 'wirecardmapper/response'
11
+ autoload :Request, 'wirecardmapper/request'
6
12
  autoload :Model, 'wirecardmapper/model'
7
- end
13
+ end
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <issuer-response>
3
+ <application>
4
+ <request-id>4711-20040712120000</request-id>
5
+ <response-id>47ae06350a010018157db660f8b85d8d</response-id>
6
+ </application>
7
+ <create-card>
8
+ <return-code>0</return-code>
9
+ <return-message>Successful system entry.</return-message>
10
+ <account-card-data>
11
+ <card-status>
12
+ <status-code>activated</status-code>
13
+ <status-message>Active card</status-message>
14
+ </card-status>
15
+ <card-data>
16
+ <card-id>47ae07020a010018157db66065da6e5c</card-id>
17
+ <card-number>5274569796581777</card-number>
18
+ <expiration-month>08</expiration-month>
19
+ <expiration-year>2011</expiration-year>
20
+ <card-security-code>618</card-security-code>
21
+ <card-level>P</card-level>
22
+ <card-comment>This is a test card</card-comment>
23
+ <issuing-date>2010-08-06</issuing-date>
24
+ </card-data>
25
+ <account-data>
26
+ <bank-code>51230800</bank-code>
27
+ <account-number>2345</account-number>
28
+ <currency>EUR</currency>
29
+ <first-name>WD SCP Test</first-name>
30
+ <last-name>WD SCP Test</last-name>
31
+ <issuer-consumer-id>2345</issuer-consumer-id>
32
+ </account-data>
33
+ </account-card-data>
34
+ </create-card>
35
+ </issuer-response>
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Model" do
4
+
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
21
+ end
22
+
23
+ it "should get cardinfo" do
24
+ response = @card.get_card_info
25
+ response.card_id.should eql('47ae07020a010018157db66065da6e5c')
26
+ response.card_number.should eql('5274569796581777')
27
+ end
28
+
29
+ it "should create card" do
30
+ response = @card.create_card
31
+ response.card_id.should_not be_empty
32
+ response.card_number.should_not be_empty
33
+ end
34
+
35
+ it "should update card info" do
36
+ response = @card.update_card_info
37
+ response.return_code.to_i.should eql(0)
38
+ response.return_message.should eql('Successful system entry.')
39
+ end
40
+
41
+ it "should submit payment" do
42
+ response = @card.submit_payment
43
+ response.return_code.to_i.should eql(0)
44
+ response.return_message.should eql('Successful system entry.')
45
+ end
46
+
47
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,8 @@ require 'rubygems'
3
3
  $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
4
  require 'wirecardmapper'
5
5
 
6
+ FIXTURES_PATH = "#{File.dirname(__FILE__)}/fixtures"
7
+
6
8
  def Model(name=nil, &block)
7
9
  klass = Class.new do
8
10
  extend WirecardMapper::Model
@@ -12,5 +14,10 @@ def Model(name=nil, &block)
12
14
  klass
13
15
  end
14
16
 
17
+ #WirecardMapper::Config.server_uri = "https://c3-test.wirecard.com/issuer/client"
18
+ WirecardMapper::Config.server_uri = "http://localhost/issuer/client"
19
+ WirecardMapper::Config.server_port = 8080
20
+ WirecardMapper::Config.login = "000000315ED21E8A";
21
+ WirecardMapper::Config.password = "FDJqLhoRX";
15
22
  WirecardMapper::Config.mode = "test"
16
- WirecardMapper::Config.entity_id = "Test entity id"
23
+ WirecardMapper::Config.entity_id = "000000315ED21F74"
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Model" do
4
+
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
21
+ end
22
+
23
+ it "should get main xml" do
24
+ xml = @card.main_xml
25
+ xml.at_css("issuer-request")['mode'].should eql(WirecardMapper::Config.mode)
26
+ xml.at_css("entity-id").content.to_s.should eql(WirecardMapper::Config.entity_id)
27
+ xml.at_css("request-id").content.to_s.should_not be_empty
28
+ end
29
+
30
+ it "should get cardinfo xml" do
31
+ xml = @card.get_card_info_xml
32
+ xml.at_css("card-id").content.should eql(@card.card_id)
33
+ end
34
+
35
+ it "should get create card xml" do
36
+ xml = @card.create_card_xml
37
+ xml.at_css("product-id").content.to_i.should eql(@card.number)
38
+ end
39
+
40
+ it "should get submit payment xml" do
41
+ xml = @card.submit_payment_xml
42
+ xml.at_css("card-id").content.should eql(@card.card_id)
43
+ xml.at_css("amount").content.to_f.should eql(@card.amount)
44
+ end
45
+
46
+ it "should get update card xml" do
47
+ xml = @card.update_card_info_xml
48
+ xml.at_css("card-id").content.should eql(@card.card_id)
49
+ end
50
+
51
+ it "should get payment info xml" do
52
+ xml = @card.get_payment_info_xml
53
+ xml.at_css("card-id").content.should eql(@card.card_id)
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Response" do
4
+
5
+ it "should get card status" do
6
+ File.open("#{FIXTURES_PATH}/create_card.xml") do |file|
7
+ response = WirecardMapper::Response.new(file)
8
+ response.card_id.should eql('47ae07020a010018157db66065da6e5c')
9
+ response.card_number.should eql('5274569796581777')
10
+ response.status_code.should eql('activated')
11
+ response.status_message.should eql('Active card')
12
+ response.expiration_month.should eql('08')
13
+ response.expiration_year.should eql('2011')
14
+ response.card_security_code.should eql('618')
15
+ response.card_level.should eql('P')
16
+ response.card_comment.should eql('This is a test card')
17
+ response.issuing_date.should eql('2010-08-06')
18
+ response.bank_code.should eql('51230800')
19
+ response.account_number.should eql('2345')
20
+ response.currency.should eql('EUR')
21
+ response.first_name.should eql('WD SCP Test')
22
+ response.last_name.should eql('WD SCP Test')
23
+ response.issuer_consumer_id.should eql('2345')
24
+ end
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,8 @@
1
+ <create-card>
2
+ <product-data>
3
+ <product-id></product-id>
4
+ </product-data>
5
+ <card-data>
6
+ <card-comment>This is a test card</card-comment>
7
+ </card-data>
8
+ </create-card>
@@ -0,0 +1,6 @@
1
+ <get-card-info>
2
+ <card-data>
3
+ <card-id></card-id>
4
+ </card-data>
5
+ <card-activity>no</card-activity>
6
+ </get-card-info>
@@ -0,0 +1,11 @@
1
+ <get-payment-info>
2
+ <time-range>
3
+ <from></from>
4
+ <to></to>
5
+ </time-range>
6
+ <detail-type>MINIMUM</detail-type>
7
+ <card-data>
8
+ <card-id></card-id>
9
+ </card-data>
10
+ </get-payment-info>
11
+
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <issuer-request mode="live" version="1.0">
3
+ <application>
4
+ <request-id></request-id>
5
+ <entity-id></entity-id>
6
+ </application>
7
+ </issuer-request>
@@ -0,0 +1,10 @@
1
+ <submit-payment>
2
+ <payment-data>
3
+ <amount currency="EUR"></amount>
4
+ <payment-comment>Load for john.doe@abc.com</payment-comment>
5
+ </payment-data>
6
+ <card-data>
7
+ <card-id></card-id>
8
+ </card-data>
9
+ </submit-payment>
10
+
@@ -0,0 +1,6 @@
1
+ <update-card-info>
2
+ <card-data>
3
+ <card-id></card-id>
4
+ </card-data>
5
+ </update-card-info>
6
+
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: 29
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 0
9
- - 1
10
- version: 0.0.1
10
+ version: 0.2.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-07-29 00:00:00 +02:00
18
+ date: 2010-08-09 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -64,11 +64,23 @@ files:
64
64
  - README.rdoc
65
65
  - Rakefile
66
66
  - lib/wirecardmapper/model.rb
67
+ - lib/wirecardmapper/response.rb
68
+ - lib/wirecardmapper/request.rb
69
+ - lib/wirecardmapper/net_http_monkeypatch.rb
67
70
  - lib/wirecardmapper/version.rb
68
71
  - lib/wirecardmapper/config.rb
69
72
  - lib/wirecardmapper.rb
70
73
  - spec/spec_helper.rb
71
- - spec/unit/new_main.rb
74
+ - spec/fixtures/create_card.xml
75
+ - spec/unit/model.rb
76
+ - spec/unit/response.rb
77
+ - spec/functional/model.rb
78
+ - templates/create_card.xml
79
+ - templates/main.xml
80
+ - templates/submit_payment.xml
81
+ - templates/get_payment_info.xml
82
+ - templates/update_card_info.xml
83
+ - templates/get_card_info.xml
72
84
  has_rdoc: true
73
85
  homepage: http://github.com/aklaiber/wirecardmapper
74
86
  licenses: []
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "RSpec Greeter" do
4
-
5
- before(:each) do
6
- @model = Model do
7
- class << self
8
- def card_id
9
- 1234
10
- end
11
- end
12
- end
13
- end
14
-
15
- it "should get main xml" do
16
- xml = @model.main_xml
17
- xml.at_css("issuer-request")['mode'].should eql('test')
18
- xml.at_css("entity-id").content.to_s.should eql('Test entity id')
19
- xml.at_css("request-id").content.to_s.should_not be_empty
20
- end
21
-
22
- it "should get get_cardinfo xml" do
23
- xml = @model.get_cardinfo_xml
24
- xml.at_css("issuer-request")['mode'].should eql('test')
25
- xml.at_css("entity-id").content.to_s.should eql('Test entity id')
26
- xml.at_css("request-id").content.to_s.should_not be_empty
27
- xml.at_css("card-id").content.to_i.should eql(@model.card_id)
28
- end
29
- end