fidor_api 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +5 -3
  5. data/CHANGELOG.md +114 -0
  6. data/Gemfile +3 -2
  7. data/README.md +12 -10
  8. data/lib/fidor_api/account.rb +7 -10
  9. data/lib/fidor_api/amount_attributes.rb +23 -20
  10. data/lib/fidor_api/approval_required.rb +9 -0
  11. data/lib/fidor_api/auth.rb +1 -1
  12. data/lib/fidor_api/beneficiary/ach.rb +39 -0
  13. data/lib/fidor_api/beneficiary/base.rb +118 -0
  14. data/lib/fidor_api/beneficiary/generic.rb +24 -0
  15. data/lib/fidor_api/beneficiary/p2p_account_number.rb +14 -0
  16. data/lib/fidor_api/beneficiary/p2p_phone.rb +14 -0
  17. data/lib/fidor_api/beneficiary/p2p_username.rb +14 -0
  18. data/lib/fidor_api/beneficiary/swift.rb +35 -0
  19. data/lib/fidor_api/beneficiary/unknown.rb +16 -0
  20. data/lib/fidor_api/beneficiary/utility.rb +35 -0
  21. data/lib/fidor_api/beneficiary.rb +27 -0
  22. data/lib/fidor_api/card.rb +31 -48
  23. data/lib/fidor_api/card_limit_attribute.rb +52 -0
  24. data/lib/fidor_api/card_limits.rb +6 -34
  25. data/lib/fidor_api/client.rb +8 -2
  26. data/lib/fidor_api/collection.rb +15 -6
  27. data/lib/fidor_api/confirmable_action.rb +45 -0
  28. data/lib/fidor_api/connectivity/connection.rb +113 -0
  29. data/lib/fidor_api/connectivity/endpoint.rb +82 -0
  30. data/lib/fidor_api/connectivity/resource.rb +76 -0
  31. data/lib/fidor_api/connectivity.rb +17 -0
  32. data/lib/fidor_api/constants.rb +3 -0
  33. data/lib/fidor_api/customer.rb +41 -23
  34. data/lib/fidor_api/customers/confirmations.rb +19 -0
  35. data/lib/fidor_api/errors.rb +14 -3
  36. data/lib/fidor_api/message.rb +17 -18
  37. data/lib/fidor_api/msisdn.rb +1 -1
  38. data/lib/fidor_api/password.rb +30 -0
  39. data/lib/fidor_api/preauth.rb +5 -12
  40. data/lib/fidor_api/session_token.rb +20 -0
  41. data/lib/fidor_api/transaction.rb +5 -12
  42. data/lib/fidor_api/transfer/ach.rb +46 -0
  43. data/lib/fidor_api/transfer/bank_internal.rb +37 -0
  44. data/lib/fidor_api/transfer/base.rb +36 -0
  45. data/lib/fidor_api/transfer/fps.rb +56 -0
  46. data/lib/fidor_api/transfer/generic.rb +134 -0
  47. data/lib/fidor_api/transfer/internal.rb +53 -0
  48. data/lib/fidor_api/transfer/p2p_account_number.rb +45 -0
  49. data/lib/fidor_api/transfer/p2p_phone.rb +45 -0
  50. data/lib/fidor_api/transfer/p2p_username.rb +45 -0
  51. data/lib/fidor_api/transfer/sepa.rb +56 -0
  52. data/lib/fidor_api/transfer/swift.rb +49 -0
  53. data/lib/fidor_api/transfer/utility.rb +50 -0
  54. data/lib/fidor_api/transfer.rb +13 -186
  55. data/lib/fidor_api/user.rb +12 -11
  56. data/lib/fidor_api/version.rb +1 -1
  57. data/lib/fidor_api.rb +39 -22
  58. metadata +37 -4
  59. data/lib/fidor_api/resource.rb +0 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b18d0f77a280f02bee3ddf6b2bce5a3c4d598644
4
- data.tar.gz: 820e2789982d1376be43f2b95be4c4e448c25902
3
+ metadata.gz: e901a140ae4373b030fc1acd73b528139ef6661f
4
+ data.tar.gz: a0cc6f973f426c1c28da0d44c2b845f79a33cf05
5
5
  SHA512:
6
- metadata.gz: a69f553f0953fb1967527fb58e50db7d4903fc39087ddfbc89d8d2f7cb3e0c8e50546b9a7c87f3d6b7f9da05b4ef5e1b4f7ec03cae0a68c69078570089224c39
7
- data.tar.gz: 06e0802e771bcf251e7d8ef8e0f7f5e9be435740702c5fc7f74a5e1eae30ef584529a368cbac37d481e34872b744ba517ef90cec6dd4bc713846801314001688
6
+ metadata.gz: a303081e9be0a99ba14e063609a3047ca4dd2db7e9765bc8aeea4cbf4142d9dd2d5f71d5d3b8527131ece88c268105c510d46af0689144d5e5d436268cf7d869
7
+ data.tar.gz: 5ef3b95906b997d771ac9e44687ce3a3d5101585d33f90b2d5282226da026b47c2cbf7c3611a5ce7d47ad4dbd11a79cbfe18a9069fa740690bd0030c17e24287
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .byebug_history
11
+ vcr.log
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.4.0
data/.travis.yml CHANGED
@@ -1,8 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.1.10"
4
- - "2.2.5"
5
- - "2.3.1"
3
+ - "2.2.6"
4
+ - "2.3.3"
5
+ - "2.4.0"
6
6
  addons:
7
7
  code_climate:
8
8
  repo_token: 2ffd456a223e8c95dbd79a25a5ea3dca9899ece93fce3cfdfae3723a76f0028e
9
+ before_install:
10
+ - gem install bundler
data/CHANGELOG.md ADDED
@@ -0,0 +1,114 @@
1
+ # Changelog
2
+
3
+ ## v0.1.0
4
+
5
+ With this release this gem will start following the semantic versioning approach.
6
+
7
+ **Note**: This version contains two major changes which will break existing applications:
8
+
9
+ ### How to initiate the client:
10
+
11
+ Before:
12
+
13
+ ```ruby
14
+ client = FidorApi::Client.new(token: FidorApi::Token.new(access_token: "f859032a6ca0a4abb2be0583b8347937"))
15
+ ```
16
+
17
+ After:
18
+
19
+ ```
20
+ FidorApi::Connectivity.access_token = "f859032a6ca0a4abb2be0583b8347937"
21
+ ```
22
+
23
+ ### How to create resources:
24
+
25
+ Before:
26
+
27
+ ```ruby
28
+ transfer = client.build_internal_transfer(
29
+ account_id: 875,
30
+ receiver: "kycfull@fidor.de",
31
+ external_uid: "4279762F5",
32
+ subject: "Money for you",
33
+ amount: 1000
34
+ )
35
+ transfer.save
36
+ ```
37
+
38
+ After:
39
+
40
+ ```ruby
41
+ transfer = FidorApi::Transfer::Internal.new(
42
+ account_id: 875,
43
+ receiver: "kycfull@fidor.de",
44
+ external_uid: "4279762F5",
45
+ subject: "Money for you",
46
+ amount: 1000
47
+ )
48
+ transfer.save
49
+ ```
50
+
51
+ * Also map errors returned on the `:base` field
52
+ * Support for `/transfers` and `/beneficiaries` endpoints` with routing types: (*Note*: Not supported in fidor.de & fidorbank.uk APIs)
53
+ * `ACH`
54
+ * `BANK_INTERNAL`
55
+ * `FOS_P2P_ACCOUNT_NUMBER`
56
+ * `FOS_P2P_PHONE`
57
+ * `FOS_P2P_USERNAME`
58
+ * `SWIFT`
59
+ * `UTILITY`
60
+ * Improve logger setup
61
+ * Add new `logger` config option to pass existing logger
62
+ * Add support for `faraday-detailed_logger` gem without adding additional dependency
63
+ * Support for `/confirmable/actions` endpoint
64
+ * New option `verify_ssl` (needed when testing against e.g. mock-services or fidor-internal test installations)
65
+ * Logging for `FidorApi::ClientError` cases
66
+ * New fields for contact- & bank-details in `/transfers` endpoint
67
+ * Support for `/session_tokens` endpoint
68
+ * Support for `/beneficiaries` endpoint
69
+ * Provide `total_entries` attribute in collections
70
+ * Support for `/messages/:id/content` endpoint
71
+ * Support for updating customer records
72
+ * New fields for customer endpoint
73
+ * Support Address attribute in cards endpoint
74
+ * Handle HTTP 303 with exception indicating the need to use confirmable-action
75
+ * Add unique_name attribute to beneficiaries
76
+ * Add support to activate and cancel cards
77
+ * Better mapping of error keys to support usage of i18n
78
+ * Suport for endpoints to reset & change password
79
+ * New way to build ressources (using `FidorApi::Transfers::ACH.new` instead of `client.build_ach_transfer`)
80
+ * Allow to update customers
81
+ * Improved Ruby 2.4 compatibility
82
+
83
+ ## v0.0.2
84
+
85
+ All commits: https://github.com/klausmeyer/fidor_api/compare/v0.0.1...v0.0.2
86
+
87
+ * Gem can now be used in rails 5 projects
88
+ * `FidorApi::Client` added to improve token-management
89
+ * `remote_bic` field optional in `Transfer::SEPA`
90
+ * Amounts are now `BigDecimal` type
91
+ * `Resource#model_name` returns `Resource` instead of `FidorApi::Resource` now
92
+ * Collection implements `Enumerable`
93
+ * `Resource#persisted?` added to improve `ActiveRecord` style behaviour
94
+ * `Customer#gender` now returns `FidorApi::Customer::Gender`
95
+ * Basic support for signup (`Msisdn`, `Customer#save`)
96
+ * Support new endpoints
97
+ * `/cards`
98
+ * `/card_limits`
99
+ * `/messages`
100
+ * `/fps_payments` (:gb: specific)
101
+ * Provide validation errors returned in API in `Resource#errors`
102
+
103
+ ## v0.0.1
104
+
105
+ * First release on rubygems.org
106
+ * oAuth support
107
+ * Basic support for the following endpoints:
108
+ * `/accounts`
109
+ * `/customers`
110
+ * `/preauths`
111
+ * `/transactions`
112
+ * `/internal_transfers`
113
+ * `/sepa_credit_transfers`
114
+ * `/users/current`
data/Gemfile CHANGED
@@ -8,7 +8,8 @@ group :development, :test do
8
8
  gem "rake", "~> 10.0"
9
9
  gem "rspec", "~> 3.3"
10
10
  gem "shoulda-matchers", "~> 2.8"
11
- gem "vcr", "~> 2.9"
12
- gem "simplecov", "~> 0.10"
11
+ gem "vcr", "~> 3.0"
12
+ gem "webmock"
13
+ gem "simplecov", github: "colszowka/simplecov"
13
14
  gem "codeclimate-test-reporter", group: :test, require: nil
14
15
  end
data/README.md CHANGED
@@ -69,13 +69,12 @@ end
69
69
  ### 2. Fetching data
70
70
 
71
71
  ```ruby
72
- token = FidorApi::Token.new(access_token: "f859032a6ca0a4abb2be0583b8347937")
72
+ FidorApi::Connectivity.access_token = "f859032a6ca0a4abb2be0583b8347937"
73
73
 
74
- client = FidorApi::Client.new(token: token)
75
- user = client.current_user
74
+ user = FidorApi::User.current
76
75
  # => FidorApi::User
77
76
 
78
- transactions = client.transactions
77
+ transactions = FidorApi::Transaction.all
79
78
  # => FidorApi::Collection
80
79
 
81
80
  transaction = transactions.first
@@ -85,11 +84,9 @@ transaction = transactions.first
85
84
  ### 3. Creating transfers
86
85
 
87
86
  ```ruby
88
- token = FidorApi::Token.new(access_token: "f859032a6ca0a4abb2be0583b8347937")
87
+ FidorApi::Connectivity.access_token = "f859032a6ca0a4abb2be0583b8347937"
89
88
 
90
- client = FidorApi::Client.new(token: token)
91
-
92
- transfer = client.build_internal_transfer(
89
+ transfer = FidorApi::Transfer::Internal.new(
93
90
  account_id: 875,
94
91
  receiver: "kycfull@fidor.de",
95
92
  external_uid: "4279762F5",
@@ -99,7 +96,9 @@ transfer = client.build_internal_transfer(
99
96
  # => FidorApi::Transfer::Internal
100
97
 
101
98
  transfer.save
102
- # => true / or raise error
99
+ # => true
100
+ # or
101
+ # => false and `transfer.errors` containing details
103
102
  ```
104
103
 
105
104
  ## Development
@@ -112,7 +111,10 @@ To install this gem onto your local machine, run `bundle exec rake install`.
112
111
 
113
112
  Bug reports and pull requests are welcome on GitHub at https://github.com/klausmeyer/fidor_api.
114
113
 
114
+ ## Changelog
115
+
116
+ Have a look at the [CHANGELOG](CHANGELOG.md) for details.
117
+
115
118
  ## License
116
119
 
117
120
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
118
-
@@ -1,9 +1,10 @@
1
1
  module FidorApi
2
-
3
- class Account < Resource
2
+ class Account < Connectivity::Resource
4
3
  extend ModelAttribute
5
4
  extend AmountAttributes
6
5
 
6
+ self.endpoint = Connectivity::Endpoint.new('/accounts', :collection)
7
+
7
8
  attribute :id, :integer
8
9
  attribute :account_number, :string
9
10
  attribute :iban, :string
@@ -22,12 +23,8 @@ module FidorApi
22
23
  amount_attribute :cash_flow_per_year
23
24
  amount_attribute :overdraft
24
25
 
25
- def self.all(access_token, options = {})
26
- Collection.build(self, request(access_token: access_token, endpoint: "/accounts", query_params: options).body)
27
- end
28
-
29
- def self.first(access_token)
30
- all(access_token, page: 1, per_page: 1).first
26
+ def self.first
27
+ all(page: 1, per_page: 1).first
31
28
  end
32
29
 
33
30
  def customers=(array)
@@ -36,11 +33,11 @@ module FidorApi
36
33
 
37
34
  module ClientSupport
38
35
  def accounts(options = {})
39
- Account.all(token.access_token, options)
36
+ Account.all(options)
40
37
  end
41
38
 
42
39
  def first_account
43
- Account.first(token.access_token)
40
+ Account.first
44
41
  end
45
42
  end
46
43
  end
@@ -1,27 +1,30 @@
1
- module AmountAttributes
2
- def self.extended(base)
3
- base.instance_variable_set('@amount_attributes', [])
4
- end
5
-
6
- def amount_attribute(name)
7
- @amount_attributes << name
1
+ module FidorApi
2
+ module AmountAttributes
8
3
 
9
- define_method name do
10
- BigDecimal.new((instance_variable_get("@#{name}") / 100.00).to_s) if instance_variable_get("@#{name}").present?
4
+ def self.extended(base)
5
+ base.instance_variable_set('@amount_attributes', [])
11
6
  end
12
7
 
13
- define_method "#{name}=" do |value|
14
- if value.instance_of?(BigDecimal)
15
- instance_variable_set("@#{name}", (value * 100.00).to_i)
16
- elsif value.instance_of?(Fixnum) || value.instance_of?(NilClass)
17
- instance_variable_set("@#{name}", value)
18
- else
19
- raise ArgumentError, "Must be either Fixnum (1234) or BigDecimal (12.34)."
8
+ def amount_attribute(name)
9
+ @amount_attributes << name
10
+
11
+ define_method name do
12
+ BigDecimal.new((instance_variable_get("@#{name}") / 100.00).to_s) if instance_variable_get("@#{name}").present?
13
+ end
14
+
15
+ define_method "#{name}=" do |value|
16
+ if value.instance_of?(BigDecimal)
17
+ instance_variable_set("@#{name}", (value * 100.00).to_i)
18
+ elsif value.class.name.in?(INTEGER_CLASSES) || value.instance_of?(NilClass)
19
+ instance_variable_set("@#{name}", value)
20
+ else
21
+ raise ArgumentError, "Must be either Fixnum (1234) or BigDecimal (12.34)."
22
+ end
20
23
  end
21
24
  end
22
- end
23
25
 
24
- def attributes
25
- super + @amount_attributes
26
+ def attributes
27
+ super + @amount_attributes
28
+ end
26
29
  end
27
- end
30
+ end
@@ -0,0 +1,9 @@
1
+ module FidorApi
2
+ class ApprovalRequired < RuntimeError
3
+ attr_reader :confirmable_action
4
+
5
+ def initialize(confirmable_action)
6
+ @confirmable_action = confirmable_action
7
+ end
8
+ end
9
+ end
@@ -28,7 +28,7 @@ module FidorApi
28
28
  private
29
29
 
30
30
  def connection
31
- Faraday.new(url: FidorApi.configuration.oauth_url) do |config|
31
+ Faraday.new(url: FidorApi.configuration.oauth_url, ssl: { verify: FidorApi.configuration.verify_ssl }) do |config|
32
32
  config.use Faraday::Request::BasicAuthentication, FidorApi.configuration.client_id, FidorApi.configuration.client_secret
33
33
  config.request :url_encoded
34
34
  config.response :logger if FidorApi.configuration.logging
@@ -0,0 +1,39 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ class ACH < Base
4
+ include Generic
5
+
6
+ attribute :account_number, :string
7
+ attribute :routing_code, :string
8
+
9
+ validates :contact_name, presence: true
10
+ validates :account_number, presence: true
11
+ validates :routing_code, presence: true
12
+
13
+ def set_attributes(attrs = {})
14
+ self.account_number = attrs.fetch("routing_info", {})["account_number"]
15
+ self.routing_code = attrs.fetch("routing_info", {})["routing_code"]
16
+ super(attrs.except("routing_type", "routing_info"))
17
+ end
18
+
19
+ def as_json_routing_type
20
+ "ACH"
21
+ end
22
+
23
+ def as_json_routing_info
24
+ {
25
+ account_number: account_number,
26
+ routing_code: routing_code
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ module ClientSupport
33
+ def build_ach_beneficiary(attributes = {})
34
+ Beneficiary::ACH.new(attributes)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,118 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ class Base < Connectivity::Resource
4
+ ROUTING_INFO_ERROR_PREFIX = "routing_info.".freeze
5
+
6
+ self.endpoint = Connectivity::Endpoint.new('/beneficiaries', :collection)
7
+
8
+ attr_accessor :confirmable_action
9
+
10
+ class << self
11
+ def new(hash={})
12
+ if self == Base
13
+ class_for_response_hash(hash).new hash
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def delete(id)
20
+ endpoint.for(new(id: id)).delete
21
+ true
22
+ end
23
+
24
+ private
25
+
26
+ def class_for_response_hash(hash)
27
+ {
28
+ "FOS_P2P_ACCOUNT_NUMBER" => FidorApi::Beneficiary::P2pAccountNumber,
29
+ "FOS_P2P_PHONE" => FidorApi::Beneficiary::P2pPhone,
30
+ "FOS_P2P_USERNAME" => FidorApi::Beneficiary::P2pUsername,
31
+ "SWIFT" => FidorApi::Beneficiary::Swift,
32
+ "UTILITY" => FidorApi::Beneficiary::Utility
33
+ }.fetch(hash["routing_type"], FidorApi::Beneficiary::Unknown)
34
+ end
35
+ end
36
+
37
+ def set_attributes(attrs = {})
38
+ self.contact_name = attrs.fetch("contact", {})["name"]
39
+ self.contact_address_line_1 = attrs.fetch("contact", {})["address_line_1"]
40
+ self.contact_address_line_2 = attrs.fetch("contact", {})["address_line_2"]
41
+ self.contact_city = attrs.fetch("contact", {})["city"]
42
+ self.contact_country = attrs.fetch("contact", {})["country"]
43
+
44
+ self.bank_name = attrs.fetch("bank", {})["name"]
45
+ self.bank_address_line_1 = attrs.fetch("bank", {})["address_line_1"]
46
+ self.bank_address_line_2 = attrs.fetch("bank", {})["address_line_2"]
47
+ self.bank_city = attrs.fetch("bank", {})["city"]
48
+ self.bank_country = attrs.fetch("bank", {})["country"]
49
+
50
+ super(attrs.except("contact", "bank", "routing_type", "routing_info"))
51
+ end
52
+
53
+ def save
54
+ fail InvalidRecordError unless valid?
55
+ super
56
+ end
57
+
58
+ def as_json
59
+ {
60
+ account_id: account_id,
61
+ unique_name: unique_name,
62
+ contact: {
63
+ name: contact_name,
64
+ address_line_1: contact_address_line_1,
65
+ address_line_2: contact_address_line_2,
66
+ city: contact_city,
67
+ country: contact_country
68
+ }.compact,
69
+ bank: {
70
+ name: bank_name,
71
+ address_line_1: bank_address_line_1,
72
+ address_line_2: bank_address_line_2,
73
+ city: bank_city,
74
+ country: bank_country
75
+ }.compact,
76
+ routing_type: as_json_routing_type,
77
+ routing_info: as_json_routing_info
78
+ }.compact
79
+ end
80
+
81
+ private
82
+
83
+ def remote_create
84
+ response = super
85
+ if path = response.headers["X-Fidor-Confirmation-Path"]
86
+ self.confirmable_action = ConfirmableAction.new(id: path.split("/").last)
87
+ end
88
+ response
89
+ end
90
+
91
+ def remote_update(*attributes)
92
+ response = super
93
+ if path = response.headers["X-Fidor-Confirmation-Path"]
94
+ self.confirmable_action = ConfirmableAction.new(id: path.split("/").last)
95
+ end
96
+ response
97
+ end
98
+
99
+ def map_errors(fields)
100
+ fields.each do |hash|
101
+ field = hash["field"].to_sym
102
+ key = hash["key"].try :to_sym
103
+
104
+ if field == :base || respond_to?(field)
105
+ if key
106
+ errors.add(field, key, message: hash["message"])
107
+ else
108
+ errors.add(field, hash["message"])
109
+ end
110
+ elsif hash["field"].start_with?(ROUTING_INFO_ERROR_PREFIX)
111
+ invalid_field = hash["field"][ROUTING_INFO_ERROR_PREFIX.size..-1]
112
+ errors.add(invalid_field, hash["key"].to_sym, message: hash["message"])
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,24 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ module Generic
4
+ def self.included(base)
5
+ base.extend ModelAttribute
6
+
7
+ base.attribute :id, :string
8
+ base.attribute :account_id, :string
9
+ base.attribute :unique_name, :string
10
+ base.attribute :contact_name, :string
11
+ base.attribute :contact_address_line_1, :string
12
+ base.attribute :contact_address_line_2, :string
13
+ base.attribute :contact_city, :string
14
+ base.attribute :contact_country, :string
15
+ base.attribute :bank_name, :string
16
+ base.attribute :bank_address_line_1, :string
17
+ base.attribute :bank_address_line_2, :string
18
+ base.attribute :bank_city, :string
19
+ base.attribute :bank_country, :string
20
+ base.attribute :verified, :boolean
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ class P2pAccountNumber < Base
4
+ include Generic
5
+
6
+ attribute :account_number, :string
7
+
8
+ def set_attributes(attrs = {})
9
+ self.account_number = attrs.fetch("routing_info", {})["account_number"]
10
+ super(attrs.except("routing_type", "routing_info"))
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ class P2pPhone < Base
4
+ include Generic
5
+
6
+ attribute :mobile_phone_number, :string
7
+
8
+ def set_attributes(attrs = {})
9
+ self.mobile_phone_number = attrs.fetch("routing_info", {})["mobile_phone_number"]
10
+ super(attrs.except("routing_type", "routing_info"))
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ class P2pUsername < Base
4
+ include Generic
5
+
6
+ attribute :username, :string
7
+
8
+ def set_attributes(attrs = {})
9
+ self.username = attrs.fetch("routing_info", {})["username"]
10
+ super(attrs.except("routing_type", "routing_info"))
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ class Swift < Base
4
+ include Generic
5
+
6
+ attribute :account_number, :string
7
+ attribute :swift_code, :string
8
+ attribute :account_currency, :string
9
+
10
+ validates :account_number, presence: true
11
+ validates :swift_code, presence: true
12
+ validates :contact_name, presence: true
13
+ validates :account_currency, presence: true
14
+
15
+ def set_attributes(attrs = {})
16
+ self.account_number = attrs.fetch("routing_info", {})["account_number"]
17
+ self.swift_code = attrs.fetch("routing_info", {})["swift_code"]
18
+ self.account_currency = attrs.fetch("routing_info", {})["account_currency"]
19
+ super(attrs.except("routing_type", "routing_info"))
20
+ end
21
+
22
+ def as_json_routing_type
23
+ "SWIFT"
24
+ end
25
+
26
+ def as_json_routing_info
27
+ {
28
+ account_number: account_number,
29
+ swift_code: swift_code,
30
+ account_currency: account_currency
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ class Unknown < Base
4
+ include Generic
5
+
6
+ attribute :routing_type, :string
7
+ attribute :routing_info, :json
8
+
9
+ def set_attributes(attrs = {})
10
+ self.routing_type = attrs["routing_type"]
11
+ self.routing_info = attrs["routing_info"]
12
+ super(attrs.except("routing_type", "routing_info"))
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ class Utility < Base
4
+ include Generic
5
+
6
+ attribute :utility_provider, :string
7
+ attribute :utility_service, :string
8
+ attribute :utility_service_number, :string
9
+
10
+ validates :utility_provider, presence: true
11
+ validates :utility_service, presence: true
12
+ validates :utility_service_number, presence: true
13
+ validates :unique_name, presence: true
14
+
15
+ def set_attributes(attrs = {})
16
+ self.utility_provider = attrs.fetch("routing_info", {})["utility_provider"]
17
+ self.utility_service = attrs.fetch("routing_info", {})["utility_service"]
18
+ self.utility_service_number = attrs.fetch("routing_info", {})["utility_service_number"]
19
+ super(attrs.except("routing_type", "routing_info"))
20
+ end
21
+
22
+ def as_json_routing_type
23
+ "UTILITY"
24
+ end
25
+
26
+ def as_json_routing_info
27
+ {
28
+ utility_provider: utility_provider,
29
+ utility_service: utility_service,
30
+ utility_service_number: utility_service_number
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ module FidorApi
2
+ module Beneficiary
3
+ autoload :Base, 'fidor_api/beneficiary/base'
4
+ autoload :Generic, 'fidor_api/beneficiary/generic'
5
+ autoload :ACH, 'fidor_api/beneficiary/ach'
6
+ autoload :P2pAccountNumber, 'fidor_api/beneficiary/p2p_account_number'
7
+ autoload :P2pPhone, 'fidor_api/beneficiary/p2p_phone'
8
+ autoload :P2pUsername, 'fidor_api/beneficiary/p2p_username'
9
+ autoload :Swift, 'fidor_api/beneficiary/swift'
10
+ autoload :Unknown, 'fidor_api/beneficiary/unknown'
11
+ autoload :Utility, 'fidor_api/beneficiary/utility'
12
+
13
+ module ClientSupport
14
+ def beneficiaries(options = {})
15
+ Beneficiary::Base.all(options)
16
+ end
17
+
18
+ def beneficiary(id)
19
+ Beneficiary::Base.find(id)
20
+ end
21
+
22
+ def delete_beneficiary(id)
23
+ Beneficiary::Base.delete(id)
24
+ end
25
+ end
26
+ end
27
+ end