hbci 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rubocop.yml +26 -0
  4. data/.rubocop_todo.yml +26 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +1 -0
  7. data/Gemfile +5 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +107 -0
  10. data/Rakefile +8 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +7 -0
  13. data/examples/credentials.rb +62 -0
  14. data/examples/get_accounts.rb +11 -0
  15. data/examples/get_balance.rb +8 -0
  16. data/examples/get_system_id.rb +6 -0
  17. data/examples/get_transactions.rb +15 -0
  18. data/hbci.gemspec +36 -0
  19. data/lib/development_profiler.rb +26 -0
  20. data/lib/hbci.rb +66 -0
  21. data/lib/hbci/connector.rb +33 -0
  22. data/lib/hbci/dialog.rb +77 -0
  23. data/lib/hbci/element_group.rb +93 -0
  24. data/lib/hbci/element_groups/generated_element_groups.rb +969 -0
  25. data/lib/hbci/element_groups/segment_head.rb +12 -0
  26. data/lib/hbci/element_groups/unknown.rb +11 -0
  27. data/lib/hbci/element_unparser.rb +21 -0
  28. data/lib/hbci/message.rb +47 -0
  29. data/lib/hbci/message_factory.rb +17 -0
  30. data/lib/hbci/parser.rb +114 -0
  31. data/lib/hbci/request.rb +32 -0
  32. data/lib/hbci/response.rb +25 -0
  33. data/lib/hbci/segment.rb +118 -0
  34. data/lib/hbci/segment_factory.rb +15 -0
  35. data/lib/hbci/segments/hikaz.rb +29 -0
  36. data/lib/hbci/segments/hikazs.rb +31 -0
  37. data/lib/hbci/segments/hirmg.rb +10 -0
  38. data/lib/hbci/segments/hirms.rb +17 -0
  39. data/lib/hbci/segments/hisal.rb +100 -0
  40. data/lib/hbci/segments/hisals.rb +19 -0
  41. data/lib/hbci/segments/hisyn.rb +11 -0
  42. data/lib/hbci/segments/hiupa.rb +12 -0
  43. data/lib/hbci/segments/hiupd.rb +37 -0
  44. data/lib/hbci/segments/hkend.rb +14 -0
  45. data/lib/hbci/segments/hkidn.rb +22 -0
  46. data/lib/hbci/segments/hkkaz.rb +25 -0
  47. data/lib/hbci/segments/hksal.rb +31 -0
  48. data/lib/hbci/segments/hksyn.rb +12 -0
  49. data/lib/hbci/segments/hkvvb.rb +18 -0
  50. data/lib/hbci/segments/hnhbk.rb +27 -0
  51. data/lib/hbci/segments/hnhbs.rb +14 -0
  52. data/lib/hbci/segments/hnsha.rb +31 -0
  53. data/lib/hbci/segments/hnshk.rb +79 -0
  54. data/lib/hbci/segments/hnvsd.rb +50 -0
  55. data/lib/hbci/segments/hnvsk.rb +60 -0
  56. data/lib/hbci/segments/segment_head.rb +11 -0
  57. data/lib/hbci/segments/unknown.rb +21 -0
  58. data/lib/hbci/services/accounts_receiver.rb +19 -0
  59. data/lib/hbci/services/balance_receiver.rb +69 -0
  60. data/lib/hbci/services/base_receiver.rb +43 -0
  61. data/lib/hbci/services/system_id_receiver.rb +35 -0
  62. data/lib/hbci/services/transactions_receiver.rb +75 -0
  63. data/lib/hbci/version.rb +5 -0
  64. metadata +315 -0
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HIKAZSv6 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element :max_entries
8
+ element :min_signatures
9
+ element :security_class
10
+ element_group :account do
11
+ element :retention_period
12
+ element :allowed_input_entry_quantity
13
+ element :allowed_request_all_accounts
14
+ element :data_format
15
+ end
16
+ end
17
+
18
+ class HIKAZSv7 < Segment
19
+ element_group :head, type: ElementGroups::SegmentHead
20
+ element :max_entries
21
+ element :min_signatures
22
+ element :security_class
23
+ element_group :account do
24
+ element :retention_period
25
+ element :allowed_input_entry_quantity
26
+ element :allowed_request_all_accounts
27
+ element :data_format
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ module Hbci
2
+ module Segments
3
+ class HIRMGv2 < Segment
4
+ element_group :head, type: ElementGroups::SegmentHead
5
+ 1.upto(99) do |i|
6
+ element_group "ret_val_#{i}".to_sym, type: ElementGroups::RetVal
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HIRMSv2 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ 1.upto(99) do |i|
8
+ element_group "ret_val_#{i}".to_sym, type: ElementGroups::RetVal
9
+ end
10
+
11
+ def allowed_tan_mechanism
12
+ groups_with_status_code = element_groups.select { |eg| eg.respond_to?(:code) && eg.code == '3920' }
13
+ groups_with_status_code.first.parm if groups_with_status_code.any?
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HISALv3 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element_group :ktv, type: ElementGroups::KTO
8
+ element :kontobez
9
+ element :curr
10
+ element_group :booked, type: ElementGroups::Saldo
11
+ element_group :pending, type: ElementGroups::Saldo
12
+ element_group :kredit, type: ElementGroups::BTG
13
+ element_group :available, type: ElementGroups::BTG
14
+ element_group :used, type: ElementGroups::BTG
15
+ end
16
+
17
+ class HISALv4 < Segment
18
+ element_group :head, type: ElementGroups::SegmentHead
19
+ element_group :ktv, type: ElementGroups::KTO
20
+ element :kontobez
21
+ element :curr
22
+ element_group :booked, type: ElementGroups::Saldo
23
+ element_group :pending, type: ElementGroups::Saldo
24
+ element_group :kredit, type: ElementGroups::BTG
25
+ element_group :available, type: ElementGroups::BTG
26
+ element_group :used, type: ElementGroups::BTG
27
+ element :timestamp_date
28
+ element :timestamp_time
29
+
30
+ def booked_amount
31
+ sign = case booked.credit_debit
32
+ when 'C' then 1
33
+ when 'D' then -1
34
+ end
35
+ sign * Monetize.parse(booked.btg_value, booked.btg_curr)
36
+ end
37
+ end
38
+
39
+ class HISALv5 < Segment
40
+ element_group :head, type: ElementGroups::SegmentHead
41
+ element_group :ktv, type: ElementGroups::KTV2
42
+ element :kontobez
43
+ element :curr
44
+ element_group :booked, type: ElementGroups::Saldo
45
+ element_group :pending, type: ElementGroups::Saldo
46
+ element_group :kredit, type: ElementGroups::BTG
47
+ element_group :available, type: ElementGroups::BTG
48
+ element_group :used, type: ElementGroups::BTG
49
+ element :timestamp_date
50
+ element :timestamp_time
51
+ element :duedate
52
+ end
53
+
54
+ class HISALv6 < Segment
55
+ element_group :head, type: ElementGroups::SegmentHead
56
+ element_group :ktv, type: ElementGroups::KTV3
57
+ element :kontobez
58
+ element :curr
59
+ element_group :booked, type: ElementGroups::Saldo2
60
+ element_group :pending, type: ElementGroups::Saldo2
61
+ element_group :kredit, type: ElementGroups::BTG
62
+ element_group :available, type: ElementGroups::BTG
63
+ element_group :used, type: ElementGroups::BTG
64
+ element_group :overdrive, type: ElementGroups::BTG
65
+ element_group :timestamp, type: ElementGroups::Timestamp
66
+ element :duedate
67
+
68
+ def booked_amount
69
+ sign = case booked.credit_debit
70
+ when 'C' then 1
71
+ when 'D' then -1
72
+ end
73
+ sign * Monetize.parse(booked.value, booked.curr)
74
+ end
75
+ end
76
+
77
+ class HISALv7 < Segment
78
+ element_group :head, type: ElementGroups::SegmentHead
79
+ element_group :ktv, type: ElementGroups::KTVInt
80
+ element :kontobez
81
+ element :curr
82
+ element_group :booked, type: ElementGroups::Saldo2
83
+ element_group :pending, type: ElementGroups::Saldo2
84
+ element_group :kredit, type: ElementGroups::BTG
85
+ element_group :available, type: ElementGroups::BTG
86
+ element_group :used, type: ElementGroups::BTG
87
+ element_group :overdrive, type: ElementGroups::BTG
88
+ element_group :timestamp, type: ElementGroups::Timestamp
89
+ element :duedate
90
+
91
+ def booked_amount
92
+ sign = case booked.credit_debit
93
+ when 'C' then 1
94
+ when 'D' then -1
95
+ end
96
+ sign * Monetize.parse(booked.value, booked.curr)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HISALSv4 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element :max_entries
8
+ element :min_signatures
9
+ element :security_class
10
+ end
11
+
12
+ class HISALSv7 < Segment
13
+ element_group :head, type: ElementGroups::SegmentHead
14
+ element :max_entries
15
+ element :min_signatures
16
+ element :security_class
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Hbci
2
+ module Segments
3
+ class HISYNv4 < Segment
4
+ element_group :head, type: ElementGroups::SegmentHead
5
+ element :system_id
6
+ element :msg_number
7
+ element :sec_ref_key
8
+ element :sec_ref_sig
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HIUPAv4 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element :user_id
8
+ element :upd_version
9
+ element :upd_usage
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HIUPDv5 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element_group :ktv, type: ElementGroups::KTV2
8
+ element :customerid
9
+ element :acctype
10
+ element :cur
11
+ element :name1
12
+ element :name2
13
+ element :konto
14
+ element_group :k_limit, type: ElementGroups::KLimit
15
+ 10.times do |i|
16
+ element_group "allowed_gv_#{i}".to_sym, type: ElementGroups::AllowedGV
17
+ end
18
+ end
19
+
20
+ class HIUPDv6 < Segment
21
+ element_group :head, type: ElementGroups::SegmentHead
22
+ element_group :ktv, type: ElementGroups::KTV2
23
+ element :iban
24
+ element :user_id
25
+ element :account_type
26
+ element :currency
27
+ element :name_1
28
+ element :name_2
29
+ element :konto
30
+ element_group :k_limit, type: ElementGroups::KLimit
31
+ 999.times do |i|
32
+ element_group "allowed_gv_#{i}".to_sym, type: ElementGroups::AllowedGV
33
+ end
34
+ element :accountdata
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HKENDv1 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element :dialog_id
8
+
9
+ def compile
10
+ self.dialog_id = request_message.dialog.id
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HKIDNv2 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element_group :bank do
8
+ element :country_code, default: 280
9
+ element :code # blz
10
+ end
11
+ element :user_id # "kunden_id"
12
+ element :system_id
13
+ element :state, default: 1
14
+
15
+ def compile
16
+ self.bank.code = Connector.instance.credentials.bank_code
17
+ self.user_id = Connector.instance.credentials.user_id
18
+ self.system_id = request_message.dialog ? request_message.dialog.system_id : 0
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HKKAZv6 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element_group :account, type: ElementGroups::KTV2
8
+ element :all_accounts, default: 'N'
9
+ element :from
10
+ element :to
11
+ element :max_entries
12
+ element :attach
13
+ end
14
+
15
+ class HKKAZv7 < Segment
16
+ element_group :head, type: ElementGroups::SegmentHead
17
+ element_group :account, type: ElementGroups::KTVInt
18
+ element :all_accounts, default: 'N'
19
+ element :from
20
+ element :to
21
+ element :max_entries
22
+ element :attach
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HKSALv4 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element_group :account do
8
+ element :number
9
+ element :country, default: 280
10
+ element :code # blz
11
+ end
12
+ element :all_accounts, default: 'N'
13
+ end
14
+
15
+ class HKSALv6 < Segment
16
+ element_group :head, type: ElementGroups::SegmentHead
17
+ element_group :account, type: ElementGroups::KTV2
18
+ element :all_accounts, default: 'N'
19
+ element :max_entries
20
+ element :attach
21
+ end
22
+
23
+ class HKSALv7 < Segment
24
+ element_group :head, type: ElementGroups::SegmentHead
25
+ element_group :account, type: ElementGroups::KTVInt
26
+ element :all_accounts, default: 'N'
27
+ element :max_entries
28
+ element :attach
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ module Hbci
2
+ module Segments
3
+ class HKSYNv3 < Segment
4
+ element_group :head, type: ElementGroups::SegmentHead
5
+ element :mode
6
+
7
+ def compile
8
+ self.mode = 0
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HKVVBv3 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element :bpd_version, default: 0
8
+ element :upd_version, default: 0
9
+ element :dialog_language, default: 0
10
+ element :product_name, default: 'FintasticHBCI'
11
+ element :product_version, default: Hbci::VERSION
12
+
13
+ def compile
14
+ self.dialog_language = 1
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HNHBKv3 < Segment
6
+ element_group :head, type: Hbci::ElementGroups::SegmentHead
7
+ element :message_size
8
+ element :hbci_version, default: 300
9
+ element :dialog_id
10
+ element :message_number
11
+ element_group :referenced_message do
12
+ element :dialog_id
13
+ element :message_number
14
+ end
15
+
16
+ def compile
17
+ self.message_size = '000000000000'
18
+ self.dialog_id = request_message.dialog ? request_message.dialog.id : 0
19
+ self.message_number = Connector.instance.message_number
20
+ end
21
+
22
+ def after_compile
23
+ self.message_size = request_message.to_s.size.to_s.rjust(12, '0')
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ class HNHBSv1 < Segment
6
+ element_group :head, type: ElementGroups::SegmentHead
7
+ element :message_number
8
+
9
+ def compile
10
+ self.message_number = Connector.instance.message_number
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hbci
4
+ module Segments
5
+ # Signature Closing Segment
6
+ #
7
+ # Counterpart of the Signature Opening (HNSHK)
8
+ class HNSHAv2 < Hbci::Segment
9
+ # Segment Head
10
+ element_group :head, type: ElementGroups::SegmentHead
11
+
12
+ # Security Reference
13
+ # MUST be the same as in signature opening (HNSHK)
14
+ element :security_reference
15
+
16
+ # Security validation result. Empty when using pin/tan.
17
+ element :security_validation_result
18
+
19
+ # User signature
20
+ element_group :signature do
21
+ element :pin
22
+ element :tan
23
+ end
24
+
25
+ def compile
26
+ self.security_reference = request_message.sec_ref
27
+ signature.pin = Connector.instance.credentials.pin
28
+ end
29
+ end
30
+ end
31
+ end