wire_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +35 -0
  3. data/.editorconfig +13 -0
  4. data/.gitignore +11 -0
  5. data/.ruby-version +1 -0
  6. data/.tool-versions +1 -0
  7. data/.tool-versions-e +1 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE +22 -0
  10. data/README.md +46 -0
  11. data/Rakefile +27 -0
  12. data/bin/setup +8 -0
  13. data/lib/wire_client/account/account.rb +59 -0
  14. data/lib/wire_client/account/creditor_account.rb +7 -0
  15. data/lib/wire_client/account/debitor_account.rb +7 -0
  16. data/lib/wire_client/base/constants.rb +61 -0
  17. data/lib/wire_client/base/converters.rb +46 -0
  18. data/lib/wire_client/base/invalid_wire_transaction_error.rb +4 -0
  19. data/lib/wire_client/base/invalid_wire_transaction_type_error.rb +3 -0
  20. data/lib/wire_client/base/validators.rb +95 -0
  21. data/lib/wire_client/messages/credit_transfer.rb +112 -0
  22. data/lib/wire_client/messages/direct_debit.rb +148 -0
  23. data/lib/wire_client/messages/message.rb +215 -0
  24. data/lib/wire_client/providers/base/wire_batch.rb +120 -0
  25. data/lib/wire_client/providers/sftp/sftp_provider.rb +39 -0
  26. data/lib/wire_client/providers/sftp/wire_batch.rb +39 -0
  27. data/lib/wire_client/transaction/credit_transfer_transaction.rb +20 -0
  28. data/lib/wire_client/transaction/direct_debit_transaction.rb +49 -0
  29. data/lib/wire_client/transaction/transaction.rb +87 -0
  30. data/lib/wire_client/version.rb +4 -0
  31. data/lib/wire_client.rb +36 -0
  32. data/schemas/.gitattributes +1 -0
  33. data/schemas/pain.001.001.03.xsd +921 -0
  34. data/schemas/pain.008.001.02.xsd +879 -0
  35. data/wire_client.gemspec +66 -0
  36. metadata +375 -0
@@ -0,0 +1,87 @@
1
+ module WireClient
2
+ class Transaction
3
+ include ActiveModel::Validations
4
+ extend Converter
5
+
6
+ DEFAULT_REQUESTED_DATE = Time.zone.now.to_date.freeze
7
+
8
+ attr_accessor :name,
9
+ :iban,
10
+ :bic,
11
+ :account_number,
12
+ :wire_routing_number,
13
+ :clear_system_code,
14
+ :agent_name,
15
+ :country,
16
+ :amount,
17
+ :instruction,
18
+ :reference,
19
+ :remittance_information,
20
+ :requested_date,
21
+ :batch_booking,
22
+ :currency,
23
+ :service_priority,
24
+ :service_level
25
+ convert :name,
26
+ :instruction,
27
+ :reference,
28
+ :remittance_information, to: :text
29
+ convert :amount, to: :decimal
30
+
31
+ validates_length_of :name, within: 1..70
32
+ validates_length_of :currency, is: 3
33
+ validates_length_of :instruction, within: 1..35, allow_nil: true
34
+ validates_length_of :reference, within: 1..35, allow_nil: true
35
+ validates_length_of :remittance_information,
36
+ within: 1..140,
37
+ allow_nil: true
38
+ validates_numericality_of :amount, greater_than: 0
39
+ validates_presence_of :requested_date
40
+ validates_inclusion_of :batch_booking, :in => [true, false]
41
+ validates_with CurrencyValidator,
42
+ CountryValidator,
43
+ BICValidator,
44
+ IBANValidator,
45
+ message: "%{value} is invalid"
46
+
47
+ def initialize(attributes = {})
48
+ attributes.each do |name, value|
49
+ send("#{name}=", value)
50
+ end
51
+
52
+ @currency ||= 'USD'
53
+ @country ||= 'US'
54
+ @clear_system_code ||= 'USABA'
55
+ @agent_name ||= 'NOTPROVIDED'
56
+ @requested_date ||= DEFAULT_REQUESTED_DATE
57
+ @reference ||= 'NOTPROVIDED'
58
+ @batch_booking = true if @batch_booking.nil?
59
+ @service_priority ||= 'NORM'
60
+ @service_level ||= 'URGP'
61
+ end
62
+
63
+ def error_messages
64
+ errors.full_messages.join("\n")
65
+ end
66
+
67
+ def schema_compatible?(_schema_name)
68
+ # By default, transactions are compatible with any `schema_name`.
69
+ # Could be used to implement schema compatibility check.
70
+ true
71
+ end
72
+
73
+ protected
74
+
75
+ def validate_requested_date_after(min_requested_date)
76
+ return unless requested_date.is_a?(Date)
77
+
78
+ if requested_date != DEFAULT_REQUESTED_DATE &&
79
+ requested_date < min_requested_date
80
+ errors.add(
81
+ :requested_date,
82
+ "must be greater or equal to #{min_requested_date}, or nil"
83
+ )
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,4 @@
1
+ module WireClient
2
+ # Increment this when changes are published
3
+ VERSION = '0.1.0'
4
+ end
@@ -0,0 +1,36 @@
1
+ require 'ach_client'
2
+ require 'active_support/all'
3
+ require 'active_model'
4
+ require 'savon'
5
+ require 'sucker_punch'
6
+ require 'bigdecimal'
7
+ require 'builder'
8
+ require 'iban-tools'
9
+
10
+ # Require all of the files in lib
11
+ Dir[File.expand_path('..', __FILE__) + '/**/*.rb'].sort.each do |f|
12
+ require(f.split('/lib/').last.split('.rb').first)
13
+ end
14
+
15
+ # Adapter for interacting with Wire transfer service providers
16
+ module WireClient
17
+ include AchClient
18
+
19
+ # Enables consumer to interact with new SFTP providers without adding them
20
+ # to the codebase. Let's say the consumer wants to integrate with Citibank.
21
+ # They would invoke WireClient::Citibank, which would be undefined. This
22
+ # const_missing would be called, and the Citibank module would be dynamically
23
+ # defined, with all the necessary SFTP concerns included and ready for use.
24
+ def self.const_missing(name)
25
+ const_set(
26
+ name,
27
+ Class.new do
28
+ include WireClient::SftpProvider
29
+
30
+ # Defines the classes within the provider namespace to use for
31
+ # sending transactions
32
+ const_set(:WireBatch, Class.new(WireClient::Sftp::WireBatch))
33
+ end
34
+ )
35
+ end
36
+ end
@@ -0,0 +1 @@
1
+ *.xsd binary