sepa_king_extended 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +30 -0
  5. data/CONTRIBUTING.md +38 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +267 -0
  9. data/Rakefile +6 -0
  10. data/gemfiles/Gemfile-activemodel-3.0.x +5 -0
  11. data/gemfiles/Gemfile-activemodel-3.1.x +5 -0
  12. data/gemfiles/Gemfile-activemodel-3.2.x +5 -0
  13. data/gemfiles/Gemfile-activemodel-4.0.x +5 -0
  14. data/gemfiles/Gemfile-activemodel-4.1.x +5 -0
  15. data/gemfiles/Gemfile-activemodel-4.2.x +5 -0
  16. data/gemfiles/Gemfile-activemodel-5.0.x +5 -0
  17. data/gemfiles/Gemfile-activemodel-5.1.x +5 -0
  18. data/lib/schema/pain.001.001.03.xsd +921 -0
  19. data/lib/schema/pain.001.002.03.xsd +450 -0
  20. data/lib/schema/pain.001.003.03.xsd +474 -0
  21. data/lib/schema/pain.008.001.02.xsd +879 -0
  22. data/lib/schema/pain.008.002.02.xsd +597 -0
  23. data/lib/schema/pain.008.003.02.xsd +614 -0
  24. data/lib/sepa_king/account/creditor_account.rb +8 -0
  25. data/lib/sepa_king/account/debtor_account.rb +5 -0
  26. data/lib/sepa_king/account.rb +19 -0
  27. data/lib/sepa_king/converter.rb +51 -0
  28. data/lib/sepa_king/message/credit_transfer.rb +99 -0
  29. data/lib/sepa_king/message/direct_debit.rb +151 -0
  30. data/lib/sepa_king/message.rb +135 -0
  31. data/lib/sepa_king/transaction/credit_transfer_transaction.rb +30 -0
  32. data/lib/sepa_king/transaction/direct_debit_transaction.rb +45 -0
  33. data/lib/sepa_king/transaction.rb +44 -0
  34. data/lib/sepa_king/validator.rb +68 -0
  35. data/lib/sepa_king/version.rb +3 -0
  36. data/lib/sepa_king.rb +16 -0
  37. data/sepa_king_extended.gemspec +32 -0
  38. data/spec/account_spec.rb +42 -0
  39. data/spec/converter_spec.rb +74 -0
  40. data/spec/credit_transfer_spec.rb +364 -0
  41. data/spec/credit_transfer_transaction_spec.rb +58 -0
  42. data/spec/creditor_account_spec.rb +23 -0
  43. data/spec/debtor_account_spec.rb +12 -0
  44. data/spec/direct_debit_spec.rb +469 -0
  45. data/spec/direct_debit_transaction_spec.rb +69 -0
  46. data/spec/examples/pain.001.001.03.xml +89 -0
  47. data/spec/examples/pain.001.002.03.xml +89 -0
  48. data/spec/examples/pain.001.003.03.xml +89 -0
  49. data/spec/examples/pain.008.002.02.xml +134 -0
  50. data/spec/examples/pain.008.003.02.xml +134 -0
  51. data/spec/message_spec.rb +88 -0
  52. data/spec/spec_helper.rb +33 -0
  53. data/spec/support/active_model.rb +30 -0
  54. data/spec/support/custom_matcher.rb +60 -0
  55. data/spec/support/factories.rb +24 -0
  56. data/spec/support/validations.rb +27 -0
  57. data/spec/transaction_spec.rb +88 -0
  58. data/spec/validation_spec.rb +25 -0
  59. data/spec/validator_spec.rb +99 -0
  60. metadata +254 -0
@@ -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,88 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::Transaction do
5
+ describe :new do
6
+ it 'should have default for reference' do
7
+ expect(SEPA::Transaction.new.reference).to eq('NOTPROVIDED')
8
+ end
9
+
10
+ it 'should have default for requested_date' do
11
+ expect(SEPA::Transaction.new.requested_date).to eq(Date.new(1999, 1, 1))
12
+ end
13
+
14
+ it 'should have default for batch_booking' do
15
+ expect(SEPA::Transaction.new.batch_booking).to eq(true)
16
+ end
17
+ end
18
+
19
+ context 'Name' do
20
+ it 'should accept valid value' do
21
+ expect(SEPA::Transaction).to accept('Manfred Mustermann III.', 'Zahlemann & Söhne GbR', 'X' * 70, for: :name)
22
+ end
23
+
24
+ it 'should not accept invalid value' do
25
+ expect(SEPA::Transaction).not_to accept(nil, '', 'X' * 71, for: :name)
26
+ end
27
+ end
28
+
29
+ context 'IBAN' do
30
+ it 'should accept valid value' do
31
+ expect(SEPA::Transaction).to accept('DE21500500009876543210', 'PL61109010140000071219812874', for: :iban)
32
+ end
33
+
34
+ it 'should not accept invalid value' do
35
+ expect(SEPA::Transaction).not_to accept(nil, '', 'invalid', for: :iban)
36
+ end
37
+ end
38
+
39
+ context 'BIC' do
40
+ it 'should accept valid value' do
41
+ expect(SEPA::Transaction).to accept('DEUTDEFF', 'DEUTDEFF500', 'SPUEDE2UXXX', for: :bic)
42
+ end
43
+
44
+ it 'should not accept invalid value' do
45
+ expect(SEPA::Transaction).not_to accept('', 'invalid', for: :bic)
46
+ end
47
+ end
48
+
49
+ context 'Amount' do
50
+ it 'should accept valid value' do
51
+ expect(SEPA::Transaction).to accept(0.01, 1, 100, 100.00, 99.99, 1234567890.12, BigDecimal('10'), '42', '42.51', '42.512', 1.23456, for: :amount)
52
+ end
53
+
54
+ it 'should not accept invalid value' do
55
+ expect(SEPA::Transaction).not_to accept(nil, 0, -3, 'xz', for: :amount)
56
+ end
57
+ end
58
+
59
+ context 'Reference' do
60
+ it 'should accept valid value' do
61
+ expect(SEPA::Transaction).to accept(nil, 'ABC-1234/78.0', 'X' * 35, for: :reference)
62
+ end
63
+
64
+ it 'should not accept invalid value' do
65
+ expect(SEPA::Transaction).not_to accept('', 'X' * 36, for: :reference)
66
+ end
67
+ end
68
+
69
+ context 'Remittance information' do
70
+ it 'should allow valid value' do
71
+ expect(SEPA::Transaction).to accept(nil, 'Bonus', 'X' * 140, for: :remittance_information)
72
+ end
73
+
74
+ it 'should not allow invalid value' do
75
+ expect(SEPA::Transaction).not_to accept('', 'X' * 141, for: :remittance_information)
76
+ end
77
+ end
78
+
79
+ context 'Currency' do
80
+ it 'should allow valid values' do
81
+ expect(SEPA::Transaction).to accept('EUR', 'CHF', 'SEK', for: :currency)
82
+ end
83
+
84
+ it 'should not allow invalid values' do
85
+ expect(SEPA::Transaction).not_to accept('', 'EURO', 'ABCDEF', for: :currency)
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Credit Transfer Initiation' do
4
+ it "should validate example file" do
5
+ expect(File.read('spec/examples/pain.001.002.03.xml')).to validate_against('pain.001.002.03.xsd')
6
+ expect(File.read('spec/examples/pain.001.003.03.xml')).to validate_against('pain.001.003.03.xsd')
7
+ end
8
+
9
+ it 'should not validate dummy string' do
10
+ expect('foo').not_to validate_against('pain.001.002.03.xsd')
11
+ expect('foo').not_to validate_against('pain.001.003.03.xsd')
12
+ end
13
+ end
14
+
15
+ describe 'Direct Debit Initiation' do
16
+ it 'should validate example file' do
17
+ expect(File.read('spec/examples/pain.008.002.02.xml')).to validate_against('pain.008.002.02.xsd')
18
+ expect(File.read('spec/examples/pain.008.003.02.xml')).to validate_against('pain.008.003.02.xsd')
19
+ end
20
+
21
+ it 'should not validate dummy string' do
22
+ expect('foo').not_to validate_against('pain.008.002.02.xsd')
23
+ expect('foo').not_to validate_against('pain.008.003.02.xsd')
24
+ end
25
+ end
@@ -0,0 +1,99 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SEPA::IBANValidator do
5
+ class Validatable
6
+ include ActiveModel::Model
7
+ attr_accessor :iban, :iban_the_terrible
8
+ validates_with SEPA::IBANValidator, message: "%{value} seems wrong"
9
+ validates_with SEPA::IBANValidator, field_name: :iban_the_terrible
10
+ end
11
+
12
+ it 'should accept valid IBAN' do
13
+ expect(Validatable).to accept('DE21500500009876543210', 'DE87200500001234567890', for: [:iban, :iban_the_terrible])
14
+ end
15
+
16
+ it 'should not accept an invalid IBAN' do
17
+ expect(Validatable).not_to accept('', 'xxx', # Oviously no IBAN
18
+ 'DE22500500009876543210', # wrong checksum
19
+ 'DE2150050000987654321', # too short
20
+ 'de87200500001234567890', # downcase characters
21
+ 'DE87 2005 0000 1234 5678 90', # spaces included
22
+ for: [:iban, :iban_the_terrible])
23
+ end
24
+
25
+ it "should customize error message" do
26
+ v = Validatable.new(:iban => 'xxx')
27
+ v.valid?
28
+ expect(v.errors[:iban]).to eq(['xxx seems wrong'])
29
+ end
30
+ end
31
+
32
+ describe SEPA::BICValidator do
33
+ class Validatable
34
+ include ActiveModel::Model
35
+ attr_accessor :bic, :custom_bic
36
+ validates_with SEPA::BICValidator, message: "%{value} seems wrong"
37
+ validates_with SEPA::BICValidator, field_name: :custom_bic
38
+ end
39
+
40
+ it 'should accept valid BICs' do
41
+ expect(Validatable).to accept('DEUTDEDBDUE', 'DUSSDEDDXXX', for: [:bic, :custom_bic])
42
+ end
43
+
44
+ it 'should not accept an invalid BIC' do
45
+ expect(Validatable).not_to accept('', 'GENODE61HR', 'DEUTDEDBDUEDEUTDEDBDUE', for: [:bic, :custom_bic])
46
+ end
47
+
48
+ it "should customize error message" do
49
+ v = Validatable.new(:bic => 'xxx')
50
+ v.valid?
51
+ expect(v.errors[:bic]).to eq(['xxx seems wrong'])
52
+ end
53
+ end
54
+
55
+ describe SEPA::CreditorIdentifierValidator do
56
+ class Validatable
57
+ include ActiveModel::Model
58
+ attr_accessor :creditor_identifier, :crid
59
+ validates_with SEPA::CreditorIdentifierValidator, message: "%{value} seems wrong"
60
+ validates_with SEPA::CreditorIdentifierValidator, field_name: :crid
61
+ end
62
+
63
+ it 'should accept valid creditor_identifier' do
64
+ expect(Validatable).to accept('DE98ZZZ09999999999', 'AT12ZZZ00000000001', 'FR12ZZZ123456', 'NL97ZZZ123456780001', for: [:creditor_identifier, :crid])
65
+ end
66
+
67
+ it 'should not accept an invalid creditor_identifier' do
68
+ expect(Validatable).not_to accept('', 'xxx', 'DE98ZZZ099999999990', for: [:creditor_identifier, :crid])
69
+ end
70
+
71
+ it "should customize error message" do
72
+ v = Validatable.new(:creditor_identifier => 'xxx')
73
+ v.valid?
74
+ expect(v.errors[:creditor_identifier]).to eq(['xxx seems wrong'])
75
+ end
76
+ end
77
+
78
+ describe SEPA::MandateIdentifierValidator do
79
+ class Validatable
80
+ include ActiveModel::Model
81
+ attr_accessor :mandate_id, :mid
82
+ validates_with SEPA::MandateIdentifierValidator, message: "%{value} seems wrong"
83
+ validates_with SEPA::MandateIdentifierValidator, field_name: :mid
84
+ end
85
+
86
+ it 'should accept valid mandate_identifier' do
87
+ expect(Validatable).to accept('XYZ-123', "+?/-:().,'", 'X' * 35, for: [:mandate_id, :mid])
88
+ end
89
+
90
+ it 'should not accept an invalid mandate_identifier' do
91
+ expect(Validatable).not_to accept(nil, '', 'X' * 36, 'ABC 123', '#/*', 'Ümläüt', for: [:mandate_id, :mid])
92
+ end
93
+
94
+ it "should customize error message" do
95
+ v = Validatable.new(:mandate_id => 'ABC 123')
96
+ v.valid?
97
+ expect(v.errors[:mandate_id]).to eq(['ABC 123 seems wrong'])
98
+ end
99
+ end
metadata ADDED
@@ -0,0 +1,254 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sepa_king_extended
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.1
5
+ platform: ruby
6
+ authors:
7
+ - Georg Leciejewski
8
+ - Georg Ledermann
9
+ - Chris Okamoto
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2018-04-10 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activemodel
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 3.0.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: builder
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: iban-tools
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: bundler
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: coveralls
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: simplecov
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rake
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: nokogiri
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '1'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '1'
141
+ description: Accepts payment type 3 - for payments in CHF and not SEPA in pain.0001.0001.03
142
+ (ISO 20022)
143
+ email:
144
+ - gl@salesking.eu
145
+ - mail@georg-ledermann.de
146
+ - christiane.okamoto@gmail.com
147
+ executables: []
148
+ extensions: []
149
+ extra_rdoc_files: []
150
+ files:
151
+ - ".gitignore"
152
+ - ".rspec"
153
+ - ".travis.yml"
154
+ - CONTRIBUTING.md
155
+ - Gemfile
156
+ - LICENSE.txt
157
+ - README.md
158
+ - Rakefile
159
+ - gemfiles/Gemfile-activemodel-3.0.x
160
+ - gemfiles/Gemfile-activemodel-3.1.x
161
+ - gemfiles/Gemfile-activemodel-3.2.x
162
+ - gemfiles/Gemfile-activemodel-4.0.x
163
+ - gemfiles/Gemfile-activemodel-4.1.x
164
+ - gemfiles/Gemfile-activemodel-4.2.x
165
+ - gemfiles/Gemfile-activemodel-5.0.x
166
+ - gemfiles/Gemfile-activemodel-5.1.x
167
+ - lib/schema/pain.001.001.03.xsd
168
+ - lib/schema/pain.001.002.03.xsd
169
+ - lib/schema/pain.001.003.03.xsd
170
+ - lib/schema/pain.008.001.02.xsd
171
+ - lib/schema/pain.008.002.02.xsd
172
+ - lib/schema/pain.008.003.02.xsd
173
+ - lib/sepa_king.rb
174
+ - lib/sepa_king/account.rb
175
+ - lib/sepa_king/account/creditor_account.rb
176
+ - lib/sepa_king/account/debtor_account.rb
177
+ - lib/sepa_king/converter.rb
178
+ - lib/sepa_king/message.rb
179
+ - lib/sepa_king/message/credit_transfer.rb
180
+ - lib/sepa_king/message/direct_debit.rb
181
+ - lib/sepa_king/transaction.rb
182
+ - lib/sepa_king/transaction/credit_transfer_transaction.rb
183
+ - lib/sepa_king/transaction/direct_debit_transaction.rb
184
+ - lib/sepa_king/validator.rb
185
+ - lib/sepa_king/version.rb
186
+ - sepa_king_extended.gemspec
187
+ - spec/account_spec.rb
188
+ - spec/converter_spec.rb
189
+ - spec/credit_transfer_spec.rb
190
+ - spec/credit_transfer_transaction_spec.rb
191
+ - spec/creditor_account_spec.rb
192
+ - spec/debtor_account_spec.rb
193
+ - spec/direct_debit_spec.rb
194
+ - spec/direct_debit_transaction_spec.rb
195
+ - spec/examples/pain.001.001.03.xml
196
+ - spec/examples/pain.001.002.03.xml
197
+ - spec/examples/pain.001.003.03.xml
198
+ - spec/examples/pain.008.002.02.xml
199
+ - spec/examples/pain.008.003.02.xml
200
+ - spec/message_spec.rb
201
+ - spec/spec_helper.rb
202
+ - spec/support/active_model.rb
203
+ - spec/support/custom_matcher.rb
204
+ - spec/support/factories.rb
205
+ - spec/support/validations.rb
206
+ - spec/transaction_spec.rb
207
+ - spec/validation_spec.rb
208
+ - spec/validator_spec.rb
209
+ homepage: https://github.com/chrisokamoto/sepa_king_extended
210
+ licenses: []
211
+ metadata: {}
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: 2.0.0
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 2.6.12
229
+ signing_key:
230
+ specification_version: 4
231
+ summary: Ruby gem for creating SEPA XML files
232
+ test_files:
233
+ - spec/account_spec.rb
234
+ - spec/converter_spec.rb
235
+ - spec/credit_transfer_spec.rb
236
+ - spec/credit_transfer_transaction_spec.rb
237
+ - spec/creditor_account_spec.rb
238
+ - spec/debtor_account_spec.rb
239
+ - spec/direct_debit_spec.rb
240
+ - spec/direct_debit_transaction_spec.rb
241
+ - spec/examples/pain.001.001.03.xml
242
+ - spec/examples/pain.001.002.03.xml
243
+ - spec/examples/pain.001.003.03.xml
244
+ - spec/examples/pain.008.002.02.xml
245
+ - spec/examples/pain.008.003.02.xml
246
+ - spec/message_spec.rb
247
+ - spec/spec_helper.rb
248
+ - spec/support/active_model.rb
249
+ - spec/support/custom_matcher.rb
250
+ - spec/support/factories.rb
251
+ - spec/support/validations.rb
252
+ - spec/transaction_spec.rb
253
+ - spec/validation_spec.rb
254
+ - spec/validator_spec.rb