ruby-saferpay 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby-saferpay.rb +12 -3
- data/lib/ruby-saferpay/version.rb +1 -1
- data/test/test_ruby-saferpay.rb +44 -33
- metadata +2 -2
data/lib/ruby-saferpay.rb
CHANGED
@@ -87,7 +87,15 @@ class Saferpay
|
|
87
87
|
attr_accessor :account_id
|
88
88
|
attr_reader :current_request
|
89
89
|
|
90
|
-
def
|
90
|
+
def valid_param?(param, conditions)
|
91
|
+
true if param.is_a?( conditions[:class] ) && ( param =~ conditions[:rexp] )
|
92
|
+
end
|
93
|
+
|
94
|
+
# def initialize( account_id = "99867-94913159", pan = "9451123100000004", expiry_date = '1107', cvc = '', name = '', tolerance = 0 )
|
95
|
+
def initialize( account_id, pan, expiry_date, cvc = '', name = '', tolerance = 0 )
|
96
|
+
raise ArgumentError, "Need a valid account_id; was: \"#{account_id}\" (class: #{account_id.class})" unless valid_param?(account_id, {:class => String, :rexp => /^[\d]{5}-[\d]{8}$/})
|
97
|
+
raise ArgumentError, "Need a valid card number; was: \"#{pan}\" (class: #{pan.class})" unless valid_param?(pan, {:class => String, :rexp => /^[\d]{16}$/})
|
98
|
+
raise ArgumentError, "Need a valid expiry_date; was: \"#{expiry_date}\" (class: #{expiry_date.class})" unless valid_param?(expiry_date, {:class => String, :rexp => /^[\d]{4}$/})
|
91
99
|
Saferpay.check_install
|
92
100
|
@current_request = nil
|
93
101
|
|
@@ -102,7 +110,8 @@ class Saferpay
|
|
102
110
|
# Convenience method to:
|
103
111
|
# 1. Authorize (reserve)
|
104
112
|
# 2. Capture
|
105
|
-
# 3.
|
113
|
+
# 3. Get transacton details
|
114
|
+
# 4. Batch clear (needed/wanted? Probably not...) (not implemented)
|
106
115
|
def pay(amount, currency = 'EUR' )
|
107
116
|
reserve amount, currency
|
108
117
|
capture
|
@@ -385,7 +394,7 @@ private
|
|
385
394
|
# Check for missing values and complain; Compile attributes string
|
386
395
|
if attrs
|
387
396
|
attrs.each{|attr, value|
|
388
|
-
raise
|
397
|
+
raise AttributeError, "Saferpay::Request#initialize #{type.to_s.capitalize}: missing required parameter \"#{attr}\"" if(value.nil? || value.to_s.empty? || (value.is_a?(Fixnum) && value == 0))
|
389
398
|
}
|
390
399
|
attrs = '-a ' + attrs.map{|k,v| "#{k.to_s.upcase} #{v}" }.join(" -a ")
|
391
400
|
end
|
data/test/test_ruby-saferpay.rb
CHANGED
@@ -16,6 +16,17 @@ class SaferpayTest < Test::Unit::TestCase
|
|
16
16
|
assert_nothing_raised { Saferpay.check_install }
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_initialize
|
20
|
+
assert_raise( ArgumentError ) { sfp = Saferpay.new() }
|
21
|
+
assert_raise( ArgumentError ) { sfp = Saferpay.new('','','') }
|
22
|
+
assert_raise( ArgumentError ) { sfp = Saferpay.new('32332','32332','') }
|
23
|
+
assert_raise( ArgumentError ) { sfp = Saferpay.new('32332-12345678','1234567891234567','') }
|
24
|
+
assert_raise( ArgumentError ) { sfp = Saferpay.new('32332-12345678','1234567891234567','12345') }
|
25
|
+
assert_raise( ArgumentError ) { sfp = Saferpay.new('32332-12345678',1234567891234567,'1234') }
|
26
|
+
assert_nothing_raised { sfp = Saferpay.new('32332-12345678','1234567891234567','1212') }
|
27
|
+
end
|
28
|
+
|
29
|
+
|
19
30
|
def test_reserve
|
20
31
|
assert_nothing_raised{
|
21
32
|
res = @sfp.reserve( 300, "USD" )
|
@@ -79,39 +90,39 @@ class SaferpayTest < Test::Unit::TestCase
|
|
79
90
|
@sfp.capture
|
80
91
|
assert @sfp.cancel
|
81
92
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
93
|
+
|
94
|
+
def test_debit_card_reserve
|
95
|
+
assert_raise( ArgumentError ) { @sfp.debit_card_reserve }
|
96
|
+
assert_raise( Saferpay::TransactionError ) {
|
97
|
+
@sfp.debit_card_reserve(100200, "EUR", "1234567890", "12345678")
|
98
|
+
assert_is_authorization_response res
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_details
|
103
|
+
assert_raise ( NoMethodError ) { @sfp.details }
|
104
|
+
assert_nothing_raised{
|
105
|
+
@sfp.reserve( 3000, "USD" )
|
106
|
+
@sfp.capture
|
107
|
+
@sfp.details
|
108
|
+
}
|
109
|
+
|
110
|
+
assert_nothing_raised{
|
111
|
+
res = @sfp.reserve( 1000, "USD" )
|
112
|
+
@sfp.capture
|
113
|
+
|
114
|
+
res2 = @sfp.reserve( 1100, "USD" )
|
115
|
+
@sfp.capture
|
116
|
+
|
117
|
+
assert_not_equal @sfp.details( res.transaction_id ), @sfp.details( res2.transaction_id )
|
118
|
+
assert_not_equal @sfp.details( res.transaction_id ), @sfp.details
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_pay
|
123
|
+
res = @sfp.pay( 4000 )
|
124
|
+
assert_is_inquiry_response res
|
125
|
+
end
|
115
126
|
|
116
127
|
|
117
128
|
private
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-saferpay
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-08-
|
6
|
+
version: 0.0.4
|
7
|
+
date: 2007-08-17 00:00:00 +02:00
|
8
8
|
summary: Ruby interface to the saferpay e-commerce payment provider
|
9
9
|
require_paths:
|
10
10
|
- lib
|