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
@@ -1,122 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SEPA
4
- class DirectDebit
5
- attr_reader :creditor, :transactions
6
-
7
- def initialize(creditor_options)
8
- @creditor = Account.new(creditor_options)
9
- @transactions = []
10
- end
11
-
12
- def add_transaction(options)
13
- @transactions << DebtTransaction.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.008.002.02',
20
- :'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
21
- :'xsi:schemaLocation' => 'urn:iso:std:iso:20022:tech:xsd:pain.008.002.02 pain.008.002.02.xsd' do
22
- builder.CstmrDrctDbtInitn do
23
- builder.GrpHdr do
24
- builder.MsgId(message_identification)
25
- builder.CreDtTm(Time.now.iso8601)
26
- builder.NbOfTxs(transactions.length)
27
- builder.CtrlSum(amount_total)
28
- builder.InitgPty do
29
- builder.Nm(creditor.name)
30
- end
31
- end
32
-
33
- builder.PmtInf do
34
- builder.PmtInfId(payment_information_identification)
35
- builder.PmtMtd('DD')
36
- builder.PmtTpInf do
37
- builder.SvcLvl do
38
- builder.Cd('SEPA')
39
- end
40
- builder.LclInstrm do
41
- builder.Cd('CORE')
42
- end
43
- builder.SeqTp('OOFF')
44
- end
45
- builder.ReqdColltnDt(Date.today.next.iso8601)
46
- builder.Cdtr do
47
- builder.Nm(creditor.name)
48
- end
49
- builder.CdtrAcct do
50
- builder.Id do
51
- builder.IBAN(creditor.iban)
52
- end
53
- end
54
- builder.CdtrAgt do
55
- builder.FinInstnId do
56
- builder.BIC(creditor.bic)
57
- end
58
- end
59
- builder.ChrgBr('SLEV')
60
- builder.CdtrSchmeId do
61
- builder.Id do
62
- builder.PrvtId do
63
- builder.Othr do
64
- builder.Id(creditor.identifier)
65
- builder.SchmeNm do
66
- builder.Prtry('SEPA')
67
- end
68
- end
69
- end
70
- end
71
- end
72
- transactions.each do |transaction|
73
- builder.DrctDbtTxInf do
74
- builder.PmtId do
75
- builder.EndToEndId(transaction.reference || 'NOTPROVIDED')
76
- end
77
- builder.InstdAmt(transaction.amount, :Ccy => 'EUR')
78
- builder.DrctDbtTx do
79
- builder.MndtRltdInf do
80
- builder.MndtId(transaction.mandate_id)
81
- builder.DtOfSgntr(transaction.mandate_date_of_signature.iso8601)
82
- end
83
- end
84
- builder.DbtrAgt do
85
- builder.FinInstnId do
86
- builder.BIC(transaction.bic)
87
- end
88
- end
89
- builder.Dbtr do
90
- builder.Nm(transaction.name)
91
- end
92
- builder.DbtrAcct do
93
- builder.Id do
94
- builder.IBAN(transaction.iban)
95
- end
96
- end
97
- if transaction.remittance_information
98
- builder.RmtInf do
99
- builder.Ustrd(transaction.remittance_information)
100
- end
101
- end
102
- end
103
- end
104
- end
105
- end
106
- end
107
- end
108
-
109
- private
110
- def amount_total
111
- transactions.inject(0) { |sum, t| sum + t.amount }
112
- end
113
-
114
- def message_identification
115
- "SEPA-KING/#{Time.now.iso8601}"
116
- end
117
-
118
- def payment_information_identification
119
- message_identification
120
- end
121
- end
122
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- module SEPA
3
- module TextConverter
4
- def convert_text(text)
5
- text = text.to_s
6
- return text if text.empty?
7
-
8
- text = text.
9
- # Convert german umlauts
10
- gsub('Ä', 'AE').
11
- gsub('Ü', 'UE').
12
- gsub('Ö', 'OE').
13
- gsub('ä', 'ae').
14
- gsub('ü', 'ue').
15
- gsub('ö', 'oe').
16
- gsub('ß', 'ss')
17
-
18
- I18n.transliterate(text).
19
- # Remove all invalid characters
20
- gsub(/[^a-zA-Z0-9\ \'\:\?\,\-\(\+\.\)\/]/, '').
21
- # Remove leading and trailing spaces
22
- strip
23
- end
24
- end
25
- end
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe SEPA::Account do
5
- it 'should initialize a new account' do
6
- lambda{
7
- SEPA::Account.new :name => 'Gläubiger GmbH',
8
- :bic => 'BANKDEFFXXX',
9
- :iban => 'DE87200500001234567890',
10
- :identifier => 'DE98ZZZ09999999999'
11
- }.should_not raise_error
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe SEPA::CreditTransaction do
5
- it 'should initialize a new transaction' do
6
- lambda{
7
- SEPA::CreditTransaction.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
- }.should_not raise_error
14
- end
15
- end
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe SEPA::CreditTransfer do
5
- it 'should create valid XML file' do
6
- ct = SEPA::CreditTransfer.new :name => 'Schuldner GmbH',
7
- :bic => 'BANKDEFFXXX',
8
- :iban => 'DE87200500001234567890'
9
-
10
- ct.add_transaction :name => 'Telekomiker AG',
11
- :bic => 'PBNKDEFF370',
12
- :iban => 'DE37112589611964645802',
13
- :amount => 102.50,
14
- :reference => 'XYZ-1234/123',
15
- :remittance_information => 'Rechnung vom 22.08.2013'
16
-
17
- ct.add_transaction :name => 'Amazonas GmbH',
18
- :bic => 'TUBDDEDDXXX',
19
- :iban => 'DE27793589132923472195',
20
- :amount => 59.00,
21
- :reference => 'XYZ-5678/456',
22
- :remittance_information => 'Rechnung vom 21.08.2013'
23
-
24
- XML::Document.string(ct.to_xml).should validate_against('pain.001.002.03.xsd')
25
- end
26
- end
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe SEPA::DebtTransaction do
5
- it 'should initialize a new transaction' do
6
- lambda{
7
- SEPA::DebtTransaction.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
- }.should_not raise_error
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
- lambda {
22
- SEPA::DebtTransaction.new :mandate_date_of_signature => valid_value
23
- }.should_not raise_error
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
- lambda {
30
- SEPA::DebtTransaction.new :mandate_date_of_signature => invalid_value
31
- }.should raise_error(ArgumentError, /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
- lambda {
40
- SEPA::DebtTransaction.new :mandate_id => valid_value
41
- }.should_not raise_error
42
- end
43
- end
44
-
45
- it 'should not allow invalid value' do
46
- [ nil, '', 'X' * 36 ].each do |invalid_value|
47
- lambda {
48
- SEPA::DebtTransaction.new :mandate_id => invalid_value
49
- }.should raise_error(ArgumentError, /Mandate ID/)
50
- end
51
- end
52
- end
53
- end
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe SEPA::DirectDebit do
5
- it 'should create valid XML file' do
6
- dd = SEPA::DirectDebit.new :name => 'Gläubiger GmbH',
7
- :bic => 'BANKDEFFXXX',
8
- :iban => 'DE87200500001234567890',
9
- :identifier => 'DE98ZZZ09999999999'
10
-
11
- dd.add_transaction :name => 'Zahlemann & Söhne GbR',
12
- :bic => 'SPUEDE2UXXX',
13
- :iban => 'DE21500500009876543210',
14
- :amount => 39.99,
15
- :reference => 'XYZ/2013-08-ABO/12345',
16
- :remittance_information => 'Unsere Rechnung vom 10.08.2013',
17
- :mandate_id => 'K-02-2011-12345',
18
- :mandate_date_of_signature => Date.new(2011,1,25)
19
-
20
- dd.add_transaction :name => 'Meier & Schulze oHG',
21
- :bic => 'GENODEF1JEV',
22
- :iban => 'DE68210501700012345678',
23
- :amount => 750.00,
24
- :reference => 'XYZ/2013-08-ABO/6789',
25
- :remittance_information => 'Vielen Dank für Ihren Einkauf!',
26
- :mandate_id => 'K-08-2010-42123',
27
- :mandate_date_of_signature => Date.new(2010,7,25)
28
-
29
- XML::Document.string(dd.to_xml).should validate_against('pain.008.002.02.xsd')
30
- end
31
- end
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe SEPA::TextConverter do
5
- include SEPA::TextConverter
6
-
7
- it "should convert to upper case" do
8
- convert_text('2&2 GmbH & Co. KG').should == '22 GmbH Co. KG'
9
- end
10
-
11
- it "should remove invalid chars" do
12
- convert_text('&@"=<>!').should == ''
13
- end
14
-
15
- it "should leave valid chars" do
16
- convert_text("abc-ABC-0123- ':?,-(+.)/").should == "abc-ABC-0123- ':?,-(+.)/"
17
- end
18
-
19
- it "should convert umlaute" do
20
- convert_text('üöäÜÖÄß').should == 'ueoeaeUEOEAEss'
21
- end
22
- end
@@ -1,112 +0,0 @@
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
- lambda {
9
- SEPA::CreditTransaction.new :name => value_value
10
- }.should_not raise_error
11
- end
12
- end
13
-
14
- it 'should not accept invalid value' do
15
- [ nil, '', 'X' * 71 ].each do |invalue_value|
16
- lambda {
17
- SEPA::CreditTransaction.new :name => invalue_value
18
- }.should raise_error(ArgumentError, /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
- lambda {
27
- SEPA::CreditTransaction.new :iban => value_value
28
- }.should_not raise_error
29
- end
30
- end
31
-
32
- it 'should not accept invalid value' do
33
- [ nil, '', 'invalid' ].each do |invalue_value|
34
- lambda {
35
- SEPA::CreditTransaction.new :iban => invalue_value
36
- }.should raise_error(ArgumentError, /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
- lambda {
45
- SEPA::CreditTransaction.new :bic => value_value
46
- }.should_not raise_error
47
- end
48
- end
49
-
50
- it 'should not accept invalid value' do
51
- [ nil, '', 'invalid' ].each do |invalue_value|
52
- lambda {
53
- SEPA::CreditTransaction.new :bic => invalue_value
54
- }.should raise_error(ArgumentError, /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") ].each do |value_value|
62
- lambda {
63
- SEPA::CreditTransaction.new :amount => value_value
64
- }.should_not raise_error
65
- end
66
- end
67
-
68
- it 'should not accept invalid value' do
69
- [ nil, 0, -3, 1.23456 ].each do |invalue_value|
70
- lambda {
71
- SEPA::CreditTransaction.new :amount => invalue_value
72
- }.should raise_error(ArgumentError, /Amount/)
73
- end
74
- end
75
- end
76
-
77
- context 'Reference' do
78
- it 'should accept valid value' do
79
- [ 'ABC-1234/78.0', 'X' * 35 ].each do |value_value|
80
- lambda {
81
- SEPA::CreditTransaction.new :reference => value_value
82
- }.should_not raise_error
83
- end
84
- end
85
-
86
- it 'should not accept invalid value' do
87
- [ nil, '', 'X' * 36 ].each do |invalue_value|
88
- lambda {
89
- SEPA::CreditTransaction.new :reference => invalue_value
90
- }.should raise_error(ArgumentError, /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
- lambda {
99
- SEPA::CreditTransaction.new :remittance_information => valid_value
100
- }.should_not raise_error
101
- end
102
- end
103
-
104
- it 'should not allow invalid value' do
105
- [ '', 'X' * 141, 42 ].each do |invalid_value|
106
- lambda {
107
- SEPA::CreditTransaction.new :remittance_information => invalid_value
108
- }.should raise_error(ArgumentError, /Remittance/)
109
- end
110
- end
111
- end
112
- end