realex 0.4 → 0.4.1

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/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gem 'nokogiri'
3
3
  gem 'builder'
4
4
 
@@ -1,5 +1,5 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
4
  builder (3.0.0)
5
5
  diff-lcs (1.1.3)
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ begin
25
25
  gemspec.email = "paul@rslw.com"
26
26
  gemspec.homepage = "http://github.com/paulca/realex"
27
27
  gemspec.authors = ["Paul Campbell"]
28
- gemspec.version = "0.4"
28
+ gemspec.version = "0.4.1"
29
29
  gemspec.add_dependency 'nokogiri', '~> 1.4'
30
30
  end
31
31
  rescue LoadError
@@ -1,20 +1,20 @@
1
1
  module RealEx
2
2
  module Recurring
3
-
3
+
4
4
  class Transaction < RealEx::Transaction
5
5
  def authorize!
6
6
  RealEx::Response.new_from_xml(RealEx::Client.call(real_vault_uri, to_xml))
7
7
  end
8
8
  end
9
-
9
+
10
10
  class Payer < Transaction
11
11
  attributes :type, :reference, :title, :firstname, :lastname, :address, :company, :comments
12
12
  attributes :update
13
-
13
+
14
14
  def request_type
15
15
  @request_type = update == true ? 'payer-edit' : 'payer-new'
16
16
  end
17
-
17
+
18
18
  def to_xml
19
19
  super do |per|
20
20
  per.payer(:type => type, :ref => reference) do |payer|
@@ -22,27 +22,31 @@ module RealEx
22
22
  payer.firstname firstname
23
23
  payer.surname lastname
24
24
  payer.company company
25
- payer.address do |add|
26
- add.line1 address.line1
27
- add.line1 address.line2
28
- add.line3 address.line3
29
- add.city address.city
30
- add.county address.county
31
- add.postcode address.post_code
32
- add.country(address.country, :country_code => address.country_code)
33
- end
34
- if address.phone_numbers.kind_of?(Hash)
35
- payer.phonenumbers do |numbers|
36
- numbers.home address.phone_numbers[:home]
37
- numbers.work address.phone_numbers[:work]
38
- numbers.fax address.phone_numbers[:fax]
39
- numbers.mobile address.phone_numbers[:mobile]
25
+
26
+ unless address.nil?
27
+ payer.address do |add|
28
+ add.line1 address.line1
29
+ add.line1 address.line2
30
+ add.line3 address.line3
31
+ add.city address.city
32
+ add.county address.county
33
+ add.postcode address.post_code
34
+ add.country(address.country, :country_code => address.country_code)
40
35
  end
36
+ if address.phone_numbers.kind_of?(Hash)
37
+ payer.phonenumbers do |numbers|
38
+ numbers.home address.phone_numbers[:home]
39
+ numbers.work address.phone_numbers[:work]
40
+ numbers.fax address.phone_numbers[:fax]
41
+ numbers.mobile address.phone_numbers[:mobile]
42
+ end
43
+ end
44
+ payer.email address.email
41
45
  end
42
- payer.email address.email
46
+
43
47
  if !comments.empty?
44
48
  payer.comments do |c|
45
- comments.each_with_index do |i,comment|
49
+ comments.each_with_index do |comment,i|
46
50
  c.comment(comment, :id => i + 1)
47
51
  end
48
52
  end
@@ -55,18 +59,18 @@ module RealEx
55
59
  def hash
56
60
  RealEx::Client.build_hash([RealEx::Client.timestamp, RealEx::Config.merchant_id, order_id, '', '', reference])
57
61
  end
58
-
62
+
59
63
  def save!
60
64
  authorize!
61
65
  end
62
-
66
+
63
67
  def update!
64
68
  self.update = true
65
69
  authorize!
66
70
  end
67
71
 
68
72
  end
69
-
73
+
70
74
  class Card < Transaction
71
75
  attributes :card, :payer, :update, :reference, :cancel
72
76
 
@@ -79,7 +83,7 @@ module RealEx
79
83
  @request_type = 'card-new'
80
84
  end
81
85
  end
82
-
86
+
83
87
  def to_xml
84
88
  super do |per|
85
89
  per.card do |c|
@@ -95,7 +99,7 @@ module RealEx
95
99
  end
96
100
  end
97
101
  end
98
-
102
+
99
103
  # 20030516181127.yourmerchantid.uniqueid…smithj01.John Smith.498843******9991
100
104
  def hash
101
105
  if cancel
@@ -106,11 +110,11 @@ module RealEx
106
110
  RealEx::Client.build_hash([RealEx::Client.timestamp, RealEx::Config.merchant_id, order_id, '', '', payer.reference,card.cardholder_name,card.number])
107
111
  end
108
112
  end
109
-
113
+
110
114
  def save!
111
115
  authorize!
112
116
  end
113
-
117
+
114
118
  def update!
115
119
  self.update = true
116
120
  authorize!
@@ -122,15 +126,15 @@ module RealEx
122
126
  end
123
127
 
124
128
  end
125
-
129
+
126
130
  class Authorization < Transaction
127
131
  attributes :payer, :reference, :customer_number, :variable_reference, :product_id
128
132
  attributes :billing_address, :shipping_address
129
-
133
+
130
134
  def request_type
131
135
  'receipt-in'
132
136
  end
133
-
137
+
134
138
  def to_xml
135
139
  super do |per|
136
140
  per.amount(amount, :currency => currency)
@@ -157,13 +161,13 @@ module RealEx
157
161
  end
158
162
  end
159
163
  end
160
-
164
+
161
165
  # timesttimestamp.merchantid.orderid.amount.currency.payerref
162
166
  def hash
163
167
  RealEx::Client.build_hash([RealEx::Client.timestamp, RealEx::Config.merchant_id, order_id, amount, currency, payer.reference])
164
- end
168
+ end
165
169
  end
166
-
170
+
167
171
  class Refund < Transaction
168
172
  attributes :payer, :reference
169
173
 
@@ -183,10 +187,10 @@ module RealEx
183
187
  def hash
184
188
  RealEx::Client.build_hash([RealEx::Client.timestamp, RealEx::Config.merchant_id, order_id, amount, currency, payer.reference])
185
189
  end
186
-
190
+
187
191
  def refund_hash
188
192
  Digest::SHA1.hexdigest(RealEx::Config.refund_password)
189
193
  end
190
194
  end
191
195
  end
192
- end
196
+ end
@@ -1,7 +1,7 @@
1
1
  module RealEx
2
2
  class Transaction
3
3
  include Initializer
4
- attributes :card, :amount, :order_id, :currency, :autosettle, :variable_reference, :remote_uri, :real_vault_uri
4
+ attributes :card, :amount, :order_id, :currency, :autosettle, :variable_reference, :remote_uri, :real_vault_uri, :account
5
5
  attr_accessor :comments
6
6
  attr_accessor :authcode, :pasref
7
7
 
@@ -14,6 +14,7 @@ module RealEx
14
14
  self.currency ||= RealEx::Config.currency || 'EUR'
15
15
  self.remote_uri ||= RealEx::Config.remote_uri || '/epage-remote.cgi'
16
16
  self.real_vault_uri ||= RealEx::Config.real_vault_uri || '/epage-remote-plugins.cgi'
17
+ self.account ||= RealEx::Config.account
17
18
  end
18
19
 
19
20
  def request_type
@@ -30,14 +31,14 @@ module RealEx
30
31
  r.orderid order_id
31
32
  r.authcode authcode if authcode
32
33
  r.pasref pasref if pasref
33
- r.account RealEx::Config.account
34
+ r.account account
34
35
  if block_given?
35
36
  block.call(r)
36
37
  end
37
38
  if !comments.empty?
38
39
  r.comments do |c|
39
- comments.each_with_index do |index,comment|
40
- c.comment(comment, :id => index)
40
+ comments.each_with_index do |comment,index|
41
+ c.comment(comment, :id => index + 1)
41
42
  end
42
43
  end
43
44
  end
@@ -157,8 +158,8 @@ module RealEx
157
158
  per.refundhash refund_hash
158
159
  if !comments.empty?
159
160
  per.comments do |c|
160
- comments.each_with_index do |index,comment|
161
- c.comment(comment, :id => index)
161
+ comments.each_with_index do |comment,index|
162
+ c.comment(comment, :id => index + 1)
162
163
  end
163
164
  end
164
165
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "realex"
8
- s.version = "0.4"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Paul Campbell"]
12
- s.date = "2012-03-15"
12
+ s.date = "2013-05-30"
13
13
  s.description = "A Ruby library to make use of the payments API at http://realexpayments.com"
14
14
  s.email = "paul@rslw.com"
15
15
  s.extra_rdoc_files = [
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  ]
43
43
  s.homepage = "http://github.com/paulca/realex"
44
44
  s.require_paths = ["lib"]
45
- s.rubygems_version = "1.8.15"
45
+ s.rubygems_version = "1.8.23"
46
46
  s.summary = "Ruby interface to http://realexpayments.com"
47
47
 
48
48
  if s.respond_to? :specification_version then
@@ -35,20 +35,20 @@ describe "RealEx::Recurring" do
35
35
  )
36
36
  RealEx::Client.stub!(:timestamp).and_return('20090326160218')
37
37
  end
38
-
38
+
39
39
  it "should create tasty XML for the payer" do
40
40
  @payer.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request type=\"payer-new\" timestamp=\"20090326160218\">\n <merchantid>paul</merchantid>\n <orderid></orderid>\n <account>internet</account>\n <payer type=\"Business\" ref=\"boom\">\n <title>Mr.</title>\n <firstname>Paul</firstname>\n <surname>Campbell</surname>\n <company>Contrast</company>\n <address>\n <line1>My house</line1>\n <line1></line1>\n <line3></line3>\n <city>Dublin</city>\n <county>Dublin</county>\n <postcode>Dublin 2</postcode>\n <country country_code=\"IE\">Ireland</country>\n </address>\n <phonenumbers>\n <home>1</home>\n <work>2</work>\n <fax>3</fax>\n <mobile>4</mobile>\n </phonenumbers>\n <email>paul@contrast.ie</email>\n </payer>\n <sha1hash>7e97b1b743c2599b6c1fd0c5515d369d8372df15</sha1hash>\n</request>\n"
41
41
  end
42
-
42
+
43
43
  it "should create tasty XML for the payer update" do
44
44
  @payer.update = true
45
45
  @payer.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request type=\"payer-edit\" timestamp=\"20090326160218\">\n <merchantid>paul</merchantid>\n <orderid></orderid>\n <account>internet</account>\n <payer type=\"Business\" ref=\"boom\">\n <title>Mr.</title>\n <firstname>Paul</firstname>\n <surname>Campbell</surname>\n <company>Contrast</company>\n <address>\n <line1>My house</line1>\n <line1></line1>\n <line3></line3>\n <city>Dublin</city>\n <county>Dublin</county>\n <postcode>Dublin 2</postcode>\n <country country_code=\"IE\">Ireland</country>\n </address>\n <phonenumbers>\n <home>1</home>\n <work>2</work>\n <fax>3</fax>\n <mobile>4</mobile>\n </phonenumbers>\n <email>paul@contrast.ie</email>\n </payer>\n <sha1hash>7e97b1b743c2599b6c1fd0c5515d369d8372df15</sha1hash>\n</request>\n"
46
46
  end
47
-
47
+
48
48
  it "should create lovely XML for the card" do
49
49
  @card.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request type=\"card-new\" timestamp=\"20090326160218\">\n <merchantid>paul</merchantid>\n <orderid></orderid>\n <account>internet</account>\n <card>\n <ref>billabong</ref>\n <payerref>boom</payerref>\n <number>4111111111111111</number>\n <expdate>0802</expdate>\n <chname>Paul Campbell</chname>\n <type>VISA</type>\n </card>\n <sha1hash>24dc62271ccaddc59082b4db45c80b0241f630f7</sha1hash>\n</request>\n"
50
50
  end
51
-
51
+
52
52
  it "should create lovely XML for the card update" do
53
53
  @card.update = true
54
54
  @card.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request type=\"card-update-card\" timestamp=\"20090326160218\">\n <merchantid>paul</merchantid>\n <orderid></orderid>\n <account>internet</account>\n <card>\n <ref>billabong</ref>\n <payerref>boom</payerref>\n <number>4111111111111111</number>\n <expdate>0802</expdate>\n <chname>Paul Campbell</chname>\n <type>VISA</type>\n </card>\n <sha1hash>cdcb4dd95d0d61d7c86685b1e465796ea55bdcea</sha1hash>\n</request>\n"
@@ -62,7 +62,7 @@ describe "RealEx::Recurring" do
62
62
  it "should create tasty XML for the authorization" do
63
63
  @transaction.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request type=\"receipt-in\" timestamp=\"20090326160218\">\n <merchantid>paul</merchantid>\n <orderid>1234</orderid>\n <account>internet</account>\n <amount currency=\"EUR\">500</amount>\n <payerref>boom</payerref>\n <paymentmethod></paymentmethod>\n <sha1hash>ec3afd1714b4473210c2b1eda0c6675bd13c411b</sha1hash>\n</request>\n"
64
64
  end
65
-
65
+
66
66
  it "should create tasty XML for the refund" do
67
67
  @refund.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request type=\"payment-out\" timestamp=\"20090326160218\">\n <merchantid>paul</merchantid>\n <orderid>1234</orderid>\n <account>internet</account>\n <amount currency=\"EUR\">500</amount>\n <payerref>boom</payerref>\n <paymentmethod></paymentmethod>\n <refundhash>5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8</refundhash>\n <sha1hash>ec3afd1714b4473210c2b1eda0c6675bd13c411b</sha1hash>\n</request>\n"
68
68
  end
@@ -85,8 +85,30 @@ describe "RealEx::Recurring without a full address" do
85
85
  @payer = RealEx::Recurring::Payer.new(:type => 'Business', :reference => 'boom', :title => 'Mr.', :firstname => 'Paul', :lastname => 'Campbell', :company => 'Contrast')
86
86
  @payer.address = RealEx::Address.new(:country => 'Ireland', :country_code => 'IE')
87
87
  end
88
-
88
+
89
89
  it "should convert the payer" do
90
90
  @payer.to_xml.should match(/IE/)
91
91
  end
92
- end
92
+ end
93
+
94
+ describe "RealEx::Recurring without any address" do
95
+ before do
96
+ RealEx::Config.merchant_id = 'paul'
97
+ RealEx::Config.shared_secret = "He's not dead, he's just asleep!"
98
+ RealEx::Config.account = 'internet'
99
+
100
+ @card = RealEx::Card.new(
101
+ :number => '4111111111111111',
102
+ :cvv => '509',
103
+ :expiry_date => '0802',
104
+ :cardholder_name => 'Paul Campbell',
105
+ :type => 'VISA',
106
+ :issue_number => nil
107
+ )
108
+ @payer = RealEx::Recurring::Payer.new(:type => 'Business', :reference => 'boom', :title => 'Mr.', :firstname => 'Paul', :lastname => 'Campbell', :company => 'Contrast')
109
+ end
110
+
111
+ it "should convert the payer" do
112
+ @payer.to_xml.should match(/Paul/)
113
+ end
114
+ end
@@ -33,6 +33,18 @@ describe "RealEx::Transaction" do
33
33
  @transaction.comments.should == ["This is a comment"]
34
34
  end
35
35
 
36
+ it "should allow overriding of the account" do
37
+ @transaction = RealEx::Authorization.new(
38
+ :card => @card,
39
+ :amount => 500,
40
+ :order_id => 1234,
41
+ :currency => 'EUR',
42
+ :autosettle => true,
43
+ :account => "override"
44
+ )
45
+ @transaction.account.should == "override"
46
+ end
47
+
36
48
  it "should build the xml" do
37
49
  @transaction.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request type=\"auth\" timestamp=\"20090326160218\">\n <merchantid>paul</merchantid>\n <orderid>1234</orderid>\n <account>internet</account>\n <amount currency=\"EUR\">500</amount>\n <card>\n <number>4111111111111111</number>\n <expdate>0802</expdate>\n <chname>Paul Campbell</chname>\n <type>VISA</type>\n </card>\n <autosettle flag=\"1\"/>\n <tssinfo>\n </tssinfo>\n <sha1hash>d979885b0a296469d85ada0f08c5577d857142a0</sha1hash>\n</request>\n"
38
50
  end
metadata CHANGED
@@ -1,60 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realex
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
5
4
  prerelease:
5
+ version: 0.4.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paul Campbell
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-15 00:00:00.000000000 Z
12
+ date: 2013-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: nokogiri
16
- requirement: &70166167360980 !ruby/object:Gem::Requirement
15
+ type: :runtime
16
+ version_requirements: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :runtime
22
+ name: nokogiri
23
23
  prerelease: false
24
- version_requirements: *70166167360980
25
- - !ruby/object:Gem::Dependency
26
- name: builder
27
- requirement: &70166167360460 !ruby/object:Gem::Requirement
24
+ requirement: !ruby/object:Gem::Requirement
28
25
  none: false
29
26
  requirements:
30
27
  - - ! '>='
31
28
  - !ruby/object:Gem::Version
32
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
33
31
  type: :runtime
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ name: builder
34
39
  prerelease: false
35
- version_requirements: *70166167360460
36
- - !ruby/object:Gem::Dependency
37
- name: jeweler
38
- requirement: &70166167359960 !ruby/object:Gem::Requirement
40
+ requirement: !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
41
43
  - - ! '>='
42
44
  - !ruby/object:Gem::Version
43
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
44
47
  type: :development
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ name: jeweler
45
55
  prerelease: false
46
- version_requirements: *70166167359960
56
+ requirement: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
- name: nokogiri
49
- requirement: &70166167359440 !ruby/object:Gem::Requirement
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
53
68
  - !ruby/object:Gem::Version
54
69
  version: '1.4'
55
- type: :runtime
70
+ name: nokogiri
56
71
  prerelease: false
57
- version_requirements: *70166167359440
72
+ requirement: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.4'
58
78
  description: A Ruby library to make use of the payments API at http://realexpayments.com
59
79
  email: paul@rslw.com
60
80
  executables: []
@@ -96,6 +116,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
116
  requirements:
97
117
  - - ! '>='
98
118
  - !ruby/object:Gem::Version
119
+ segments:
120
+ - 0
121
+ hash: -150098097176807892
99
122
  version: '0'
100
123
  required_rubygems_version: !ruby/object:Gem::Requirement
101
124
  none: false
@@ -105,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
128
  version: '0'
106
129
  requirements: []
107
130
  rubyforge_project:
108
- rubygems_version: 1.8.15
131
+ rubygems_version: 1.8.23
109
132
  signing_key:
110
133
  specification_version: 3
111
134
  summary: Ruby interface to http://realexpayments.com