clieop 0.1.1 → 0.1.3
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/MIT-LICENSE +2 -2
- data/README.rdoc +1 -1
- data/clieop.gemspec +4 -4
- data/doc/clieop03.pdf +0 -0
- data/init.rb +1 -0
- data/lib/clieop/batch.rb +15 -9
- data/lib/clieop/record.rb +11 -11
- data/lib/clieop.rb +5 -0
- data/spec/clieop/batch_spec.rb +51 -0
- data/spec/clieop/record_spec.rb +88 -0
- data/{test/clieop_writer_test.rb → spec/clieop_spec.rb} +15 -14
- data/spec/spec_helper.rb +10 -0
- metadata +28 -9
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2008-
|
1
|
+
Copyright (c) 2008-2010 Willem van Bergen & Leon Berenschot
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -20,7 +20,7 @@ http://www.ingbank.nl/ing/downloadables/eclieop1.pdf
|
|
20
20
|
|
21
21
|
== Usage
|
22
22
|
|
23
|
-
Run <tt>gem install clieop
|
23
|
+
Run <tt>gem install clieop</tt> to install the gem.
|
24
24
|
|
25
25
|
See the project's wiki at http://wiki.github.com/wvanbergen/clieop for an example
|
26
26
|
creating and writing a direct debt batch file.
|
data/clieop.gemspec
CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
3
3
|
|
4
4
|
# Do not set version and date yourself, this will be done automatically
|
5
5
|
# by the gem release script.
|
6
|
-
s.version = "0.1.
|
7
|
-
s.date = "
|
6
|
+
s.version = "0.1.3"
|
7
|
+
s.date = "2010-06-02"
|
8
8
|
|
9
9
|
s.summary = "A pure Ruby implementation to write CLIEOP files"
|
10
10
|
s.description = "This library is a pure Ruby, MIT licensed implementation of the CLIEOP03 transaction format. CLIEOP03 can be used to communicate direct debt transactions with your (Dutch) bank."
|
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
# Do not set files and test_files yourself, this will be done automatically
|
17
17
|
# by the gem release script.
|
18
|
-
s.files = %w(.gitignore lib/clieop/record.rb lib/clieop/file.rb lib/clieop/batch.rb lib/clieop.rb Rakefile
|
19
|
-
s.test_files = %w(
|
18
|
+
s.files = %w(spec/spec_helper.rb spec/clieop/batch_spec.rb .gitignore lib/clieop/record.rb MIT-LICENSE doc/clieop03.pdf lib/clieop/file.rb lib/clieop/batch.rb lib/clieop.rb init.rb Rakefile clieop.gemspec README.rdoc tasks/github-gem.rake spec/clieop_spec.rb spec/clieop/record_spec.rb)
|
19
|
+
s.test_files = %w(spec/clieop/batch_spec.rb spec/clieop_spec.rb spec/clieop/record_spec.rb)
|
20
20
|
end
|
data/doc/clieop03.pdf
ADDED
Binary file
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'clieop'
|
data/lib/clieop/batch.rb
CHANGED
@@ -48,17 +48,17 @@ module Clieop
|
|
48
48
|
# add transactions to batch
|
49
49
|
@transactions.each do |tr|
|
50
50
|
|
51
|
-
# update checksums
|
52
|
-
total_account += tr[:account_nr].to_i
|
53
|
-
total_amount += (tr[:amount].to_f * 100).truncate
|
54
|
-
|
55
51
|
# prepare data for this transaction's records
|
56
|
-
transaction_type = @batch_info[:transaction_group] == 10 ? 1002 : 0
|
52
|
+
transaction_type = tr[:transaction_type] || (@batch_info[:transaction_group] == 10 ? 1002 : 0)
|
57
53
|
to_account = @batch_info[:transaction_group] == 10 ? @batch_info[:account_nr] : tr[:account_nr]
|
58
54
|
from_account = @batch_info[:transaction_group] == 10 ? tr[:account_nr] : @batch_info[:account_nr]
|
59
|
-
amount_in_cents = (tr[:amount]
|
55
|
+
amount_in_cents = (tr[:amount] * 100).round.to_i
|
60
56
|
name_record = @batch_info[:transaction_group] == 10 ? :invoice_name : :payment_name
|
61
57
|
|
58
|
+
# update checksums
|
59
|
+
total_account += tr[:account_nr].to_i
|
60
|
+
total_amount += amount_in_cents
|
61
|
+
|
62
62
|
# generate transaction record
|
63
63
|
batch_data << Clieop::Record.new(:transaction_info,
|
64
64
|
:transaction_type => transaction_type, :amount => amount_in_cents,
|
@@ -70,15 +70,15 @@ module Clieop
|
|
70
70
|
|
71
71
|
# split discription into lines and make a record for the first 4 lines
|
72
72
|
unless tr[:description].nil? || tr[:description] == ''
|
73
|
-
tr[:description].split(/\r?\n/)[0, 4].each do |line|
|
73
|
+
tr[:description].split(/\r?\n/)[0, 4].each do |line| # FIXME raise warning when line is longer than 32 chars/description longer than 4 lines
|
74
74
|
batch_data << Clieop::Record.new(:transaction_description, :description => line.strip).to_s unless line == ''
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
# generate batch footer record including some checks
|
80
|
-
batch_data << Clieop::Record.new(:batch_footer, :
|
81
|
-
:total_amount => total_amount, :account_checksum => total_account
|
80
|
+
batch_data << Clieop::Record.new(:batch_footer, :transaction_count => @transactions.length,
|
81
|
+
:total_amount => total_amount, :account_checksum => account_checksum(total_account)).to_clieop
|
82
82
|
|
83
83
|
end
|
84
84
|
|
@@ -98,5 +98,11 @@ module Clieop
|
|
98
98
|
Clieop::Batch.new(batch_info)
|
99
99
|
end
|
100
100
|
|
101
|
+
# the checksum on the total of accounts is in fact the last 10 chars of total amount
|
102
|
+
def account_checksum(total)
|
103
|
+
total.to_s.split('').last(10).join('') # ruby 1.8.6
|
104
|
+
# total.to_s.chars.last(10).join('') # ruby 1.8.7
|
105
|
+
end
|
106
|
+
|
101
107
|
end
|
102
108
|
end
|
data/lib/clieop/record.rb
CHANGED
@@ -8,9 +8,9 @@ module Clieop
|
|
8
8
|
[:record_variant, :alpha, 1, 'A'],
|
9
9
|
[:date, :numeric, 6],
|
10
10
|
[:filename, :alpha, 8, 'CLIEOP03'],
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
[:sender_identification, :alpha, 5],
|
12
|
+
[:file_identification, :alpha, 4],
|
13
|
+
[:duplicate_code, :numeric, 1, 1]
|
14
14
|
],
|
15
15
|
:file_footer => [
|
16
16
|
[:record_code, :numeric, 4, 9999],
|
@@ -29,7 +29,7 @@ module Clieop
|
|
29
29
|
[:record_variant, :alpha, 1, 'A'],
|
30
30
|
[:total_amount, :numeric, 18],
|
31
31
|
[:account_checksum, :numeric, 10],
|
32
|
-
[:
|
32
|
+
[:transaction_count, :numeric, 7],
|
33
33
|
],
|
34
34
|
:batch_description => [
|
35
35
|
[:record_code, :numeric, 4, 20],
|
@@ -47,7 +47,7 @@ module Clieop
|
|
47
47
|
:transaction_info => [
|
48
48
|
[:record_code, :numeric, 4, 100],
|
49
49
|
[:record_variant, :alpha, 1, 'A'],
|
50
|
-
[:transaction_type, :
|
50
|
+
[:transaction_type, :alpha, 4, "1002"],
|
51
51
|
[:amount, :numeric, 12],
|
52
52
|
[:from_account, :numeric, 10],
|
53
53
|
[:to_account, :numeric, 10],
|
@@ -65,14 +65,14 @@ module Clieop
|
|
65
65
|
:transaction_reference => [
|
66
66
|
[:record_code, :numeric, 4, 150],
|
67
67
|
[:record_variant, :alpha, 1, 'A'],
|
68
|
-
[:reference_number, :
|
68
|
+
[:reference_number, :alpha, 16],
|
69
69
|
],
|
70
70
|
:transaction_description => [
|
71
71
|
[:record_code, :numeric, 4, 160],
|
72
72
|
[:record_variant, :alpha, 1, 'A'],
|
73
73
|
[:description, :alpha, 32],
|
74
74
|
],
|
75
|
-
|
75
|
+
}
|
76
76
|
|
77
77
|
attr_accessor :definition, :data
|
78
78
|
|
@@ -95,10 +95,10 @@ module Clieop
|
|
95
95
|
#format each field
|
96
96
|
@definition.each do |field|
|
97
97
|
fmt = '%'
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
fmt << (field[1] == :numeric ? '0' : '-')
|
99
|
+
fmt << (field[2].to_s)
|
100
|
+
fmt << (field[1] == :numeric ? 'd' : 's')
|
101
|
+
raw_data = (field[1] == :numeric) ? @data[field[0]].to_i : @data[field[0]]
|
102
102
|
value = sprintf(fmt, raw_data)
|
103
103
|
line << (field[1] == :numeric ? value[0 - field[2], field[2]] : value[0, field[2]])
|
104
104
|
end
|
data/lib/clieop.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Clieop::Batch do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@batch_info = {
|
7
|
+
:description => "Batch" ,
|
8
|
+
:account_nr => 123456789,
|
9
|
+
:account_owner => "Reciever"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should generate valid object" do
|
14
|
+
Clieop::Batch.new(@batch_info.dup).class.should eql(Clieop::Batch)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should generate a invoice batch" do
|
18
|
+
batch = Clieop::Batch.invoice_batch(@batch_info.dup)
|
19
|
+
batch.class.should eql(Clieop::Batch)
|
20
|
+
batch.batch_info[:transaction_group].should eql(10)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should generate a payment batch" do
|
24
|
+
batch = Clieop::Batch.payment_batch(@batch_info.dup)
|
25
|
+
batch.class.should eql(Clieop::Batch)
|
26
|
+
batch.batch_info[:transaction_group].should eql(0)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should add transactions to batch" do
|
30
|
+
batch = Clieop::Batch.invoice_batch(@batch_info.dup)
|
31
|
+
batch << {
|
32
|
+
:reference_number => "Factnr 100101",
|
33
|
+
:account_nr => 123456789,
|
34
|
+
:account_owner => 'Payee',
|
35
|
+
:amount => 30102,
|
36
|
+
:description => "Testing a CLIEOP direct debt transaction\nCharging your bank account",
|
37
|
+
:transaction_type => 1001
|
38
|
+
}
|
39
|
+
batch.batch_info[:transaction_group].should eql(10)
|
40
|
+
batch.to_clieop.should match(/0010B1001234567890001EUR /)
|
41
|
+
batch.to_clieop.should match(/0020ABatch /)
|
42
|
+
batch.to_clieop.should match(/0030B1000000Reciever P /)
|
43
|
+
batch.to_clieop.should match(/0100A100100000301020001234567890123456789 /)
|
44
|
+
batch.to_clieop.should match(/0110BPayee /)
|
45
|
+
batch.to_clieop.should match(/0150AFactnr 100101 /)
|
46
|
+
batch.to_clieop.should match(/0160ATesting a CLIEOP direct debt tra /)
|
47
|
+
batch.to_clieop.should match(/0160ACharging your bank account /)
|
48
|
+
batch.to_clieop.should match(/9990A00000000000301020002469135780000001 /)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Clieop::Record do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should generate :file_header" do
|
9
|
+
record = Clieop::Record.new(:file_header, :date => '050410')
|
10
|
+
record.to_clieop.should match(/0001A050410CLIEOP03 1 /)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should generate :file_footer" do
|
14
|
+
record = Clieop::Record.new(:file_footer)
|
15
|
+
record.to_clieop.should match(/9999A /)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should generate :batch_header" do
|
19
|
+
record = Clieop::Record.new(:batch_header,
|
20
|
+
:transaction_group => 10,
|
21
|
+
:acount_nr => 1234567890,
|
22
|
+
:serial_nr => 1
|
23
|
+
)
|
24
|
+
record.to_clieop.should match(/0010B1012345678900001EUR /)
|
25
|
+
end
|
26
|
+
|
27
|
+
# TODO Also do calculations
|
28
|
+
it "should generate :batch_footer" do
|
29
|
+
record = Clieop::Record.new(:batch_footer,
|
30
|
+
:total_amount => 0,
|
31
|
+
:account_checksum => 1234567890,
|
32
|
+
:tranasction_count => 0
|
33
|
+
)
|
34
|
+
record.to_clieop.should match(/9990A00000000000000000012345678900000000 /)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should generate :batch_description" do
|
38
|
+
record = Clieop::Record.new(:batch_description,
|
39
|
+
:description => 'Testing a CLIEOP direct debt transaction\nCharging your bank account'
|
40
|
+
)
|
41
|
+
record.to_clieop.should match(/0020ATesting a CLIEOP direct debt tra /)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should generate :batch_owner" do
|
45
|
+
record = Clieop::Record.new(:batch_owner,
|
46
|
+
:owner => 'Reciever'
|
47
|
+
)
|
48
|
+
record.to_clieop.should match(/0030B1000000Reciever P /)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should generate :transaction_info" do
|
52
|
+
record = Clieop::Record.new(:transaction_info,
|
53
|
+
:amount => 'Reciever',
|
54
|
+
:from_account => 1234567890,
|
55
|
+
:to_account => 1234567890
|
56
|
+
)
|
57
|
+
record.to_clieop.should match(/0100A100200000000000012345678901234567890 /)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should generate :invoice_name" do
|
61
|
+
record = Clieop::Record.new(:invoice_name,
|
62
|
+
:name => 'Payee'
|
63
|
+
)
|
64
|
+
record.to_clieop.should match(/0110BPayee /)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should generate :payment_name" do
|
68
|
+
record = Clieop::Record.new(:payment_name,
|
69
|
+
:name => 'Reciever'
|
70
|
+
)
|
71
|
+
record.to_clieop.should match(/0170BReciever /)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should generate :transaction_reference" do
|
75
|
+
record = Clieop::Record.new(:transaction_reference,
|
76
|
+
:reference_number => '201000505'
|
77
|
+
)
|
78
|
+
record.to_clieop.should match(/0150A201000505 /)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should generate :transaction_description" do
|
82
|
+
record = Clieop::Record.new(:transaction_description,
|
83
|
+
:description => 'Automatic Invoice Transaction'
|
84
|
+
)
|
85
|
+
record.to_clieop.should match(/0160AAutomatic Invoice Transaction /)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -1,22 +1,16 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
require 'clieop'
|
3
|
+
describe Clieop do
|
5
4
|
|
6
|
-
|
5
|
+
it "should test basic invoice usage" do
|
7
6
|
|
8
|
-
def setup
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_basic_invoice_usage
|
15
7
|
file = Clieop::File.new
|
8
|
+
|
16
9
|
file.invoice_batch({:description => 'some description', :account_nr => 123, :account_owner => 'me'}) do |batch|
|
17
10
|
|
18
11
|
batch << { :account_nr => 123456, :account_owner => 'you', :amount => 133.0,
|
19
|
-
:description => "Testing a CLIEOP direct debt transaction\nCharging your bank account"
|
12
|
+
:description => "Testing a CLIEOP direct debt transaction\nCharging your bank account"
|
13
|
+
}
|
20
14
|
|
21
15
|
batch << { :account_nr => 654321, :account_owner => 'somebody else', :amount => 233.0,
|
22
16
|
:description => 'Some description for the other guy' }
|
@@ -25,9 +19,16 @@ class ClieopWriterTest < Test::Unit::TestCase
|
|
25
19
|
|
26
20
|
clieop_data = file.to_clieop
|
27
21
|
|
28
|
-
|
29
|
-
|
22
|
+
clieop_data.class.should eql(String)
|
23
|
+
|
24
|
+
end
|
30
25
|
|
26
|
+
it "should format the checksum" do
|
27
|
+
batch = Clieop::Batch.new({:description => "Description", :account_nr => "Account Nr", :account_owner => "Account Owner" } )
|
28
|
+
batch.account_checksum('1234567890123').should eql('4567890123')
|
29
|
+
batch.account_checksum('7654321').should eql('7654321')
|
31
30
|
end
|
32
31
|
|
32
|
+
#TODO: more tests
|
33
|
+
|
33
34
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clieop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Willem van Bergen
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-06-02 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -23,17 +29,22 @@ extensions: []
|
|
23
29
|
extra_rdoc_files: []
|
24
30
|
|
25
31
|
files:
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
- spec/clieop/batch_spec.rb
|
26
34
|
- .gitignore
|
27
35
|
- lib/clieop/record.rb
|
36
|
+
- MIT-LICENSE
|
37
|
+
- doc/clieop03.pdf
|
28
38
|
- lib/clieop/file.rb
|
29
39
|
- lib/clieop/batch.rb
|
30
40
|
- lib/clieop.rb
|
41
|
+
- init.rb
|
31
42
|
- Rakefile
|
32
|
-
- MIT-LICENSE
|
33
|
-
- test/clieop_writer_test.rb
|
34
|
-
- tasks/github-gem.rake
|
35
43
|
- clieop.gemspec
|
36
44
|
- README.rdoc
|
45
|
+
- tasks/github-gem.rake
|
46
|
+
- spec/clieop_spec.rb
|
47
|
+
- spec/clieop/record_spec.rb
|
37
48
|
has_rdoc: true
|
38
49
|
homepage: http://github.com/wvanbergen/clieop/wikis
|
39
50
|
licenses: []
|
@@ -44,23 +55,31 @@ rdoc_options: []
|
|
44
55
|
require_paths:
|
45
56
|
- lib
|
46
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
47
59
|
requirements:
|
48
60
|
- - ">="
|
49
61
|
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
50
65
|
version: "0"
|
51
|
-
version:
|
52
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
53
68
|
requirements:
|
54
69
|
- - ">="
|
55
70
|
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
56
74
|
version: "0"
|
57
|
-
version:
|
58
75
|
requirements: []
|
59
76
|
|
60
77
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.3.
|
78
|
+
rubygems_version: 1.3.7
|
62
79
|
signing_key:
|
63
80
|
specification_version: 3
|
64
81
|
summary: A pure Ruby implementation to write CLIEOP files
|
65
82
|
test_files:
|
66
|
-
-
|
83
|
+
- spec/clieop/batch_spec.rb
|
84
|
+
- spec/clieop_spec.rb
|
85
|
+
- spec/clieop/record_spec.rb
|