king_dtaus 2.0.1.pre → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ nbproject/*
2
+ .rvmrc
3
+ coverage/*
4
+ rdoc/*
5
+ pkg/*
6
+ .DS_Store
7
+ DTAUS0.TXT
8
+ dta.txt
9
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
1
  source :rubygems
2
-
3
2
  gemspec
data/README.markdown ADDED
@@ -0,0 +1,128 @@
1
+ # DTAUS & DTAZV always comes together
2
+
3
+ [![Build Status](https://secure.travis-ci.org/salesking/king_dtaus.png)](http://travis-ci.org/salesking/king_dtaus)
4
+
5
+ DTAUS & DTAZV are formats for German bank transfers and is short for
6
+ "Datenträgeraustausch". The format itself totally sucks because it was
7
+ established in the last century, to be used on floppy disks. Still almost
8
+ all German banks use it (they only seem innovative at robbing), and it is
9
+ therefore supported in common banking programs too.
10
+
11
+ This gem saves you all the trouble when generating DTAUS- or DTAZV-text.
12
+
13
+ We love building payment applications.
14
+
15
+ ## Install
16
+
17
+ gem install king_dtaus
18
+
19
+ ## Features
20
+
21
+ * Create DTAUS debit transfer (Lastschrift)
22
+ * Create DTAUS credit transfer (Gutschrift)
23
+ * Create DTAZV debit transfer
24
+ * 100% test coverage to ensure software quality
25
+ * works with ruby 1.8 & 1.9.2
26
+
27
+ ## Version Info
28
+
29
+ Version 2 has breaking changes!
30
+
31
+ * account attributes now passed in as hash
32
+ * renamed account.client_xy => owner_xy
33
+ * renamed account.account_number => bank_account_number
34
+ * added iban/bic to account
35
+ * DTAZV added
36
+
37
+ If you want to stay with v1 just pin it in your Gemfile:
38
+
39
+ gem "king_dtaus", "<2"
40
+
41
+ ## TODOs
42
+
43
+ * some more edge-case tests needed, we need your feedback here!
44
+
45
+ ## Resources
46
+
47
+ * SalesKing: http://salesking.eu
48
+ * DTAZV-Viewer: http://www.meta-evolutions.de/pages/artikel-20070630-dtazv-datei-betrachter.html
49
+ * DTA/DTAZV PHP Pear: http://pear.php.net/package/Payment_DTA
50
+ * Windata ZV-Tools: http://www.windata.de/Site/2Produkte2/ZVTools.aspx
51
+ * The Swift Codes: http://www.theswiftcodes.com/
52
+ * StarMoney: http://www.starmoney.de/index.php?id=starmoneybusiness_testen
53
+
54
+ ## Examples
55
+
56
+ Here are some examples how to create a DTA- or DTAZV-File. Also check out the spec/dtazv_test.rb to have a running example of an export.
57
+
58
+ ### DTA
59
+
60
+ # create a new dtaus object
61
+ dta = KingDta::Dtaus.new('LK')
62
+
63
+ # set sender account
64
+ dta.account = KingDta::Account.new(
65
+ :bank_account_number => "123456789",
66
+ :bank_number => "69069096",
67
+ :owner_name => "Return to Sender",
68
+ :bank_name => "Money Burner Bank")
69
+
70
+ # following should be done in a loop to add multiple bookings
71
+ # create receiving account
72
+ receiver = KingDta::Account.new(
73
+ :bank_account_number => "987456123",
74
+ :bank_number => "99099096",
75
+ :owner_name => "Gimme More Lt.",
76
+ :bank_name => "Banking Bandits")
77
+ # create booking
78
+ booking = KingDta::Booking.new(receiver, 100.00 )
79
+
80
+ # set booking text if you want to
81
+ booking.text = "Thanks for your purchase"
82
+
83
+ # add booking
84
+ dta.add( booking )
85
+ # end loop
86
+
87
+ # create datausstring and do with it whatever fits your workflow
88
+ my_str = dta.create
89
+
90
+ ### DTAZV
91
+
92
+ @dtazv = KingDta::Dtazv.new()
93
+
94
+ # sender account
95
+ @dtazv.account = KingDta::Account.new(
96
+ :bank_account_number => "123456789",
97
+ :bank_number => "40050100",
98
+ :bank_name => "Greedy Fuckers Bank",
99
+ :owner_name => "Sender name"
100
+ )
101
+
102
+ # receiver account
103
+ receiver = KingDta::Account.new(
104
+ :bank_account_number => "987654321",
105
+ :bank_iban => "PLsome-long-Iban",
106
+ :bank_bic => "BicCode",
107
+ :owner_name => "receivers name"
108
+ )
109
+ # add bookings, probably in a loop
110
+ booking = KingDta::Booking.new(receiver, 220.25)
111
+ @dtazv.add(booking)
112
+
113
+ # get output as string
114
+ @dtazv.create
115
+
116
+ also make sure to read the code and the specs
117
+
118
+ ## Credits
119
+
120
+ Bugfixes and enhancements by
121
+
122
+ * Georg Ledermann - https://github.com/ledermann
123
+ * Kim Rudolph - https://github.com/krudolph
124
+ * Thorsten Böttger - https://github.com/alto
125
+ * Jan Kus - https://github.com/koos
126
+ * used https://rubygems.org/gems/DTAUS as a starting point
127
+
128
+ Copyright (c) 2009-2011 Georg Leciejewski (SalesKing), Jan Kus (Railslove), released under the MIT license
data/Rakefile CHANGED
@@ -1,25 +1,25 @@
1
1
  require 'rake'
2
+ require 'rspec'
2
3
  require 'rspec/core/rake_task'
3
-
4
+ require 'rdoc/task'
5
+ require 'bundler/gem_helper'
6
+ Bundler::GemHelper.install_tasks
4
7
  desc "Run specs"
5
8
  RSpec::Core::RakeTask.new
6
9
 
7
10
  task :default => :spec
8
11
 
9
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
12
+ RSpec::Core::RakeTask.new(:coverage) do |t|
13
+ t.rcov = true
14
+ t.rcov_opts = %q[--exclude "spec"]
15
+ t.verbose = true
16
+ end
10
17
 
11
- begin
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- gem.name = "king_dtaus"
15
- gem.summary = %Q{Generate DTAUS strings and files}
16
- gem.description = %Q{DTAUS is a text-based format, to create bank transfers for german banks. This gem helps with the creation of those transfer files.}
17
- gem.email = "gl@salesking.eu"
18
- gem.homepage = "http://github.com/salesking/king_dtaus"
19
- gem.authors = ["Georg Leciejewski", "Georg Ledermann"]
20
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
- end
22
- Jeweler::GemcutterTasks.new
23
- rescue LoadError
24
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ desc 'Generate documentation'
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'docs/rdoc'
21
+ rdoc.title = 'KingPdf'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
25
  end
data/king_dtaus.gemspec CHANGED
@@ -1,75 +1,36 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'king_dta/version'
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = %q{king_dtaus}
8
- s.version = "2.0.1.pre"
7
+ s.version = KingDta::VERSION
9
8
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Georg Leciejewski", "Georg Ledermann"]
12
- s.date = %q{2011-06-15}
13
- s.description = %q{DTAUS is a text-based format, to create bank transfers for german banks. This gem helps with the creation of those transfer files.}
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.authors = ["Georg Leciejewski", "Georg Ledermann", "Jan Kus"]
11
+ s.date = %q{2011-11-15}
12
+ s.summary = %q{Generate DTA/DTAUS and DTAZV bank transfer files .. the easy way}
13
+ s.description = %q{DTA/DTAUS and DTAZV are text-based formats to create bank transfers for german banks.
14
+ This gem creates DTA/DATAUS files for inner german credit and debit(Gutschrift/Lastschrift) transfers.
15
+ It is also capable of creating DTAZV credit-files for transfers from Germany to European SEPA region.}
14
16
  s.email = %q{gl@salesking.eu}
15
17
  s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".rvmrc",
20
- "Gemfile",
21
- "Gemfile.lock",
22
- "MIT-LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "docs/dtazv.pdf",
27
- "docs/dtazv_bank_bbk.pdf",
28
- "example.output",
29
- "king_dtaus.gemspec",
30
- "lib/king_dta/account.rb",
31
- "lib/king_dta/booking.rb",
32
- "lib/king_dta/dta.rb",
33
- "lib/king_dta/dtaus.rb",
34
- "lib/king_dta/dtazv.rb",
35
- "lib/king_dta/exception.rb",
36
- "lib/king_dta/helper.rb",
37
- "lib/king_dtaus.rb",
38
- "spec/account_spec.rb",
39
- "spec/booking_spec.rb",
40
- "spec/dtaus_spec.rb",
41
- "spec/dtazv_spec.rb",
42
- "spec/dtazv_test.rb",
43
- "spec/helper_spec.rb",
44
- "spec/spec_helper.rb"
18
+ "README.markdown"
45
19
  ]
20
+ s.executables = nil
21
+ s.files = `git ls-files`.split("\n").reject{|i| i[/^docs\//] }
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+
46
24
  s.homepage = %q{http://github.com/salesking/king_dtaus}
47
25
  s.require_paths = ["lib"]
48
- s.rubygems_version = %q{1.5.0}
49
- s.summary = %q{Generate DTAUS strings and files}
26
+ s.rubygems_version = %q{1.6.2}
50
27
 
51
- if s.respond_to? :specification_version then
52
- s.specification_version = 3
28
+ s.add_runtime_dependency 'i18n'
29
+ s.add_development_dependency 'rdoc'
30
+ s.add_development_dependency 'rspec'
31
+ s.add_development_dependency 'simplecov'
32
+ s.add_development_dependency 'mocha'
33
+ s.add_development_dependency 'rake', '>= 0.9.2'
53
34
 
54
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<king_dtaus>, [">= 0"])
56
- s.add_development_dependency(%q<rspec>, [">= 0"])
57
- s.add_development_dependency(%q<jeweler>, [">= 0"])
58
- s.add_development_dependency(%q<simplecov>, [">= 0"])
59
- s.add_development_dependency(%q<mocha>, [">= 0"])
60
- else
61
- s.add_dependency(%q<king_dtaus>, [">= 0"])
62
- s.add_dependency(%q<rspec>, [">= 0"])
63
- s.add_dependency(%q<jeweler>, [">= 0"])
64
- s.add_dependency(%q<simplecov>, [">= 0"])
65
- s.add_dependency(%q<mocha>, [">= 0"])
66
- end
67
- else
68
- s.add_dependency(%q<king_dtaus>, [">= 0"])
69
- s.add_dependency(%q<rspec>, [">= 0"])
70
- s.add_dependency(%q<jeweler>, [">= 0"])
71
- s.add_dependency(%q<simplecov>, [">= 0"])
72
- s.add_dependency(%q<mocha>, [">= 0"])
73
- end
74
35
  end
75
36
 
@@ -1,55 +1,74 @@
1
1
  # encoding: utf-8
2
2
  module KingDta
3
- #Kontodaten verwalten mit Name des Inhabers und Bank, Bankleitzahl und Kontonummer.
3
+ # Bank account and owner information
4
4
  class Account
5
5
  include KingDta::Helper
6
- # dta~ jeweilige Feld in DTAUS-Norm
7
- attr_accessor :account_number, :bank_number, :client_number, :bank_street, :bank_city, :bank_zip_code, :bank_name,
8
- :client_name, :client_street, :client_city, :client_zip_code, :bank_country_code, :client_country_code
9
6
 
10
- # TODO test
7
+ attr_accessor :bank_street, :bank_city,
8
+ :bank_zip, :bank_name, :bank_country_code, :bank_iban,
9
+ :bank_bic,
10
+ :owner_name, :owner_number, :owner_street, :owner_city,
11
+ :owner_zip_code, :owner_country_code
12
+ attr_reader :bank_account_number, :bank_number
13
+
11
14
  def initialize(args={})
12
15
 
13
16
  @bank_street = convert_text(args.delete(:bank_street))
14
17
  @bank_city = convert_text(args.delete(:bank_city))
15
18
  @bank_name = convert_text(args.delete(:bank_name))
16
- @client_name = convert_text(args.delete(:client_name))
17
- @client_street = convert_text(args.delete(:client_street))
18
- @client_city = convert_text(args.delete(:client_city))
19
+ @owner_name = convert_text(args.delete(:owner_name))
20
+ @owner_street = convert_text(args.delete(:owner_street))
21
+ @owner_city = convert_text(args.delete(:owner_city))
19
22
 
20
23
  args.each do |key,value|
21
24
  self.send("#{key}=",value)
22
25
  end
23
26
 
24
- raise ArgumentError.new('Account number too long, max 35 allowed') if @account_number && "#{@account_number}".length > 35
25
- raise ArgumentError.new('Bank number too long, max 11 allowed') if @bank_number && "#{@bank_number}".length > 11
26
- raise ArgumentError.new('Client number too long, max 10 allowed') if @client_number && "#{@client_number}".length > 10
27
- raise ArgumentError.new("Bank account number cannot be 0") if @account_number && @account_number == 0
28
- raise ArgumentError.new("Bank number cannot be 0") if @bank_number && @bank_number == 0
29
- raise ArgumentError.new("Street and/or Zip Code too long, max 35 allowed") if @bank_street && @bank_zip_code && "#{@bank_street} #{@bank_zip_code}".length > 35
30
- raise ArgumentError.new("City too long, max 35 allowed") if @bank_city && @bank_city.length > 35
31
- raise ArgumentError.new("Bank Name too long, max 35 allowed") if @bank_name && @bank_name.length > 35
32
- raise ArgumentError.new("Client Street and/or Zip Code too long, max 35 allowed") if @client_street && @client_zip_code && "#{@client_street} #{@client_zip_code}".length > 35
33
- raise ArgumentError.new("Client City too long, max 35 allowed") if @client_city && @client_city.length > 35
34
- raise ArgumentError.new("Bank Country code too long, max 2 allowed") if @bank_country_code && @bank_country_code.length > 2
35
- raise ArgumentError.new("Client Country code too long, max 2 allowed") if @client_country_code && @client_country_code.length > 2
27
+ raise ArgumentError.new('Owner number too long, max 10 allowed') if @owner_number && "#{@owner_number}".length > 10
28
+ raise ArgumentError.new('Owner street too long, max 35 allowed') if @owner_street && @owner_street.length > 35
29
+ raise ArgumentError.new('Owner city too long, max 35 allowed') if @owner_city && @owner_city.length > 35
30
+ raise ArgumentError.new('Owner country code too long, max 2 allowed') if @owner_country_code && @owner_country_code.length > 2
31
+
32
+
33
+ raise ArgumentError.new("Bank iban wrong length: #{@bank_iban.length}, must be between 15-34") if @bank_iban && !@bank_iban.length.between?(15,34)
34
+ raise ArgumentError.new("Bank bic wrong length: #{@bank_bic.length} must be between 8-11") if @bank_bic && !@bank_bic.length.between?(8,11)
36
35
 
36
+ raise ArgumentError.new('Bank street too long, max 35 allowed') if @bank_street && @bank_street.length > 35
37
+ raise ArgumentError.new('Bank city too long, max 35 allowed') if @bank_city && @bank_city.length > 35
38
+ raise ArgumentError.new('Bank name too long, max 35 allowed') if @bank_name && @bank_name.length > 35
39
+ raise ArgumentError.new('Bank country code too long, max 2 allowed') if @bank_country_code && @bank_country_code.length > 2
40
+
41
+ @owner_country_code = @bank_iban[0..1 ] if @bank_iban && !@owner_country_code
37
42
  end
38
43
 
39
- def client_name_1
40
- @client_name[0..35]
44
+ # Cast given account number to integer. Strips spaces and leading zeros
45
+ # from the bank account number.
46
+ # DTA relies on integers for checksums and field values.
47
+ # @param [String|Integer] number
48
+ def bank_account_number=(number)
49
+ raise ArgumentError.new('Bank account number too long, max 10 allowed') if "#{number}".length > 10
50
+ raise ArgumentError.new('Bank account number cannot be 0') if number == 0
51
+
52
+ @bank_account_number = number.is_a?(String) ? number.gsub(/\s/,'').to_i : number
41
53
  end
42
54
 
43
- def client_name_2
44
- @client_name[36..70]
55
+ # Cast given bank number to integer. Strips spaces and leading zeros
56
+ # from the bank account number.
57
+ # DTA relies on integers for checksums and field values.
58
+ # @param [String|Integer] number
59
+ def bank_number=(number)
60
+ raise ArgumentError.new('Bank number too long, max 8 allowed') if "#{number}".length > 8
61
+ raise ArgumentError.new('Bank number cannot be 0') if number == 0
62
+
63
+ @bank_number = number.is_a?(String) ? number.gsub(/\s/,'').to_i : number
45
64
  end
46
65
 
47
- def zip_city
48
- "#{@bank_zip_code} #{@bank_city}"
66
+ def bank_zip_city
67
+ "#{@bank_zip} #{@bank_city}"
49
68
  end
50
69
 
51
- def client_zip_city
52
- "#{@client_zip_code} #{@client_city}"
70
+ def owner_zip_city
71
+ "#{@owner_zip_code} #{@owner_city}"
53
72
  end
54
73
 
55
74
  end
data/lib/king_dta/dta.rb CHANGED
@@ -4,6 +4,16 @@ module KingDta
4
4
  include KingDta::Helper
5
5
  attr_reader :default_text
6
6
 
7
+ # Create a new dta string.
8
+ # === Parameter #
9
+ # typ<Date>:: date when the the transfer is to be created
10
+ def initialize(date=Date.today )
11
+ raise ArgumentError.new("Wrong date format. Make it a Time or Date object with yyyy-mm-dd") unless date.respond_to?(:strftime)
12
+ @date = date
13
+ @value_pos = true #values are positive by default changed by first booking
14
+ @closed = false
15
+ @default_text = ''
16
+ end
7
17
  # Set the sending account(you own)
8
18
  # === Parameter
9
19
  # account<Account>:: the sending account, must be an instance of class