ruby-saferpay 0.0.3 → 0.0.4

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.
@@ -87,7 +87,15 @@ class Saferpay
87
87
  attr_accessor :account_id
88
88
  attr_reader :current_request
89
89
 
90
- def initialize( account_id = "99867-94913159", pan = "9451123100000004", expiry_date = '1107', cvc = '', name = '', tolerance = 0 )
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. Batch clear (needed/wanted? Probably not...)
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 ArgumentError, "#{type.to_s.capitalize}: missing required parameter \"#{attr}\"" if(value.nil? || value.to_s.empty? || (value.is_a?(Fixnum) && value == 0))
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
@@ -2,7 +2,7 @@ module RubySaferpay #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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
- # def test_debit_card_reserve
84
- # assert_raise( ArgumentError ) { @sfp.debit_card_reserve }
85
- # assert_raise( Saferpay::TransactionError ) {
86
- # @sfp.debit_card_reserve(100200, "EUR", "1234567890", "12345678")
87
- # assert_is_authorization_response res
88
- # }
89
- # end
90
- #
91
- # def test_details
92
- # assert_raise ( NoMethodError ) { @sfp.details }
93
- # assert_nothing_raised{
94
- # @sfp.reserve( 3000, "USD" )
95
- # @sfp.capture
96
- # @sfp.details
97
- # }
98
- #
99
- # assert_nothing_raised{
100
- # res = @sfp.reserve( 1000, "USD" )
101
- # @sfp.capture
102
- #
103
- # res2 = @sfp.reserve( 1100, "USD" )
104
- # @sfp.capture
105
- #
106
- # assert_not_equal @sfp.details( res.transaction_id ), @sfp.details( res2.transaction_id )
107
- # assert_not_equal @sfp.details( res.transaction_id ), @sfp.details
108
- # }
109
- # end
110
- #
111
- # def test_pay
112
- # res = @sfp.pay( 4000 )
113
- # assert_is_inquiry_response res
114
- # end
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.3
7
- date: 2007-08-15 00:00:00 +02:00
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