wirecardmapper 0.8.0 → 0.9.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.
@@ -0,0 +1,28 @@
1
+ module WirecardMapper
2
+ module Model
3
+ module MongoMapper
4
+
5
+ include Base
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ before_create :create_card, :if => "self.card_id.blank?"
11
+ end
12
+
13
+ private
14
+
15
+ def create_card
16
+ response = WirecardMapper.create_card(:entity_id => self.class.entity_id, :product_data => { :product_id => self.class.product_id })
17
+ if response.ok?
18
+ transaction_log("create_card", response)
19
+ self.card_id = response.card_id
20
+ self.number = response.card_number
21
+ self.security_code = response.card_security_code
22
+ self.blocked!
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module WirecardMapper
2
+ class Railtie < Rails::Railtie
3
+
4
+ initializer "setup wirecardmapper" do
5
+ config_file = Rails.root.join("config", "wirecardmapper.yml")
6
+ if config_file.file?
7
+ WirecardMapper::Config.config = YAML.load(ERB.new(config_file.read).result)[Rails.env]
8
+ end
9
+ end
10
+
11
+ initializer "warn when configuration is missing" do
12
+ config.after_initialize do
13
+ unless Rails.root.join("config", "wirecardmapper.yml").file?
14
+ puts "\nWirecardMapper config not found. Create a config file at: config/wirecardmapper.yml"
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -1,24 +1,11 @@
1
1
  module WirecardMapper
2
2
  class Response
3
-
4
- def self.node_reader(*args)
5
- args.each do |arg|
6
- define_method(arg) do
7
- return parse(@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, :balance
19
3
 
20
4
  def initialize(xml)
21
5
  @doc = Nokogiri::XML(xml)
6
+ if @doc.at_css('issuer-response').nil?
7
+ raise WirecardMapper::Exception, "No valid wirecard issuer-response"
8
+ end
22
9
  end
23
10
 
24
11
  def to_s
@@ -26,7 +13,35 @@ module WirecardMapper
26
13
  end
27
14
 
28
15
  def ok?
29
- return_code.to_i.eql?(0)
16
+ return_code.to_i.eql?(0) || return_code.to_i.eql?(21)
17
+ end
18
+
19
+ def card_security_code
20
+ @doc.at_css('card-security-code').content
21
+ end
22
+
23
+ def card_number
24
+ @doc.at_css('card-number').content
25
+ end
26
+
27
+ def bank_code
28
+ @doc.at_css('bank-code').content
29
+ end
30
+
31
+ def account_number
32
+ @doc.at_css('account-number').content
33
+ end
34
+
35
+ public
36
+
37
+ def method_missing(method, *args)
38
+ node_name = method.to_s.gsub(/_/, '-')
39
+ node = @doc.at_css(node_name)
40
+ unless node.nil?
41
+ parse(@doc.at_css(node_name).content)
42
+ else
43
+ super
44
+ end
30
45
  end
31
46
 
32
47
  private
@@ -1,3 +1,3 @@
1
1
  module WirecardMapper
2
- Version = '0.8.0'
2
+ Version = '0.9.0'
3
3
  end
@@ -0,0 +1,12 @@
1
+ development:
2
+ server_uri: "http://localhost/issuer/client"
3
+ server_port: 8080
4
+ login: "000000315ED21E8A"
5
+ password: "FDJqLhoRX"
6
+ mode: "live"
7
+ entity_id: "000000315ED21F74"
8
+ product_id: 11
9
+
10
+ test:
11
+
12
+ production:
@@ -17,7 +17,7 @@
17
17
  <card-number>5274569796581777</card-number>
18
18
  <expiration-month>08</expiration-month>
19
19
  <expiration-year>2011</expiration-year>
20
- <card-security-code>618</card-security-code>
20
+ <card-security-code>018</card-security-code>
21
21
  <card-level>P</card-level>
22
22
  <card-comment>This is a test card</card-comment>
23
23
  <issuing-date>2010-08-06</issuing-date>
@@ -0,0 +1,34 @@
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-number>5274569796581777</card-number>
17
+ <expiration-month>08</expiration-month>
18
+ <expiration-year>2011</expiration-year>
19
+ <card-security-code>618</card-security-code>
20
+ <card-level>P</card-level>
21
+ <card-comment>This is a test card</card-comment>
22
+ <issuing-date>2010-08-06</issuing-date>
23
+ </card-data>
24
+ <account-data>
25
+ <bank-code>51230800</bank-code>
26
+ <account-number>2345</account-number>
27
+ <currency>EUR</currency>
28
+ <first-name>WD SCP Test</first-name>
29
+ <last-name>WD SCP Test</last-name>
30
+ <issuer-consumer-id>2345</issuer-consumer-id>
31
+ </account-data>
32
+ </account-card-data>
33
+ </create-card>
34
+ </issuer-response>
@@ -0,0 +1,46 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <issuer-response>
3
+ <application>
4
+ <request-id>bbfb11b0-6b6a-012e-268a-001c2597881a</request-id>
5
+ <response-id>372945BF0A0681400CA6A49B77F19C0D</response-id>
6
+ </application>
7
+ <get-card-info>
8
+ <return-code>0</return-code>
9
+ <return-message>Successful system entry.</return-message>
10
+ <consumer-data>
11
+ <consumer-id>1302eff60a0a0c6f00e53108045ed118</consumer-id>
12
+ <first-name>WD SCP Test</first-name>
13
+ <last-name>WD SCP Test</last-name>
14
+ <email>wirecardscpbusiness@wirecard.de</email>
15
+ <consumer-type>B</consumer-type>
16
+ <salutation>0</salutation>
17
+ <marital-status>0</marital-status>
18
+ </consumer-data>
19
+ <account-card-data>
20
+ <card-status>
21
+ <status-code>activated</status-code>
22
+ <status-message>Cancellation of the card is in process</status-message>
23
+ </card-status>
24
+ <card-data>
25
+ <card-id>47ae07020a010018157db66065da6e5c</card-id>
26
+ <card-number>5274569796581777</card-number>
27
+ <expiration-month>08</expiration-month>
28
+ <expiration-year>2011</expiration-year>
29
+ <card-security-code>618</card-security-code>
30
+ <card-level>P</card-level>
31
+ <statement-data processing-date="2011-05-28" currency="EUR">
32
+ <balance>200</balance>
33
+ </statement-data>
34
+ <issuing-date>2010-08-06</issuing-date>
35
+ </card-data>
36
+ <account-data>
37
+ <bank-code>51230800</bank-code>
38
+ <account-number>2345</account-number>
39
+ <currency>EUR</currency>
40
+ <first-name>WD SCP Test</first-name>
41
+ <last-name>WD SCP Test</last-name>
42
+ <issuer-consumer-id>2345</issuer-consumer-id>
43
+ </account-data>
44
+ </account-card-data>
45
+ </get-card-info>
46
+ </issuer-response>
@@ -0,0 +1,42 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Draft//EN" "">
3
+ <HTML>
4
+ <HEAD>
5
+ <TITLE>Error 404--Not Found</TITLE>
6
+ <META NAME="GENERATOR" CONTENT="WebLogic Server">
7
+ </META>
8
+ <BODY bgcolor="white">
9
+ <FONT/>Helvetica&gt;<BR/>all&gt;
10
+ <TABLE/>0 cellspacing=5&gt;
11
+ <TR>
12
+ <TD><BR/>all&gt;
13
+ <FONT FACE="Helvetica" COLOR="black" SIZE="3">
14
+ <H2>Error 404--Not Found</H2>
15
+ </FONT>
16
+ </TD>
17
+ </TR>
18
+ </BODY>
19
+ <TABLE/>0 width=100% cellpadding=10&gt;
20
+ <TR><TD/>top WIDTH=100% BGCOLOR=white&gt;
21
+ <FONT FACE="Courier New">
22
+ <FONT FACE="Helvetica" SIZE="3">
23
+ <H3>From RFC 2068<i>Hypertext Transfer Protocol -- HTTP/1.1</i>:
24
+ </H3>
25
+ </FONT>
26
+ <FONT FACE="Helvetica" SIZE="3">
27
+ <H4>10.4.5 404 Not Found</H4>
28
+ </FONT>
29
+ <P>
30
+ <FONT FACE="Courier New">The server has not found anything matching the Request-URI. No indication is given of
31
+ whether the condition is temporary or permanent.
32
+ </FONT>
33
+ <p>If the server does not wish to make this information available to the client, the status code 403
34
+ (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some
35
+ internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding
36
+ address.
37
+ </p>
38
+ </P>
39
+ </FONT>
40
+ </TR>
41
+ </HEAD>
42
+ </HTML>
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe WirecardMapper::Model::Base do
4
+
5
+ before(:all) do
6
+ @klass = Class.new
7
+ @klass.class_eval do
8
+ include WirecardMapper::Model::Base
9
+
10
+ entity_id "000000315ED21F74"
11
+
12
+ def initialize(card_id, amount)
13
+ @card_id = card_id
14
+ @amount = amount
15
+ end
16
+ end
17
+ end
18
+
19
+ let(:card) { @klass.new(WirecardMapper.create_card.card_id, 2200) }
20
+
21
+ it "should get expiration year" do
22
+ card.expiration_year.should eql(1.year.from_now.year)
23
+ end
24
+
25
+ describe "change status" do
26
+ it "should activate card" do
27
+ card.activated!
28
+
29
+ card.status.should eql('activated')
30
+ card.activated?.should be_true
31
+ end
32
+
33
+ it "should block card" do
34
+ card.blocked!
35
+
36
+ card.status.should eql('blocked')
37
+ card.blocked?.should be_true
38
+ end
39
+
40
+ it "should cancelled card" do
41
+ card.cancelled!
42
+
43
+ card.status.should eql('cancellation-pending')
44
+ card.cancellation_pending?.should be_true
45
+ end
46
+ end
47
+
48
+ describe "load amount" do
49
+ it "should get balance" do
50
+ card.load_amount
51
+
52
+ card.amount.class.should eql(Money)
53
+ card.amount.cents.should eql(2200)
54
+ card.amount.to_f.should eql(22.00)
55
+
56
+ card.balance.class.should eql(Money)
57
+ card.balance.cents.should eql(2200)
58
+ card.balance.to_f.should eql(22.00)
59
+ end
60
+ end
61
+
62
+ describe "unload amount" do
63
+
64
+ before(:each) do
65
+ card.load_amount
66
+ end
67
+
68
+ it "should get balance" do
69
+ card.unload_amount
70
+
71
+ card.balance.class.should eql(Money)
72
+ card.balance.cents.should eql(0)
73
+ card.balance.to_f.should eql(0.0)
74
+ end
75
+
76
+ it "should unload card with comment" do
77
+ card.unload_amount(1000, "unload test Card").should be_true
78
+
79
+ card.balance.class.should eql(Money)
80
+ card.balance.cents.should eql(1200)
81
+ card.balance.to_f.should eql(12.0)
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe WirecardMapper::Model::MongoMapper do
4
+
5
+ before(:all) do
6
+ @klass = Class.new
7
+ @klass.class_eval do
8
+ include MongoMapper::Document
9
+ include WirecardMapper::Model::MongoMapper
10
+
11
+ product_id 11
12
+ entity_id "000000315ED21F74"
13
+
14
+ key :card_id, String
15
+ key :number, String
16
+ key :security_code, Integer
17
+ end
18
+ end
19
+
20
+
21
+ it "should create card" do
22
+ card = @klass.new
23
+
24
+ card.save.should be_true
25
+ card.card_id.should_not be_blank
26
+ card.number.should_not be_blank
27
+ card.security_code.should_not be_blank
28
+ end
29
+
30
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ describe WirecardMapper do
4
+
5
+ let(:card_id) { WirecardMapper.create_card(:card_data => {:card_comment => 'Test'}).card_id }
6
+
7
+ def card_info
8
+ WirecardMapper.card_info(card_id, :card_activity => 'no')
9
+ end
10
+
11
+ it "should create card" do
12
+ response = WirecardMapper.create_card
13
+
14
+ response.ok?.should be_true
15
+ response.card_id.should_not be_empty
16
+ response.card_number.should_not be_nil
17
+ response.status_message.should eql('Active card')
18
+ response.status_code.should eql('activated')
19
+ end
20
+
21
+ it "should get card info" do
22
+ response = WirecardMapper.card_info(card_id, :card_activity => 'no')
23
+
24
+ response.ok?.should be_true
25
+ response.card_id.should eql(card_id)
26
+ response.balance.should eql(0)
27
+ end
28
+
29
+ it "should update card info" do
30
+ response = WirecardMapper.update_card_info(card_id)
31
+
32
+ response.ok?.should be_true
33
+ response.return_code.to_i.should eql(0)
34
+ response.return_message.should eql('Successful system entry.')
35
+ end
36
+
37
+ it "should get payment info" do
38
+ response = WirecardMapper.payment_info(card_id, :time_range => {:from => 1.day.ago.iso8601, :to => Time.now.iso8601})
39
+
40
+ response.ok?.should be_true
41
+ response.return_code.to_i.should eql(0)
42
+ response.return_message.should eql('Successful system entry.')
43
+ end
44
+
45
+ describe '#change_card_status' do
46
+ it "should set status" do
47
+ response = WirecardMapper.change_card_status(card_id, :status_code => 'cancelled')
48
+
49
+ response.ok?.should be_true
50
+ response.return_code.to_i.should eql(0)
51
+ response.return_message.should eql('Successful system entry.')
52
+
53
+ card_info.status_code.should eql('cancellation-pending')
54
+ end
55
+
56
+ it "should switch status" do
57
+ response = WirecardMapper.change_card_status(card_id, :status_code => 'blocked')
58
+
59
+ response.ok?.should be_true
60
+ response.return_code.to_i.should eql(0)
61
+ response.return_message.should eql('Successful system entry.')
62
+
63
+ card_info.status_code.should eql('blocked')
64
+
65
+ response = WirecardMapper.change_card_status(card_id, :status_code => 'activated')
66
+
67
+ response.ok?.should be_true
68
+ response.return_code.to_i.should eql(0)
69
+ response.return_message.should eql('Successful system entry.')
70
+
71
+ card_info.status_code.should eql('activated')
72
+ end
73
+ end
74
+
75
+ describe '#submit_payment' do
76
+ it "should load card" do
77
+ response = WirecardMapper.submit_payment(card_id, :payment_data => {:amount => {:text => 2000, :attributes => {:currency => 'EUR'}}})
78
+
79
+ response.ok?.should be_true
80
+ response.return_code.to_i.should eql(0)
81
+ response.return_message.should eql('Successful system entry.')
82
+ response.amount.should eql(2000)
83
+
84
+ card_info.balance.should eql(2000)
85
+ end
86
+
87
+ context "unload" do
88
+ before(:each) do
89
+ WirecardMapper.submit_payment(card_id, :payment_data => {:amount => {:text => 2000, :attributes => {:currency => 'EUR'}}})
90
+ end
91
+
92
+ it "should unload card" do
93
+ response = WirecardMapper.submit_payment(card_id, :payment_data => {:amount => {:text => -1000, :attributes => {:currency => 'EUR'}}})
94
+
95
+ response.ok?.should be_true
96
+ response.return_code.to_i.should eql(0)
97
+ response.return_message.should eql('Successful system entry.')
98
+
99
+ card_info.balance.should eql(1000)
100
+ end
101
+ end
102
+ end
103
+ end
104
+