sepa_king 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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sepa_king/account/creditor_account.rb +8 -0
  3. data/lib/sepa_king/{exception.rb → account/debtor_account.rb} +1 -1
  4. data/lib/sepa_king/account.rb +9 -28
  5. data/lib/sepa_king/converter.rb +44 -0
  6. data/lib/sepa_king/message/credit_transfer.rb +86 -0
  7. data/lib/sepa_king/message/direct_debit.rb +104 -0
  8. data/lib/sepa_king/message.rb +48 -0
  9. data/lib/sepa_king/transaction/credit_transfer_transaction.rb +5 -0
  10. data/lib/sepa_king/transaction/direct_debit_transaction.rb +17 -0
  11. data/lib/sepa_king/transaction.rb +13 -45
  12. data/lib/sepa_king/version.rb +1 -1
  13. data/lib/sepa_king.rb +9 -6
  14. data/sepa_king.gemspec +1 -0
  15. data/spec/account_spec.rb +66 -0
  16. data/spec/converter_spec.rb +46 -0
  17. data/spec/credit_transfer_spec.rb +69 -0
  18. data/spec/credit_transfer_transaction_spec.rb +15 -0
  19. data/spec/creditor_account_spec.rb +31 -0
  20. data/spec/debtor_account_spec.rb +12 -0
  21. data/spec/direct_debit_spec.rb +76 -0
  22. data/spec/direct_debit_transaction_spec.rb +53 -0
  23. data/spec/{fixtures → examples}/pain.001.002.03.xml +0 -0
  24. data/spec/{fixtures → examples}/pain.008.002.02.xml +0 -0
  25. data/spec/message_spec.rb +22 -0
  26. data/spec/spec_helper.rb +0 -1
  27. data/spec/support/validations.rb +27 -0
  28. data/spec/transaction_spec.rb +112 -0
  29. data/spec/{sepa_king/validation_spec.rb → validation_spec.rb} +2 -2
  30. metadata +52 -28
  31. data/lib/sepa_king/credit_transaction.rb +0 -5
  32. data/lib/sepa_king/credit_transfer.rb +0 -104
  33. data/lib/sepa_king/debt_transaction.rb +0 -18
  34. data/lib/sepa_king/direct_debit.rb +0 -122
  35. data/lib/sepa_king/text_converter.rb +0 -25
  36. data/spec/sepa_king/account_spec.rb +0 -13
  37. data/spec/sepa_king/credit_transaction_spec.rb +0 -15
  38. data/spec/sepa_king/credit_transfer_spec.rb +0 -26
  39. data/spec/sepa_king/debt_transaction_spec.rb +0 -53
  40. data/spec/sepa_king/direct_debit_spec.rb +0 -31
  41. data/spec/sepa_king/text_converter_spec.rb +0 -22
  42. data/spec/sepa_king/transaction_spec.rb +0 -112
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::CreditTransferTransaction do
5
+ it 'should initialize a new transaction' do
6
+ expect(
7
+ SEPA::CreditTransferTransaction.new :name => 'Telekomiker AG',
8
+ :iban => 'DE37112589611964645802',
9
+ :bic => 'PBNKDEFF370',
10
+ :amount => 102.50,
11
+ :reference => 'XYZ-1234/123',
12
+ :remittance_information => 'Rechnung 123 vom 22.08.2013'
13
+ ).to be_valid
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::CreditorAccount do
5
+ it 'should initialize a new account' do
6
+ expect(
7
+ SEPA::CreditorAccount.new :name => 'Gläubiger GmbH',
8
+ :bic => 'BANKDEFFXXX',
9
+ :iban => 'DE87200500001234567890',
10
+ :identifier => 'DE98ZZZ09999999999'
11
+ ).to be_valid
12
+ end
13
+
14
+ describe :identifier do
15
+ it 'should accept valid value' do
16
+ [ 'DE98ZZZ09999999999' ].each do |value_value|
17
+ expect(
18
+ SEPA::CreditorAccount.new :identifier => value_value
19
+ ).to have(:no).errors_on(:identifier)
20
+ end
21
+ end
22
+
23
+ it 'should not accept invalid value' do
24
+ [ '', 'invalid' ].each do |invalue_value|
25
+ expect(
26
+ SEPA::CreditorAccount.new :identifier => invalue_value
27
+ ).to have_at_least(1).errors_on(:identifier)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::DebtorAccount do
5
+ it 'should initialize a new account' do
6
+ expect(
7
+ SEPA::DebtorAccount.new :name => 'Gläubiger GmbH',
8
+ :bic => 'BANKDEFFXXX',
9
+ :iban => 'DE87200500001234567890'
10
+ ).to be_valid
11
+ end
12
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::DirectDebit do
5
+ let(:direct_debit) {
6
+ SEPA::DirectDebit.new :name => 'Gläubiger GmbH',
7
+ :bic => 'BANKDEFFXXX',
8
+ :iban => 'DE87200500001234567890',
9
+ :identifier => 'DE98ZZZ09999999999'
10
+ }
11
+
12
+ describe :new do
13
+ it 'should accept missing options' do
14
+ expect {
15
+ SEPA::DirectDebit.new
16
+ }.to_not raise_error
17
+ end
18
+ end
19
+
20
+ describe :add_transaction do
21
+ it 'should add valid transactions' do
22
+ 3.times {
23
+ direct_debit.add_transaction :name => 'Zahlemann & Söhne GbR',
24
+ :bic => 'SPUEDE2UXXX',
25
+ :iban => 'DE21500500009876543210',
26
+ :amount => 39.99,
27
+ :reference => 'XYZ/2013-08-ABO/12345',
28
+ :remittance_information => 'Unsere Rechnung vom 10.08.2013',
29
+ :mandate_id => 'K-02-2011-12345',
30
+ :mandate_date_of_signature => Date.new(2011,1,25)
31
+ }
32
+
33
+ expect(direct_debit).to have(3).transactions
34
+ end
35
+
36
+ it 'should fail for invalid transaction' do
37
+ expect {
38
+ direct_debit.add_transaction :name => ''
39
+ }.to raise_error(ArgumentError)
40
+ end
41
+ end
42
+
43
+ describe :to_xml do
44
+ it 'should fail for invalid debtor' do
45
+ expect {
46
+ SEPA::DirectDebit.new.to_xml
47
+ }.to raise_error(RuntimeError)
48
+ end
49
+
50
+ it 'should create valid XML file' do
51
+ dd = direct_debit
52
+
53
+ dd.add_transaction :name => 'Zahlemann & Söhne GbR',
54
+ :bic => 'SPUEDE2UXXX',
55
+ :iban => 'DE21500500009876543210',
56
+ :amount => 39.99,
57
+ :reference => 'XYZ/2013-08-ABO/12345',
58
+ :remittance_information => 'Unsere Rechnung vom 10.08.2013',
59
+ :mandate_id => 'K-02-2011-12345',
60
+ :mandate_date_of_signature => Date.new(2011,1,25)
61
+
62
+ dd.add_transaction :name => 'Meier & Schulze oHG',
63
+ :bic => 'GENODEF1JEV',
64
+ :iban => 'DE68210501700012345678',
65
+ :amount => 750.00,
66
+ :reference => 'XYZ/2013-08-ABO/6789',
67
+ :remittance_information => 'Vielen Dank für Ihren Einkauf!',
68
+ :mandate_id => 'K-08-2010-42123',
69
+ :mandate_date_of_signature => Date.new(2010,7,25)
70
+
71
+ expect(
72
+ XML::Document.string(dd.to_xml)
73
+ ).to validate_against('pain.008.002.02.xsd')
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::DirectDebitTransaction do
5
+ it 'should initialize a new transaction' do
6
+ expect(
7
+ SEPA::DirectDebitTransaction.new :name => 'Zahlemann & Söhne Gbr',
8
+ :bic => 'SPUEDE2UXXX',
9
+ :iban => 'DE21500500009876543210',
10
+ :amount => 39.99,
11
+ :reference => 'XYZ-1234/123',
12
+ :remittance_information => 'Vielen Dank für Ihren Einkauf!',
13
+ :mandate_id => 'K-02-2011-12345',
14
+ :mandate_date_of_signature => Date.new(2011,1,25)
15
+ ).to be_valid
16
+ end
17
+
18
+ context 'Mandate Date of Signature' do
19
+ it 'should allow valid value' do
20
+ [ Date.today, Date.today - 1 ].each do |valid_value|
21
+ expect(
22
+ SEPA::DirectDebitTransaction.new :mandate_date_of_signature => valid_value
23
+ ).to have(:no).errors_on(:mandate_date_of_signature)
24
+ end
25
+ end
26
+
27
+ it 'should not allow invalid value' do
28
+ [ nil, '2010-12-01', Date.today + 1 ].each do |invalid_value|
29
+ expect(
30
+ SEPA::DirectDebitTransaction.new :mandate_date_of_signature => invalid_value
31
+ ).to have_at_least(1).errors_on(:mandate_date_of_signature)
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'Mandate ID' do
37
+ it 'should allow valid value' do
38
+ [ 'XYZ-123', 'X' * 35 ].each do |valid_value|
39
+ expect(
40
+ SEPA::DirectDebitTransaction.new :mandate_id => valid_value
41
+ ).to have(:no).errors_on(:mandate_id)
42
+ end
43
+ end
44
+
45
+ it 'should not allow invalid value' do
46
+ [ nil, '', 'X' * 36 ].each do |invalid_value|
47
+ expect(
48
+ SEPA::DirectDebitTransaction.new :mandate_id => invalid_value
49
+ ).to have_at_least(1).errors_on(:mandate_id)
50
+ end
51
+ end
52
+ end
53
+ end
File without changes
File without changes
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ class DummyTransaction < SEPA::Transaction
5
+ def valid?; true end
6
+ end
7
+
8
+ class DummyMessage < SEPA::Message
9
+ self.account_class = Hash
10
+ self.transaction_class = DummyTransaction
11
+ end
12
+
13
+ describe SEPA::Message do
14
+ describe :amount_total do
15
+ it 'should sum up transactions' do
16
+ message = DummyMessage.new
17
+ message.add_transaction :amount => 1.1
18
+ message.add_transaction :amount => 2.2
19
+ message.amount_total.should == 3.3
20
+ end
21
+ end
22
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,7 +8,6 @@ require 'coveralls'
8
8
  SimpleCov.formatter = Coveralls::SimpleCov::Formatter
9
9
  SimpleCov.start
10
10
 
11
- require 'ostruct'
12
11
  require 'xml'
13
12
  require 'sepa_king'
14
13
 
@@ -0,0 +1,27 @@
1
+ # Borrowed from rspec-rails
2
+ # https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/extensions/active_record/base.rb
3
+
4
+ module ::ActiveModel::Validations
5
+ # Extension to enhance `to have` on AR Model instances. Calls
6
+ # model.valid? in order to prepare the object's errors object. Accepts
7
+ # a :context option to specify the validation context.
8
+ #
9
+ # You can also use this to specify the content of the error messages.
10
+ #
11
+ # @example
12
+ #
13
+ # expect(model).to have(:no).errors_on(:attribute)
14
+ # expect(model).to have(1).error_on(:attribute)
15
+ # expect(model).to have(n).errors_on(:attribute)
16
+ # expect(model).to have(n).errors_on(:attribute, :context => :create)
17
+ #
18
+ # expect(model.errors_on(:attribute)).to include("can't be blank")
19
+ def errors_on(attribute, options = {})
20
+ valid_args = [options[:context]].compact
21
+ self.valid?(*valid_args)
22
+
23
+ [self.errors[attribute]].flatten.compact
24
+ end
25
+
26
+ alias :error_on :errors_on
27
+ end
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::Transaction do
5
+ context 'Name' do
6
+ it 'should accept valid value' do
7
+ [ 'Manfred Mustermann III.', 'Zahlemann & Söhne GbR', 'X' * 70 ].each do |value_value|
8
+ expect(
9
+ SEPA::Transaction.new :name => value_value
10
+ ).to have(:no).errors_on(:name)
11
+ end
12
+ end
13
+
14
+ it 'should not accept invalid value' do
15
+ [ nil, '', 'X' * 71 ].each do |invalue_value|
16
+ expect(
17
+ SEPA::Transaction.new :name => invalue_value
18
+ ).to have_at_least(1).errors_on(:name)
19
+ end
20
+ end
21
+ end
22
+
23
+ context 'IBAN' do
24
+ it 'should accept valid value' do
25
+ [ 'DE21500500009876543210', 'PL61109010140000071219812874' ].each do |value_value|
26
+ expect(
27
+ SEPA::Transaction.new :iban => value_value
28
+ ).to have(:no).errors_on(:iban)
29
+ end
30
+ end
31
+
32
+ it 'should not accept invalid value' do
33
+ [ nil, '', 'invalid' ].each do |invalue_value|
34
+ expect(
35
+ SEPA::Transaction.new :iban => invalue_value
36
+ ).to have_at_least(1).errors_on(:iban)
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'BIC' do
42
+ it 'should accept valid value' do
43
+ [ 'DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX' ].each do |value_value|
44
+ expect(
45
+ SEPA::Transaction.new :bic => value_value
46
+ ).to have(:no).errors_on(:bic)
47
+ end
48
+ end
49
+
50
+ it 'should not accept invalid value' do
51
+ [ nil, '', 'invalid' ].each do |invalue_value|
52
+ expect(
53
+ SEPA::Transaction.new :bic => invalue_value
54
+ ).to have_at_least(1).errors_on(:bic)
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'Amount' do
60
+ it 'should accept valid value' do
61
+ [ 0.01, 1, 100, 100.00, 99.99, 1234567890.12, BigDecimal('10'), '42', '42.51', '42.512', 1.23456 ].each do |value_value|
62
+ expect(
63
+ SEPA::Transaction.new :amount => value_value
64
+ ).to have(:no).errors_on(:amount)
65
+ end
66
+ end
67
+
68
+ it 'should not accept invalid value' do
69
+ [ nil, 0, -3, 'xz' ].each do |invalue_value|
70
+ expect(
71
+ SEPA::Transaction.new :amount => invalue_value
72
+ ).to have_at_least(1).errors_on(:amount)
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'Reference' do
78
+ it 'should accept valid value' do
79
+ [ nil, 'ABC-1234/78.0', 'X' * 35 ].each do |value_value|
80
+ expect(
81
+ SEPA::Transaction.new :reference => value_value
82
+ ).to have(:no).errors_on(:reference)
83
+ end
84
+ end
85
+
86
+ it 'should not accept invalid value' do
87
+ [ '', 'X' * 36 ].each do |invalid_value|
88
+ expect(
89
+ SEPA::Transaction.new :reference => invalid_value
90
+ ).to have_at_least(1).errors_on(:reference)
91
+ end
92
+ end
93
+ end
94
+
95
+ context 'Remittance information' do
96
+ it 'should allow valid value' do
97
+ [ nil, 'Bonus', 'X' * 140 ].each do |valid_value|
98
+ expect(
99
+ SEPA::Transaction.new :remittance_information => valid_value
100
+ ).to have(:no).errors_on(:remittance_information)
101
+ end
102
+ end
103
+
104
+ it 'should not allow invalid value' do
105
+ [ '', 'X' * 141 ].each do |invalid_value|
106
+ expect(
107
+ SEPA::Transaction.new :remittance_information => invalid_value
108
+ ).to have_at_least(1).errors_on(:remittance_information)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Credit Transfer Initiation' do
4
4
  it "should validate example file" do
5
- XML::Document.file('spec/fixtures/pain.001.002.03.xml').should validate_against('pain.001.002.03.xsd')
5
+ XML::Document.file('spec/examples/pain.001.002.03.xml').should validate_against('pain.001.002.03.xsd')
6
6
  end
7
7
  end
8
8
 
9
9
  describe 'Direct Debit Initiation' do
10
10
  it 'should validate example file' do
11
- XML::Document.file('spec/fixtures/pain.008.002.02.xml').should validate_against('pain.008.002.02.xsd')
11
+ XML::Document.file('spec/examples/pain.008.002.02.xml').should validate_against('pain.008.002.02.xsd')
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sepa_king
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Leciejewski
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-23 00:00:00.000000000 Z
12
+ date: 2013-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activemodel
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: i18n
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -156,27 +170,33 @@ files:
156
170
  - lib/schema/pain.008.002.02.xsd
157
171
  - lib/sepa_king.rb
158
172
  - lib/sepa_king/account.rb
159
- - lib/sepa_king/credit_transaction.rb
160
- - lib/sepa_king/credit_transfer.rb
161
- - lib/sepa_king/debt_transaction.rb
162
- - lib/sepa_king/direct_debit.rb
163
- - lib/sepa_king/exception.rb
164
- - lib/sepa_king/text_converter.rb
173
+ - lib/sepa_king/account/creditor_account.rb
174
+ - lib/sepa_king/account/debtor_account.rb
175
+ - lib/sepa_king/converter.rb
176
+ - lib/sepa_king/message.rb
177
+ - lib/sepa_king/message/credit_transfer.rb
178
+ - lib/sepa_king/message/direct_debit.rb
165
179
  - lib/sepa_king/transaction.rb
180
+ - lib/sepa_king/transaction/credit_transfer_transaction.rb
181
+ - lib/sepa_king/transaction/direct_debit_transaction.rb
166
182
  - lib/sepa_king/version.rb
167
183
  - sepa_king.gemspec
168
- - spec/fixtures/pain.001.002.03.xml
169
- - spec/fixtures/pain.008.002.02.xml
170
- - spec/sepa_king/account_spec.rb
171
- - spec/sepa_king/credit_transaction_spec.rb
172
- - spec/sepa_king/credit_transfer_spec.rb
173
- - spec/sepa_king/debt_transaction_spec.rb
174
- - spec/sepa_king/direct_debit_spec.rb
175
- - spec/sepa_king/text_converter_spec.rb
176
- - spec/sepa_king/transaction_spec.rb
177
- - spec/sepa_king/validation_spec.rb
184
+ - spec/account_spec.rb
185
+ - spec/converter_spec.rb
186
+ - spec/credit_transfer_spec.rb
187
+ - spec/credit_transfer_transaction_spec.rb
188
+ - spec/creditor_account_spec.rb
189
+ - spec/debtor_account_spec.rb
190
+ - spec/direct_debit_spec.rb
191
+ - spec/direct_debit_transaction_spec.rb
192
+ - spec/examples/pain.001.002.03.xml
193
+ - spec/examples/pain.008.002.02.xml
194
+ - spec/message_spec.rb
178
195
  - spec/spec_helper.rb
179
196
  - spec/support/custom_matcher.rb
197
+ - spec/support/validations.rb
198
+ - spec/transaction_spec.rb
199
+ - spec/validation_spec.rb
180
200
  homepage: http://github.com/salesking/sepa_king
181
201
  licenses:
182
202
  - MIT
@@ -202,15 +222,19 @@ signing_key:
202
222
  specification_version: 4
203
223
  summary: Generate SEPA XML files with Ruby ... the easy way
204
224
  test_files:
205
- - spec/fixtures/pain.001.002.03.xml
206
- - spec/fixtures/pain.008.002.02.xml
207
- - spec/sepa_king/account_spec.rb
208
- - spec/sepa_king/credit_transaction_spec.rb
209
- - spec/sepa_king/credit_transfer_spec.rb
210
- - spec/sepa_king/debt_transaction_spec.rb
211
- - spec/sepa_king/direct_debit_spec.rb
212
- - spec/sepa_king/text_converter_spec.rb
213
- - spec/sepa_king/transaction_spec.rb
214
- - spec/sepa_king/validation_spec.rb
225
+ - spec/account_spec.rb
226
+ - spec/converter_spec.rb
227
+ - spec/credit_transfer_spec.rb
228
+ - spec/credit_transfer_transaction_spec.rb
229
+ - spec/creditor_account_spec.rb
230
+ - spec/debtor_account_spec.rb
231
+ - spec/direct_debit_spec.rb
232
+ - spec/direct_debit_transaction_spec.rb
233
+ - spec/examples/pain.001.002.03.xml
234
+ - spec/examples/pain.008.002.02.xml
235
+ - spec/message_spec.rb
215
236
  - spec/spec_helper.rb
216
237
  - spec/support/custom_matcher.rb
238
+ - spec/support/validations.rb
239
+ - spec/transaction_spec.rb
240
+ - spec/validation_spec.rb
@@ -1,5 +0,0 @@
1
- # encoding: utf-8
2
- module SEPA
3
- class CreditTransaction < Transaction
4
- end
5
- end
@@ -1,104 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SEPA
4
- class CreditTransfer
5
- attr_reader :debitor, :transactions
6
-
7
- def initialize(debitor_options)
8
- @debitor = Account.new(debitor_options)
9
- @transactions = []
10
- end
11
-
12
- def add_transaction(options)
13
- @transactions << CreditTransaction.new(options)
14
- end
15
-
16
- def to_xml
17
- builder = Builder::XmlMarkup.new :indent => 2
18
- builder.instruct!
19
- builder.Document :xmlns => 'urn:iso:std:iso:20022:tech:xsd:pain.001.002.03',
20
- :'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
21
- :'xsi:schemaLocation' => 'urn:iso:std:iso:20022:tech:xsd:pain.001.002.03 pain.001.002.03.xsd' do
22
- builder.CstmrCdtTrfInitn do
23
- builder.GrpHdr do
24
- builder.MsgId(message_identification)
25
- builder.CreDtTm(Time.now.iso8601)
26
- builder.NbOfTxs(transactions.length)
27
- builder.InitgPty do
28
- builder.Nm(debitor.name)
29
- end
30
- end
31
-
32
- builder.PmtInf do
33
- builder.PmtInfId(payment_information_identification)
34
- builder.PmtMtd('TRF')
35
- builder.BtchBookg(true)
36
- builder.NbOfTxs(transactions.length)
37
- builder.CtrlSum(amount_total)
38
- builder.PmtTpInf do
39
- builder.SvcLvl do
40
- builder.Cd('SEPA')
41
- end
42
- end
43
- builder.ReqdExctnDt(Date.today.next.iso8601)
44
- builder.Dbtr do
45
- builder.Nm(debitor.name)
46
- end
47
- builder.DbtrAcct do
48
- builder.Id do
49
- builder.IBAN(debitor.iban)
50
- end
51
- end
52
- builder.DbtrAgt do
53
- builder.FinInstnId do
54
- builder.BIC(debitor.bic)
55
- end
56
- end
57
- builder.ChrgBr('SLEV')
58
- transactions.each do |transaction|
59
- builder.CdtTrfTxInf do
60
- builder.PmtId do
61
- builder.EndToEndId(transaction.reference || 'NOTPROVIDED')
62
- end
63
- builder.Amt do
64
- builder.InstdAmt(transaction.amount, :Ccy => 'EUR')
65
- end
66
- builder.CdtrAgt do
67
- builder.FinInstnId do
68
- builder.BIC(transaction.bic)
69
- end
70
- end
71
- builder.Cdtr do
72
- builder.Nm(transaction.name)
73
- end
74
- builder.CdtrAcct do
75
- builder.Id do
76
- builder.IBAN(transaction.iban)
77
- end
78
- end
79
- if transaction.remittance_information
80
- builder.RmtInf do
81
- builder.Ustrd(transaction.remittance_information)
82
- end
83
- end
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
90
-
91
- private
92
- def amount_total
93
- transactions.inject(0) { |sum, t| sum + t.amount }
94
- end
95
-
96
- def message_identification
97
- "SEPA-KING/#{Time.now.iso8601}"
98
- end
99
-
100
- def payment_information_identification
101
- message_identification
102
- end
103
- end
104
- end
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
- module SEPA
3
- class DebtTransaction < Transaction
4
- attr_reader :mandate_id, :mandate_date_of_signature
5
-
6
- def mandate_id=(value)
7
- raise ArgumentError.new('Mandate ID is missing') if value.nil? || value.empty?
8
- raise ArgumentError.new("Mandate ID is too long: #{value.length}, must be 35 maximum") if value.length > 35
9
- @mandate_id = convert_text(value)
10
- end
11
-
12
- def mandate_date_of_signature=(value)
13
- raise ArgumentError.new('Mandate Date of Signature is missing') unless value.is_a?(Date)
14
- raise ArgumentError.new('Mandate Date of Signature is in the future') if value > Date.today
15
- @mandate_date_of_signature = value
16
- end
17
- end
18
- end