sepa_king_codeur 0.12.1

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 (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +37 -0
  5. data/CONTRIBUTING.md +38 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +297 -0
  9. data/Rakefile +6 -0
  10. data/gemfiles/Gemfile-activemodel-3.1.x +5 -0
  11. data/gemfiles/Gemfile-activemodel-3.2.x +5 -0
  12. data/gemfiles/Gemfile-activemodel-4.0.x +5 -0
  13. data/gemfiles/Gemfile-activemodel-4.1.x +5 -0
  14. data/gemfiles/Gemfile-activemodel-4.2.x +5 -0
  15. data/gemfiles/Gemfile-activemodel-5.0.x +5 -0
  16. data/gemfiles/Gemfile-activemodel-5.1.x +5 -0
  17. data/gemfiles/Gemfile-activemodel-5.2.x +5 -0
  18. data/gemfiles/Gemfile-activemodel-6.0.x +5 -0
  19. data/lib/schema/pain.001.001.03.ch.02.xsd +1212 -0
  20. data/lib/schema/pain.001.001.03.xsd +921 -0
  21. data/lib/schema/pain.001.002.03.xsd +450 -0
  22. data/lib/schema/pain.001.003.03.xsd +474 -0
  23. data/lib/schema/pain.008.001.02.xsd +879 -0
  24. data/lib/schema/pain.008.002.02.xsd +597 -0
  25. data/lib/schema/pain.008.003.02.xsd +614 -0
  26. data/lib/sepa_king.rb +19 -0
  27. data/lib/sepa_king/account.rb +19 -0
  28. data/lib/sepa_king/account/creditor_account.rb +8 -0
  29. data/lib/sepa_king/account/creditor_address.rb +37 -0
  30. data/lib/sepa_king/account/debtor_account.rb +5 -0
  31. data/lib/sepa_king/account/debtor_address.rb +37 -0
  32. data/lib/sepa_king/converter.rb +51 -0
  33. data/lib/sepa_king/error.rb +4 -0
  34. data/lib/sepa_king/message.rb +169 -0
  35. data/lib/sepa_king/message/credit_transfer.rb +137 -0
  36. data/lib/sepa_king/message/direct_debit.rb +207 -0
  37. data/lib/sepa_king/transaction.rb +56 -0
  38. data/lib/sepa_king/transaction/credit_transfer_transaction.rb +31 -0
  39. data/lib/sepa_king/transaction/direct_debit_transaction.rb +56 -0
  40. data/lib/sepa_king/validator.rb +57 -0
  41. data/lib/sepa_king/version.rb +3 -0
  42. data/sepa_king.gemspec +33 -0
  43. data/spec/account_spec.rb +42 -0
  44. data/spec/converter_spec.rb +74 -0
  45. data/spec/credit_transfer_spec.rb +520 -0
  46. data/spec/credit_transfer_transaction_spec.rb +74 -0
  47. data/spec/creditor_account_spec.rb +23 -0
  48. data/spec/debtor_account_spec.rb +12 -0
  49. data/spec/debtor_address_spec.rb +12 -0
  50. data/spec/direct_debit_spec.rb +657 -0
  51. data/spec/direct_debit_transaction_spec.rb +69 -0
  52. data/spec/examples/pain.001.001.03.ch.02.xml +172 -0
  53. data/spec/examples/pain.001.001.03.xml +89 -0
  54. data/spec/examples/pain.001.002.03.xml +89 -0
  55. data/spec/examples/pain.001.003.03.xml +89 -0
  56. data/spec/examples/pain.008.002.02.xml +134 -0
  57. data/spec/examples/pain.008.003.02.xml +134 -0
  58. data/spec/message_spec.rb +128 -0
  59. data/spec/spec_helper.rb +33 -0
  60. data/spec/support/active_model.rb +30 -0
  61. data/spec/support/custom_matcher.rb +60 -0
  62. data/spec/support/factories.rb +24 -0
  63. data/spec/support/validations.rb +27 -0
  64. data/spec/transaction_spec.rb +134 -0
  65. data/spec/validation_spec.rb +25 -0
  66. data/spec/validator_spec.rb +99 -0
  67. metadata +250 -0
@@ -0,0 +1,134 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.002.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.008.002.02 pain.008.002.02.xsd">
3
+ <CstmrDrctDbtInitn>
4
+ <GrpHdr>
5
+ <MsgId>Message-ID</MsgId>
6
+ <CreDtTm>2010-11-21T09:30:47.000Z</CreDtTm>
7
+ <NbOfTxs>2</NbOfTxs>
8
+ <InitgPty>
9
+ <Nm>Initiator Name</Nm>
10
+ </InitgPty>
11
+ </GrpHdr>
12
+ <PmtInf>
13
+ <PmtInfId>Payment-ID</PmtInfId>
14
+ <PmtMtd>DD</PmtMtd>
15
+ <NbOfTxs>2</NbOfTxs>
16
+ <CtrlSum>6655.86</CtrlSum>
17
+ <PmtTpInf>
18
+ <SvcLvl>
19
+ <Cd>SEPA</Cd>
20
+ </SvcLvl>
21
+ <LclInstrm>
22
+ <Cd>CORE</Cd>
23
+ </LclInstrm>
24
+ <SeqTp>FRST</SeqTp>
25
+ </PmtTpInf>
26
+ <ReqdColltnDt>2010-12-03</ReqdColltnDt>
27
+ <Cdtr>
28
+ <Nm>Creditor Name</Nm>
29
+ </Cdtr>
30
+ <CdtrAcct>
31
+ <Id>
32
+ <IBAN>DE87200500001234567890</IBAN>
33
+ </Id>
34
+ </CdtrAcct>
35
+ <CdtrAgt>
36
+ <FinInstnId>
37
+ <BIC>BANKDEFFXXX</BIC>
38
+ </FinInstnId>
39
+ </CdtrAgt>
40
+ <ChrgBr>SLEV</ChrgBr>
41
+ <CdtrSchmeId>
42
+ <Id>
43
+ <PrvtId>
44
+ <Othr>
45
+ <Id>DE00ZZZ00099999999</Id>
46
+ <SchmeNm>
47
+ <Prtry>SEPA</Prtry>
48
+ </SchmeNm>
49
+ </Othr>
50
+ </PrvtId>
51
+ </Id>
52
+ </CdtrSchmeId>
53
+ <DrctDbtTxInf>
54
+ <PmtId>
55
+ <EndToEndId>OriginatorID1234</EndToEndId>
56
+ </PmtId>
57
+ <InstdAmt Ccy="EUR">6543.14</InstdAmt>
58
+ <DrctDbtTx>
59
+ <MndtRltdInf>
60
+ <MndtId>Mandate-Id</MndtId>
61
+ <DtOfSgntr>2010-11-20</DtOfSgntr>
62
+ <AmdmntInd>true</AmdmntInd>
63
+ <AmdmntInfDtls>
64
+ <OrgnlCdtrSchmeId>
65
+ <Nm>Original Creditor Name</Nm>
66
+ <Id>
67
+ <PrvtId>
68
+ <Othr>
69
+ <Id>AA00ZZZOriginalCreditorID</Id>
70
+ <SchmeNm>
71
+ <Prtry>SEPA</Prtry>
72
+ </SchmeNm>
73
+ </Othr>
74
+ </PrvtId>
75
+ </Id>
76
+ </OrgnlCdtrSchmeId>
77
+ </AmdmntInfDtls>
78
+ </MndtRltdInf>
79
+ </DrctDbtTx>
80
+ <DbtrAgt>
81
+ <FinInstnId>
82
+ <BIC>SPUEDE2UXXX</BIC>
83
+ </FinInstnId>
84
+ </DbtrAgt>
85
+ <Dbtr>
86
+ <Nm>Debtor Name</Nm>
87
+ </Dbtr>
88
+ <DbtrAcct>
89
+ <Id>
90
+ <IBAN>DE21500500009876543210</IBAN>
91
+ </Id>
92
+ </DbtrAcct>
93
+ <UltmtDbtr>
94
+ <Nm>Ultimate Debtor Name</Nm>
95
+ </UltmtDbtr>
96
+ <RmtInf>
97
+ <Ustrd>Unstructured Remittance Information</Ustrd>
98
+ </RmtInf>
99
+ </DrctDbtTxInf>
100
+ <DrctDbtTxInf>
101
+ <PmtId>
102
+ <EndToEndId>OriginatorID1235</EndToEndId>
103
+ </PmtId>
104
+ <InstdAmt Ccy="EUR">112.72</InstdAmt>
105
+ <DrctDbtTx>
106
+ <MndtRltdInf>
107
+ <MndtId>Other-Mandate-Id</MndtId>
108
+ <DtOfSgntr>2010-11-20</DtOfSgntr>
109
+ <AmdmntInd>false</AmdmntInd>
110
+ </MndtRltdInf>
111
+ </DrctDbtTx>
112
+ <DbtrAgt>
113
+ <FinInstnId>
114
+ <BIC>SPUEDE2UXXX</BIC>
115
+ </FinInstnId>
116
+ </DbtrAgt>
117
+ <Dbtr>
118
+ <Nm>Other Debtor Name</Nm>
119
+ </Dbtr>
120
+ <DbtrAcct>
121
+ <Id>
122
+ <IBAN>DE21500500001234567897</IBAN>
123
+ </Id>
124
+ </DbtrAcct>
125
+ <UltmtDbtr>
126
+ <Nm>Ultimate Debtor Name</Nm>
127
+ </UltmtDbtr>
128
+ <RmtInf>
129
+ <Ustrd>Unstructured Remittance Information</Ustrd>
130
+ </RmtInf>
131
+ </DrctDbtTxInf>
132
+ </PmtInf>
133
+ </CstmrDrctDbtInitn>
134
+ </Document>
@@ -0,0 +1,134 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.003.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.008.003.02 pain.008.003.02.xsd">
3
+ <CstmrDrctDbtInitn>
4
+ <GrpHdr>
5
+ <MsgId>Message-ID</MsgId>
6
+ <CreDtTm>2010-11-21T09:30:47.000Z</CreDtTm>
7
+ <NbOfTxs>2</NbOfTxs>
8
+ <InitgPty>
9
+ <Nm>Initiator Name</Nm>
10
+ </InitgPty>
11
+ </GrpHdr>
12
+ <PmtInf>
13
+ <PmtInfId>Payment-ID</PmtInfId>
14
+ <PmtMtd>DD</PmtMtd>
15
+ <NbOfTxs>2</NbOfTxs>
16
+ <CtrlSum>6655.86</CtrlSum>
17
+ <PmtTpInf>
18
+ <SvcLvl>
19
+ <Cd>SEPA</Cd>
20
+ </SvcLvl>
21
+ <LclInstrm>
22
+ <Cd>CORE</Cd>
23
+ </LclInstrm>
24
+ <SeqTp>FRST</SeqTp>
25
+ </PmtTpInf>
26
+ <ReqdColltnDt>2010-12-03</ReqdColltnDt>
27
+ <Cdtr>
28
+ <Nm>Creditor Name</Nm>
29
+ </Cdtr>
30
+ <CdtrAcct>
31
+ <Id>
32
+ <IBAN>DE87200500001234567890</IBAN>
33
+ </Id>
34
+ </CdtrAcct>
35
+ <CdtrAgt>
36
+ <FinInstnId>
37
+ <BIC>BANKDEFFXXX</BIC>
38
+ </FinInstnId>
39
+ </CdtrAgt>
40
+ <ChrgBr>SLEV</ChrgBr>
41
+ <CdtrSchmeId>
42
+ <Id>
43
+ <PrvtId>
44
+ <Othr>
45
+ <Id>DE00ZZZ00099999999</Id>
46
+ <SchmeNm>
47
+ <Prtry>SEPA</Prtry>
48
+ </SchmeNm>
49
+ </Othr>
50
+ </PrvtId>
51
+ </Id>
52
+ </CdtrSchmeId>
53
+ <DrctDbtTxInf>
54
+ <PmtId>
55
+ <EndToEndId>OriginatorID1234</EndToEndId>
56
+ </PmtId>
57
+ <InstdAmt Ccy="EUR">6543.14</InstdAmt>
58
+ <DrctDbtTx>
59
+ <MndtRltdInf>
60
+ <MndtId>Mandate-Id</MndtId>
61
+ <DtOfSgntr>2010-11-20</DtOfSgntr>
62
+ <AmdmntInd>true</AmdmntInd>
63
+ <AmdmntInfDtls>
64
+ <OrgnlCdtrSchmeId>
65
+ <Nm>Original Creditor Name</Nm>
66
+ <Id>
67
+ <PrvtId>
68
+ <Othr>
69
+ <Id>AA00ZZZOriginalCreditorID</Id>
70
+ <SchmeNm>
71
+ <Prtry>SEPA</Prtry>
72
+ </SchmeNm>
73
+ </Othr>
74
+ </PrvtId>
75
+ </Id>
76
+ </OrgnlCdtrSchmeId>
77
+ </AmdmntInfDtls>
78
+ </MndtRltdInf>
79
+ </DrctDbtTx>
80
+ <DbtrAgt>
81
+ <FinInstnId>
82
+ <BIC>SPUEDE2UXXX</BIC>
83
+ </FinInstnId>
84
+ </DbtrAgt>
85
+ <Dbtr>
86
+ <Nm>Debtor Name</Nm>
87
+ </Dbtr>
88
+ <DbtrAcct>
89
+ <Id>
90
+ <IBAN>DE21500500009876543210</IBAN>
91
+ </Id>
92
+ </DbtrAcct>
93
+ <UltmtDbtr>
94
+ <Nm>Ultimate Debtor Name</Nm>
95
+ </UltmtDbtr>
96
+ <RmtInf>
97
+ <Ustrd>Unstructured Remittance Information</Ustrd>
98
+ </RmtInf>
99
+ </DrctDbtTxInf>
100
+ <DrctDbtTxInf>
101
+ <PmtId>
102
+ <EndToEndId>OriginatorID1235</EndToEndId>
103
+ </PmtId>
104
+ <InstdAmt Ccy="EUR">112.72</InstdAmt>
105
+ <DrctDbtTx>
106
+ <MndtRltdInf>
107
+ <MndtId>Other-Mandate-Id</MndtId>
108
+ <DtOfSgntr>2010-11-20</DtOfSgntr>
109
+ <AmdmntInd>false</AmdmntInd>
110
+ </MndtRltdInf>
111
+ </DrctDbtTx>
112
+ <DbtrAgt>
113
+ <FinInstnId>
114
+ <BIC>SPUEDE2UXXX</BIC>
115
+ </FinInstnId>
116
+ </DbtrAgt>
117
+ <Dbtr>
118
+ <Nm>Other Debtor Name</Nm>
119
+ </Dbtr>
120
+ <DbtrAcct>
121
+ <Id>
122
+ <IBAN>DE21500500001234567897</IBAN>
123
+ </Id>
124
+ </DbtrAcct>
125
+ <UltmtDbtr>
126
+ <Nm>Ultimate Debtor Name</Nm>
127
+ </UltmtDbtr>
128
+ <RmtInf>
129
+ <Ustrd>Unstructured Remittance Information</Ustrd>
130
+ </RmtInf>
131
+ </DrctDbtTxInf>
132
+ </PmtInf>
133
+ </CstmrDrctDbtInitn>
134
+ </Document>
@@ -0,0 +1,128 @@
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 = SEPA::Account
10
+ self.transaction_class = DummyTransaction
11
+ end
12
+
13
+ describe SEPA::Message do
14
+ describe :amount_total do
15
+ subject do
16
+ message = DummyMessage.new
17
+ message.add_transaction amount: 1.1
18
+ message.add_transaction amount: 2.2
19
+ message
20
+ end
21
+
22
+ it 'should sum up all transactions' do
23
+ expect(subject.amount_total).to eq(3.3)
24
+ end
25
+
26
+ it 'should sum up selected transactions' do
27
+ expect(subject.amount_total([subject.transactions[0]])).to eq(1.1)
28
+ end
29
+ end
30
+
31
+ describe 'validation' do
32
+ subject { DummyMessage.new }
33
+
34
+ it 'should fail with invalid account' do
35
+ expect(subject).not_to be_valid
36
+ expect(subject.errors_on(:account).size).to eq(2)
37
+ end
38
+
39
+ it 'should fail without transactions' do
40
+ expect(subject).not_to be_valid
41
+ expect(subject.errors_on(:transactions).size).to eq(1)
42
+ end
43
+ end
44
+
45
+ describe :message_identification do
46
+ subject { DummyMessage.new }
47
+
48
+ describe 'getter' do
49
+ it 'should return prefixed random hex string' do
50
+ expect(subject.message_identification).to match(/SEPA-KING\/([a-f0-9]{2}){11}/)
51
+ end
52
+ end
53
+
54
+ describe 'setter' do
55
+ it 'should accept valid ID' do
56
+ [ 'gid://myMoneyApp/Payment/15108', # for example, Rails Global ID could be a candidate
57
+ Time.now.to_f.to_s # or a time based string
58
+ ].each do |valid_msgid|
59
+ subject.message_identification = valid_msgid
60
+ expect(subject.message_identification).to eq(valid_msgid)
61
+ end
62
+ end
63
+
64
+ it 'should deny invalid string' do
65
+ [ 'my_MESSAGE_ID/123', # contains underscore
66
+ '', # blank string
67
+ 'üöäß', # non-ASCII chars
68
+ '1' * 36 # too long
69
+ ].each do |arg|
70
+ expect {
71
+ subject.message_identification = arg
72
+ }.to raise_error(ArgumentError)
73
+ end
74
+ end
75
+
76
+ it 'should deny argument other than String' do
77
+ [ 123,
78
+ nil,
79
+ :foo
80
+ ].each do |arg|
81
+ expect {
82
+ subject.message_identification = arg
83
+ }.to raise_error(ArgumentError)
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ describe :creation_date_time do
90
+ subject { DummyMessage.new }
91
+
92
+ describe 'getter' do
93
+ it 'should return Time.now.iso8601' do
94
+ expect(subject.creation_date_time).to eq(Time.now.iso8601)
95
+ end
96
+ end
97
+
98
+ describe 'setter' do
99
+ it 'should accept date time strings' do
100
+ ['2017-01-05T12:28:52', '2017-01-05T12:28:52Z', '2017-01-05 12:28:52', '2017-01-05T12:28:52+01:00'].each do |valid_dt|
101
+ subject.creation_date_time = valid_dt
102
+ expect(subject.creation_date_time).to eq(valid_dt)
103
+ end
104
+ end
105
+
106
+ it 'should deny invalid string' do
107
+ [ 'an arbitrary string',
108
+ ''
109
+ ].each do |arg|
110
+ expect {
111
+ subject.creation_date_time = arg
112
+ }.to raise_error(ArgumentError)
113
+ end
114
+ end
115
+
116
+ it 'should deny argument other than String' do
117
+ [ 123,
118
+ nil,
119
+ :foo
120
+ ].each do |arg|
121
+ expect {
122
+ subject.creation_date_time = arg
123
+ }.to raise_error(ArgumentError)
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,33 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+
6
+ require 'simplecov'
7
+ require 'coveralls'
8
+
9
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
10
+ SimpleCov::Formatter::HTMLFormatter,
11
+ Coveralls::SimpleCov::Formatter
12
+ ])
13
+ SimpleCov.start do
14
+ add_filter '/spec/'
15
+ end
16
+
17
+ require 'sepa_king'
18
+
19
+ # Requires supporting ruby files with custom matchers and macros, etc,
20
+ # in spec/support/ and its subdirectories.
21
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
22
+
23
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
+ RSpec.configure do |config|
25
+ config.run_all_when_everything_filtered = true
26
+ config.filter_run :focus
27
+
28
+ # Run specs in random order to surface order dependencies. If you find an
29
+ # order dependency and want to debug it, you can fix the order by providing
30
+ # the seed, which is printed after each run.
31
+ # --seed 1234
32
+ config.order = 'random'
33
+ end
@@ -0,0 +1,30 @@
1
+ unless defined?(ActiveModel::Model)
2
+ # ActiveModel::Model is available since ActiveModel 4.0 only.
3
+ #
4
+ # If it's missing, add the code from
5
+ # https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb
6
+ module ActiveModel
7
+ module Model
8
+ def self.included(base)
9
+ base.class_eval do
10
+ extend ActiveModel::Naming
11
+ extend ActiveModel::Translation
12
+ include ActiveModel::Validations
13
+ include ActiveModel::Conversion
14
+ end
15
+ end
16
+
17
+ def initialize(params={})
18
+ params.each do |attr, value|
19
+ self.public_send("#{attr}=", value)
20
+ end if params
21
+
22
+ super()
23
+ end
24
+
25
+ def persisted?
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end