ruby-saferpay 0.0.4 → 0.0.5
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/Manifest.txt +1 -0
- data/lib/ruby-saferpay.rb +25 -24
- data/lib/ruby-saferpay/version.rb +1 -1
- data/test/test_ruby-saferpay.rb +26 -7
- metadata +2 -1
data/Manifest.txt
CHANGED
data/lib/ruby-saferpay.rb
CHANGED
|
@@ -99,11 +99,11 @@ class Saferpay
|
|
|
99
99
|
Saferpay.check_install
|
|
100
100
|
@current_request = nil
|
|
101
101
|
|
|
102
|
-
@account_id = account_id
|
|
103
|
-
@pan = pan
|
|
104
|
-
@expiry_date= expiry_date
|
|
105
|
-
@cvc = cvc.gsub(/[\s]/,'').chomp
|
|
106
|
-
@name = name.chomp
|
|
102
|
+
@account_id = account_id
|
|
103
|
+
@pan = pan
|
|
104
|
+
@expiry_date= expiry_date
|
|
105
|
+
@cvc = cvc.gsub(/[\s]/,'').chomp rescue ''
|
|
106
|
+
@name = name.chomp rescue ''
|
|
107
107
|
@tolerance = tolerance # Amount tolerance in percent. The finally captured amount is AMOUNT + TOLERANCE
|
|
108
108
|
end
|
|
109
109
|
|
|
@@ -112,8 +112,8 @@ class Saferpay
|
|
|
112
112
|
# 2. Capture
|
|
113
113
|
# 3. Get transacton details
|
|
114
114
|
# 4. Batch clear (needed/wanted? Probably not...) (not implemented)
|
|
115
|
-
def pay(amount, currency = 'EUR' )
|
|
116
|
-
reserve amount, currency
|
|
115
|
+
def pay(amount, currency = 'EUR', back_reference = nil )
|
|
116
|
+
reserve amount, currency, back_reference
|
|
117
117
|
capture
|
|
118
118
|
details
|
|
119
119
|
end
|
|
@@ -125,15 +125,15 @@ class Saferpay
|
|
|
125
125
|
do_direct_cc req.cmd
|
|
126
126
|
end
|
|
127
127
|
|
|
128
|
-
def reserve( amount, currency )
|
|
128
|
+
def reserve( amount, currency, back_reference = nil )
|
|
129
129
|
check_params amount, currency
|
|
130
|
-
@current_request = Request.new(:reserve, :amount => amount, :currency => currency, :accountid => @account_id, :pan => @pan, :exp => @expiry_date)
|
|
130
|
+
@current_request = Request.new(:reserve, :amount => amount, :currency => currency, :accountid => @account_id, :pan => @pan, :exp => @expiry_date, :back_reference => back_reference)
|
|
131
131
|
do_direct_cc( @current_request.cmd )
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
-
def refund( amount, currency )
|
|
134
|
+
def refund( amount, currency, back_reference = nil )
|
|
135
135
|
check_params amount, currency
|
|
136
|
-
@current_request = Request.new(:refund, :amount => amount, :currency => currency, :accountid => @account_id, :pan => @pan, :exp => @expiry_date)
|
|
136
|
+
@current_request = Request.new(:refund, :amount => amount, :currency => currency, :accountid => @account_id, :pan => @pan, :exp => @expiry_date, :back_reference => back_reference)
|
|
137
137
|
do_direct_cc @current_request.cmd
|
|
138
138
|
end
|
|
139
139
|
|
|
@@ -142,23 +142,23 @@ class Saferpay
|
|
|
142
142
|
refund_transaction @current_request.transaction_id
|
|
143
143
|
end
|
|
144
144
|
|
|
145
|
-
def refund_transaction( transaction_id = nil )
|
|
145
|
+
def refund_transaction( transaction_id = nil, back_reference = nil )
|
|
146
146
|
raise ArgumentError, "Cannot refund without transaction_id" if transaction_id.nil?
|
|
147
|
-
@current_request = Request.new(:refund_transaction, :transaction_id => transaction_id)
|
|
147
|
+
@current_request = Request.new(:refund_transaction, :transaction_id => transaction_id, :back_reference => back_reference )
|
|
148
148
|
do_direct_cc @current_request.cmd
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
# Capture the amount of the transaction with id transaction_id
|
|
152
152
|
# Defaults to capturing the current transaction's amount.
|
|
153
|
-
def capture( transaction_id = nil
|
|
153
|
+
def capture( transaction_id = nil )
|
|
154
154
|
transaction_id = @current_request.transaction_id if transaction_id.nil?
|
|
155
155
|
@current_request = Request.new( :capture, :transaction_id => transaction_id )
|
|
156
156
|
do_direct_cc @current_request.cmd
|
|
157
157
|
end
|
|
158
158
|
|
|
159
|
-
def cancel( transaction_id = nil
|
|
159
|
+
def cancel( transaction_id = nil )
|
|
160
160
|
transaction_id = @current_request.transaction_id if transaction_id.nil?
|
|
161
|
-
|
|
161
|
+
raise ArgumentError, "Cancel failed. No transaction to cancel (transaction_id is nil)" if transaction_id.nil?
|
|
162
162
|
@current_request = Request.new( :cancel, :transaction_id => transaction_id )
|
|
163
163
|
do_direct_cc @current_request.cmd
|
|
164
164
|
end
|
|
@@ -167,13 +167,13 @@ class Saferpay
|
|
|
167
167
|
# This will always fail with the test account.
|
|
168
168
|
# Takes an account number (10 digits) and a mysterious 'BLZ' number (8 digits).
|
|
169
169
|
# This is a very common payment method in Germany and Austria
|
|
170
|
-
def debit_card_reserve( amount, currency, account_number, blz )
|
|
170
|
+
def debit_card_reserve( amount, currency, account_number, blz, back_reference = nil )
|
|
171
171
|
check_params amount, currency
|
|
172
172
|
raise AttributeError, "Account number is a ten digit number" unless account_number.length == 10
|
|
173
173
|
raise AttributeError, "BLZ is a eight digit number" unless blz.length == 8
|
|
174
174
|
|
|
175
175
|
track2 = "\";59#{blz}=#{account_number}\"" # Weird, huh?
|
|
176
|
-
@current_request = Request.new(:debit_card_reserve, :amount => amount, :currency => currency, :accountid => @account_id, :track2 => track2 )
|
|
176
|
+
@current_request = Request.new(:debit_card_reserve, :amount => amount, :currency => currency, :accountid => @account_id, :track2 => track2, :back_reference => back_reference )
|
|
177
177
|
do_direct_cc @current_request.cmd
|
|
178
178
|
end
|
|
179
179
|
alias :lastschrift :debit_card_reserve
|
|
@@ -275,7 +275,7 @@ private
|
|
|
275
275
|
raise TransactionError.new(response)
|
|
276
276
|
end
|
|
277
277
|
else
|
|
278
|
-
response = OpenStruct.new(:response => '0',
|
|
278
|
+
response = OpenStruct.new(@current_request.to_hash.merge( {:response => '0', :success => true} ) )
|
|
279
279
|
end
|
|
280
280
|
end
|
|
281
281
|
response
|
|
@@ -349,12 +349,11 @@ private
|
|
|
349
349
|
end
|
|
350
350
|
|
|
351
351
|
class Request
|
|
352
|
-
attr_reader :cmd, :type, :accountid, :account_id, :amount, :currency, :pan, :exp, :expiry_date, :cvc, :track2
|
|
352
|
+
attr_reader :cmd, :type, :accountid, :account_id, :amount, :currency, :pan, :exp, :expiry_date, :cvc, :track2, :back_reference
|
|
353
353
|
attr_accessor :transaction_id, :token
|
|
354
|
+
|
|
354
355
|
def initialize(type = :authorization, args = {})
|
|
355
356
|
logger = Saferpay.logger
|
|
356
|
-
# logger.debug "#{self.class}#initialize ARGS: #{args.inspect}"
|
|
357
|
-
# logger.debug "#{self.class}#initialize #{type.to_s.capitalize}. Required attributes are:...."
|
|
358
357
|
opts = nil
|
|
359
358
|
attrs = nil
|
|
360
359
|
mess = nil
|
|
@@ -394,9 +393,10 @@ private
|
|
|
394
393
|
# Check for missing values and complain; Compile attributes string
|
|
395
394
|
if attrs
|
|
396
395
|
attrs.each{|attr, value|
|
|
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))
|
|
396
|
+
raise AttributeError, "Saferpay::Request#initialize #{type.to_s.capitalize}: missing required parameter \"#{attr}\" (args passed: #{args.inspect})" if(value.nil? || value.to_s.empty? || (value.is_a?(Fixnum) && value == 0))
|
|
398
397
|
}
|
|
399
|
-
attrs =
|
|
398
|
+
attrs = '-a ' + attrs.map{|k,v| "#{k.to_s.upcase} #{v}" }.join(" -a ")
|
|
399
|
+
attrs += " -a ORDERID #{args[:back_reference]} " if args[:back_reference] # Reference to calling app's record for this transaction
|
|
400
400
|
end
|
|
401
401
|
|
|
402
402
|
# TODO: fill all ivars and class_eval them to be attr_reader-able
|
|
@@ -408,6 +408,7 @@ private
|
|
|
408
408
|
@track2 = args[:track2]
|
|
409
409
|
@accountid = args[:accountid]; @account_id = @accountid
|
|
410
410
|
@transaction_id = args[:transaction_id]
|
|
411
|
+
@back_reference = args[:back_reference] # Reference to calling app's record for this transaction
|
|
411
412
|
@type = type
|
|
412
413
|
@cmd = "#{Saferpay::BASEDIR}#{Saferpay::EXECUTABLE} -#{op} -p #{Saferpay::CONFIG} #{message} #{opts} #{attrs}"
|
|
413
414
|
end
|
data/test/test_ruby-saferpay.rb
CHANGED
|
@@ -11,6 +11,11 @@ class SaferpayTest < Test::Unit::TestCase
|
|
|
11
11
|
@sfp = Saferpay.new( @accountid, @pan, @exp )
|
|
12
12
|
@sfp2 = Saferpay.new( @accountid, @pan, @exp )
|
|
13
13
|
end
|
|
14
|
+
def test_pay
|
|
15
|
+
res = @sfp.pay( 4000 )
|
|
16
|
+
assert_is_inquiry_response res
|
|
17
|
+
end
|
|
18
|
+
|
|
14
19
|
|
|
15
20
|
def test_install
|
|
16
21
|
assert_nothing_raised { Saferpay.check_install }
|
|
@@ -32,6 +37,11 @@ class SaferpayTest < Test::Unit::TestCase
|
|
|
32
37
|
res = @sfp.reserve( 300, "USD" )
|
|
33
38
|
assert_is_authorization_response res
|
|
34
39
|
}
|
|
40
|
+
|
|
41
|
+
assert_raise( Saferpay::TransactionError ) {
|
|
42
|
+
sfp = Saferpay.new(@accountid, @pan, "3233")
|
|
43
|
+
sfp.reserve( 12345, "EUR")
|
|
44
|
+
}
|
|
35
45
|
end
|
|
36
46
|
|
|
37
47
|
def test_reserve_with_bad_params
|
|
@@ -86,9 +96,21 @@ class SaferpayTest < Test::Unit::TestCase
|
|
|
86
96
|
end
|
|
87
97
|
|
|
88
98
|
def test_cancel
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
assert_nothing_raised{
|
|
100
|
+
@sfp.reserve( 600, 'EUR' )
|
|
101
|
+
@sfp.capture
|
|
102
|
+
assert @sfp.cancel
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
assert_raise( ArgumentError ) {
|
|
106
|
+
sfp = Saferpay.new(@accountid, @pan, "1107")
|
|
107
|
+
sfp.reserve( 12345, "EUR")
|
|
108
|
+
sfp.capture
|
|
109
|
+
#puts "CAPTURE. sfp.current_request: #{sfp.current_request.inspect}"
|
|
110
|
+
sfp.current_request.transaction_id = nil
|
|
111
|
+
sfp.cancel
|
|
112
|
+
}
|
|
113
|
+
|
|
92
114
|
end
|
|
93
115
|
|
|
94
116
|
def test_debit_card_reserve
|
|
@@ -119,10 +141,7 @@ class SaferpayTest < Test::Unit::TestCase
|
|
|
119
141
|
}
|
|
120
142
|
end
|
|
121
143
|
|
|
122
|
-
|
|
123
|
-
res = @sfp.pay( 4000 )
|
|
124
|
-
assert_is_inquiry_response res
|
|
125
|
-
end
|
|
144
|
+
|
|
126
145
|
|
|
127
146
|
|
|
128
147
|
private
|
metadata
CHANGED
|
@@ -3,7 +3,7 @@ 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.
|
|
6
|
+
version: 0.0.5
|
|
7
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:
|
|
@@ -36,6 +36,7 @@ files:
|
|
|
36
36
|
- bin/ruby-saferpay
|
|
37
37
|
- lib/ruby-saferpay.rb
|
|
38
38
|
- lib/ruby-saferpay/version.rb
|
|
39
|
+
- lib/log
|
|
39
40
|
- test/test_ruby-saferpay.rb
|
|
40
41
|
test_files:
|
|
41
42
|
- test/test_ruby-saferpay.rb
|