sepa_king 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd633edaa40b7ed3cd1dfe6bbcdb5d676053b6a4
4
- data.tar.gz: 8bdcfc3411785c55878a7a0039815ff046f9f428
3
+ metadata.gz: 26e9894eb7ccc0a61f5f5eaba7f787c9c0e19095
4
+ data.tar.gz: effbc319d83f8b8967ef06f3055ea1af5a686de5
5
5
  SHA512:
6
- metadata.gz: 8e9af124aa9adf73f3b49a4b20880b68ed9f04bbf49fa75bac9bb49140fb1e694efb243595864567bb7544c64a581008b8006afc04e7d404bda9f3d074c104f8
7
- data.tar.gz: c71cb2fb8a9691c2c9d0e70a9a1d2bc63d96178594ca0f41d913670d0d58d9f188ad3b833e28d63d18a5ff4b4a8b61f05adb039cee23b3f0cbf8065c96fda688
6
+ metadata.gz: 7d228d0db0b1fdba496ddf820a9ce9ecb0ee3c9e7b685705353eb9e2022975c103577324e37b8091709cd581d317c01b3d452cebafc0e559a2b8736d024ccf9c
7
+ data.tar.gz: a4f437e100aecbe85d63ab94075176cbd348756a1640ed09566aaf855008dfdf2cc4ff0e7eec5caa3ebcd3147bf01a1289ac590dca439b72d16fc89c26be1aca
data/.travis.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  rvm:
2
2
  - 2.0.0
3
3
  - 2.1.10
4
- - 2.2.6
5
- - 2.3.3
4
+ - 2.2.7
5
+ - 2.3.4
6
+ - 2.4.1
6
7
  gemfile:
7
8
  - gemfiles/Gemfile-activemodel-3.0.x
8
9
  - gemfiles/Gemfile-activemodel-3.1.x
@@ -11,10 +12,19 @@ gemfile:
11
12
  - gemfiles/Gemfile-activemodel-4.1.x
12
13
  - gemfiles/Gemfile-activemodel-4.2.x
13
14
  - gemfiles/Gemfile-activemodel-5.0.x
15
+ - gemfiles/Gemfile-activemodel-5.1.x
14
16
  matrix:
15
17
  exclude:
18
+ - rvm: 2.0.0
19
+ gemfile: gemfiles/Gemfile-activemodel-5.1.x
20
+ - rvm: 2.1.10
21
+ gemfile: gemfiles/Gemfile-activemodel-5.1.x
16
22
  - rvm: 2.0.0
17
23
  gemfile: gemfiles/Gemfile-activemodel-5.0.x
18
24
  - rvm: 2.1.10
19
25
  gemfile: gemfiles/Gemfile-activemodel-5.0.x
26
+ - rvm: 2.4.1
27
+ gemfile: gemfiles/Gemfile-activemodel-4.1.x
28
+ - rvm: 2.4.1
29
+ gemfile: gemfiles/Gemfile-activemodel-4.2.x
20
30
  sudo: false
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2016 Georg Leciejewski (Sales King GmbH) & Georg Ledermann
1
+ Copyright (c) 2013-2017 Georg Leciejewski (Sales King GmbH) & Georg Ledermann
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -70,10 +70,14 @@ sdd.add_transaction(
70
70
  # String, max. 34 chars
71
71
  iban: 'DE21500500009876543210',
72
72
 
73
- # Amount in EUR
73
+ # Amount
74
74
  # Number with two decimal digit
75
75
  amount: 39.99,
76
76
 
77
+ # OPTIONAL: Currency, EUR by default (ISO 4217 standard)
78
+ # String, 3 char
79
+ currency: 'EUR',
80
+
77
81
  # OPTIONAL: Instruction Identification, will not be submitted to the debtor
78
82
  # String, max. 35 char
79
83
  instruction: '12345',
@@ -166,10 +170,14 @@ sct.add_transaction(
166
170
  # String, max. 34 chars
167
171
  iban: 'DE37112589611964645802',
168
172
 
169
- # Amount in EUR
173
+ # Amount
170
174
  # Number with two decimal digit
171
175
  amount: 102.50,
172
176
 
177
+ # OPTIONAL: Currency, EUR by default (ISO 4217 standard)
178
+ # String, 3 char
179
+ currency: 'EUR',
180
+
173
181
  # OPTIONAL: Instruction Identification, will not be submitted to the creditor
174
182
  # String, max. 35 char
175
183
  instruction: '12345',
@@ -256,4 +264,4 @@ https://github.com/salesking/sepa_king/graphs/contributors
256
264
 
257
265
  Released under the MIT license
258
266
 
259
- Copyright (c) 2013-2016 Georg Leciejewski (SalesKing), Georg Ledermann (https://github.com/ledermann)
267
+ Copyright (c) 2013-2017 Georg Leciejewski (SalesKing), Georg Ledermann (https://github.com/ledermann)
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activemodel', '~> 5.1.0'
@@ -37,7 +37,14 @@ module SEPA
37
37
 
38
38
  def convert_decimal(value)
39
39
  return unless value
40
- BigDecimal(value.to_s).round(2)
40
+ value = begin
41
+ BigDecimal(value.to_s)
42
+ rescue ArgumentError
43
+ end
44
+
45
+ if value && value.finite? && value > 0
46
+ value.round(2)
47
+ end
41
48
  end
42
49
  end
43
50
  end
@@ -69,7 +69,7 @@ module SEPA
69
69
  builder.EndToEndId(transaction.reference)
70
70
  end
71
71
  builder.Amt do
72
- builder.InstdAmt('%.2f' % transaction.amount, Ccy: 'EUR')
72
+ builder.InstdAmt('%.2f' % transaction.amount, Ccy: transaction.currency)
73
73
  end
74
74
  if transaction.bic
75
75
  builder.CdtrAgt do
@@ -113,7 +113,7 @@ module SEPA
113
113
  end
114
114
  builder.EndToEndId(transaction.reference)
115
115
  end
116
- builder.InstdAmt('%.2f' % transaction.amount, Ccy: 'EUR')
116
+ builder.InstdAmt('%.2f' % transaction.amount, Ccy: transaction.currency)
117
117
  builder.DrctDbtTx do
118
118
  builder.MndtRltdInf do
119
119
  builder.MndtId(transaction.mandate_id)
@@ -14,10 +14,12 @@ module SEPA
14
14
 
15
15
  def schema_compatible?(schema_name)
16
16
  case schema_name
17
- when PAIN_001_001_03, PAIN_001_002_03
17
+ when PAIN_001_001_03
18
18
  self.bic.present? && self.service_level == 'SEPA'
19
+ when PAIN_001_002_03
20
+ self.bic.present? && self.service_level == 'SEPA' && self.currency == 'EUR'
19
21
  when PAIN_001_003_03
20
- true
22
+ self.currency == 'EUR'
21
23
  end
22
24
  end
23
25
  end
@@ -34,8 +34,10 @@ module SEPA
34
34
  def schema_compatible?(schema_name)
35
35
  case schema_name
36
36
  when PAIN_008_002_02
37
- self.bic.present? && %w(CORE B2B).include?(self.local_instrument)
38
- when PAIN_008_003_02, PAIN_008_001_02
37
+ self.bic.present? && %w(CORE B2B).include?(self.local_instrument) && self.currency == 'EUR'
38
+ when PAIN_008_003_02
39
+ self.currency == 'EUR'
40
+ when PAIN_008_001_02
39
41
  true
40
42
  end
41
43
  end
@@ -6,11 +6,12 @@ module SEPA
6
6
 
7
7
  DEFAULT_REQUESTED_DATE = Date.new(1999, 1, 1).freeze
8
8
 
9
- attr_accessor :name, :iban, :bic, :amount, :instruction, :reference, :remittance_information, :requested_date, :batch_booking
9
+ attr_accessor :name, :iban, :bic, :amount, :instruction, :reference, :remittance_information, :requested_date, :batch_booking, :currency
10
10
  convert :name, :instruction, :reference, :remittance_information, to: :text
11
11
  convert :amount, to: :decimal
12
12
 
13
13
  validates_length_of :name, within: 1..70
14
+ validates_length_of :currency, is: 3
14
15
  validates_length_of :instruction, within: 1..35, allow_nil: true
15
16
  validates_length_of :reference, within: 1..35, allow_nil: true
16
17
  validates_length_of :remittance_information, within: 1..140, allow_nil: true
@@ -27,6 +28,7 @@ module SEPA
27
28
  self.requested_date ||= DEFAULT_REQUESTED_DATE
28
29
  self.reference ||= 'NOTPROVIDED'
29
30
  self.batch_booking = true if self.batch_booking.nil?
31
+ self.currency ||= 'EUR'
30
32
  end
31
33
 
32
34
  protected
@@ -1,3 +1,3 @@
1
1
  module SEPA
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'
3
3
  end
data/sepa_king.gemspec CHANGED
@@ -29,5 +29,5 @@ Gem::Specification.new do |s|
29
29
  s.add_development_dependency 'coveralls'
30
30
  s.add_development_dependency 'simplecov'
31
31
  s.add_development_dependency 'rake'
32
- s.add_development_dependency 'nokogiri'
32
+ s.add_development_dependency 'nokogiri', RUBY_VERSION < '2.1.0' ? '~> 1.6.0' : '~> 1'
33
33
  end
@@ -56,5 +56,19 @@ describe SEPA::Converter do
56
56
  it 'should not touch nil' do
57
57
  expect(convert_decimal(nil)).to eq(nil)
58
58
  end
59
+
60
+ it 'should not convert zero value' do
61
+ expect(convert_decimal(0)).to eq(nil)
62
+ end
63
+
64
+ it 'should not convert negative value' do
65
+ expect(convert_decimal(-3)).to eq(nil)
66
+ end
67
+
68
+ it 'should not convert invalid value' do
69
+ expect(convert_decimal('xyz')).to eq(nil)
70
+ expect(convert_decimal('NaN')).to eq(nil)
71
+ expect(convert_decimal('Infinity')).to eq(nil)
72
+ end
59
73
  end
60
74
  end
@@ -288,6 +288,45 @@ describe SEPA::CreditTransfer do
288
288
  expect(subject).to have_xml('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/PmtId/InstrId', '1234/ABC')
289
289
  end
290
290
  end
291
+
292
+ context 'with a different currency given' do
293
+ subject do
294
+ sct = credit_transfer
295
+
296
+ sct.add_transaction name: 'Telekomiker AG',
297
+ iban: 'DE37112589611964645802',
298
+ bic: 'PBNKDEFF370',
299
+ amount: 102.50,
300
+ currency: 'CHF'
301
+
302
+ sct
303
+ end
304
+
305
+ it 'should validate against pain.001.001.03' do
306
+ expect(subject.to_xml('pain.001.001.03')).to validate_against('pain.001.001.03.xsd')
307
+ end
308
+
309
+ it 'should have a CHF Ccy' do
310
+ doc = Nokogiri::XML(subject.to_xml('pain.001.001.03'))
311
+ doc.remove_namespaces!
312
+
313
+ nodes = doc.xpath('//Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf[1]/Amt/InstdAmt')
314
+ expect(nodes.length).to eql(1)
315
+ expect(nodes.first.attribute('Ccy').value).to eql('CHF')
316
+ end
317
+
318
+ it 'should fail for pain.001.002.03' do
319
+ expect {
320
+ subject.to_xml(SEPA::PAIN_001_002_03)
321
+ }.to raise_error(RuntimeError)
322
+ end
323
+
324
+ it 'should fail for pain.001.003.03' do
325
+ expect {
326
+ subject.to_xml(SEPA::PAIN_001_003_03)
327
+ }.to raise_error(RuntimeError)
328
+ end
329
+ end
291
330
  end
292
331
  end
293
332
  end
@@ -17,19 +17,30 @@ describe SEPA::CreditTransferTransaction do
17
17
 
18
18
  describe :schema_compatible? do
19
19
  context 'for pain.001.003.03' do
20
- it 'should success' do
20
+ it 'should succeed' do
21
21
  expect(SEPA::CreditTransferTransaction.new({})).to be_schema_compatible('pain.001.003.03')
22
22
  end
23
+
24
+ it 'should fail for invalid attributes' do
25
+ expect(SEPA::CreditTransferTransaction.new(:currency => 'CHF')).not_to be_schema_compatible('pain.001.003.03')
26
+ end
23
27
  end
24
28
 
25
29
  context 'pain.001.002.03' do
26
- it 'should success for valid attributes' do
30
+ it 'should succeed for valid attributes' do
27
31
  expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'SEPA')).to be_schema_compatible('pain.001.002.03')
28
32
  end
29
33
 
30
34
  it 'should fail for invalid attributes' do
31
35
  expect(SEPA::CreditTransferTransaction.new(:bic => nil)).not_to be_schema_compatible('pain.001.002.03')
32
36
  expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :service_level => 'URGP')).not_to be_schema_compatible('pain.001.002.03')
37
+ expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'CHF')).not_to be_schema_compatible('pain.001.002.03')
38
+ end
39
+ end
40
+
41
+ context 'for pain.001.001.03' do
42
+ it 'should succeed for valid attributes' do
43
+ expect(SEPA::CreditTransferTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'CHF')).to be_schema_compatible('pain.001.001.03')
33
44
  end
34
45
  end
35
46
  end
@@ -429,6 +429,41 @@ describe SEPA::DirectDebit do
429
429
  expect(subject).to have_xml('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/PmtId/InstrId', '1234/ABC')
430
430
  end
431
431
  end
432
+
433
+ context 'with a different currency given' do
434
+ subject do
435
+ sct = direct_debit
436
+
437
+ sct.add_transaction(direct_debt_transaction.merge(instruction: '1234/ABC', currency: 'SEK'))
438
+
439
+ sct
440
+ end
441
+
442
+ it 'should validate against pain.001.001.03' do
443
+ expect(subject.to_xml(SEPA::PAIN_008_001_02)).to validate_against('pain.008.001.02.xsd')
444
+ end
445
+
446
+ it 'should have a CHF Ccy' do
447
+ doc = Nokogiri::XML(subject.to_xml('pain.008.001.02'))
448
+ doc.remove_namespaces!
449
+
450
+ nodes = doc.xpath('//Document/CstmrDrctDbtInitn/PmtInf/DrctDbtTxInf[1]/InstdAmt')
451
+ expect(nodes.length).to eql(1)
452
+ expect(nodes.first.attribute('Ccy').value).to eql('SEK')
453
+ end
454
+
455
+ it 'should fail for pain.008.002.02' do
456
+ expect {
457
+ subject.to_xml(SEPA::PAIN_008_002_02)
458
+ }.to raise_error(RuntimeError)
459
+ end
460
+
461
+ it 'should fail for pain.008.003.02' do
462
+ expect {
463
+ subject.to_xml(SEPA::PAIN_008_003_02)
464
+ }.to raise_error(RuntimeError)
465
+ end
466
+ end
432
467
  end
433
468
  end
434
469
  end
@@ -19,19 +19,30 @@ describe SEPA::DirectDebitTransaction do
19
19
 
20
20
  describe :schema_compatible? do
21
21
  context 'for pain.008.003.02' do
22
- it 'should success' do
22
+ it 'should succeed' do
23
23
  expect(SEPA::DirectDebitTransaction.new({})).to be_schema_compatible('pain.008.003.02')
24
24
  end
25
+
26
+ it 'should fail for invalid attributes' do
27
+ expect(SEPA::DirectDebitTransaction.new(:currency => 'CHF')).not_to be_schema_compatible('pain.001.003.03')
28
+ end
25
29
  end
26
30
 
27
31
  context 'for pain.008.002.02' do
28
- it 'should success for valid attributes' do
32
+ it 'should succeed for valid attributes' do
29
33
  expect(SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :local_instrument => 'CORE')).to be_schema_compatible('pain.008.002.02')
30
34
  end
31
35
 
32
36
  it 'should fail for invalid attributes' do
33
37
  expect(SEPA::DirectDebitTransaction.new(:bic => nil)).not_to be_schema_compatible('pain.008.002.02')
34
38
  expect(SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :local_instrument => 'COR1')).not_to be_schema_compatible('pain.008.002.02')
39
+ expect(SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'CHF')).not_to be_schema_compatible('pain.008.002.02')
40
+ end
41
+ end
42
+
43
+ context 'for pain.008.001.02' do
44
+ it 'should succeed for valid attributes' do
45
+ expect(SEPA::DirectDebitTransaction.new(:bic => 'SPUEDE2UXXX', :currency => 'CHF')).to be_schema_compatible('pain.008.001.02')
35
46
  end
36
47
  end
37
48
  end
@@ -75,4 +75,14 @@ describe SEPA::Transaction do
75
75
  expect(SEPA::Transaction).not_to accept('', 'X' * 141, for: :remittance_information)
76
76
  end
77
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
78
88
  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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Leciejewski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-15 00:00:00.000000000 Z
12
+ date: 2017-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -127,16 +127,16 @@ dependencies:
127
127
  name: nokogiri
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - ">="
130
+ - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: '0'
132
+ version: '1'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - ">="
137
+ - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: '0'
139
+ version: '1'
140
140
  description: Implemention of pain.001.002.03 and pain.008.002.02 (ISO 20022)
141
141
  email:
142
142
  - gl@salesking.eu
@@ -160,6 +160,7 @@ files:
160
160
  - gemfiles/Gemfile-activemodel-4.1.x
161
161
  - gemfiles/Gemfile-activemodel-4.2.x
162
162
  - gemfiles/Gemfile-activemodel-5.0.x
163
+ - gemfiles/Gemfile-activemodel-5.1.x
163
164
  - lib/schema/pain.001.001.03.xsd
164
165
  - lib/schema/pain.001.002.03.xsd
165
166
  - lib/schema/pain.001.003.03.xsd
@@ -222,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  version: '0'
223
224
  requirements: []
224
225
  rubyforge_project:
225
- rubygems_version: 2.6.8
226
+ rubygems_version: 2.6.12
226
227
  signing_key:
227
228
  specification_version: 4
228
229
  summary: Ruby gem for creating SEPA XML files