Class: NordigenOBClient

Inherits:
Object
  • Object
show all
Defined in:
lib/nordigen_ob_client.rb

Instance Method Summary collapse

Constructor Details

#initializeNordigenOBClient

Returns a new instance of NordigenOBClient.



6
7
# File 'lib/nordigen_ob_client.rb', line 6

def initialize
end

Instance Method Details

#create_requisition(redirect_url, selected_bank_id, reference) ⇒ Object

> Name: create_requisition

> Description: It creates a new requisition ID that will enable the user

to connect his bank accounts.

> Parameters: redirect_url: The URL to which the user will be redirected

after logging in to his bank environment.

selected_bank_id: The Nordigen ID of the bank the user
will be redirected.

reference: A unique user identifier that will associate
the user who will log in with the new requisition ID.

> Returns: The access token



229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/nordigen_ob_client.rb', line 229

def create_requisition redirect_url, selected_bank_id, reference
  request_body = {
                  "redirect" => redirect_url,
                  "institution_id" => selected_bank_id,
                  "user_language" => "EN",
                  "reference" => reference
  }.to_json

  response = RestClient.post(
    "https://bankaccountdata.gocardless.com/api/v2/requisitions/",
    request_body,
    headers=@request_header)
  JSON.parse(response.body)
end

#delete_requisition(requisition_id) ⇒ Object

> Name: delete_requisition

> Description: It deletes the provided requisition ID.

> Parameters: requisition_id: The requisition to delete.

> Returns: The result of the operation



256
257
258
259
260
261
262
# File 'lib/nordigen_ob_client.rb', line 256

def delete_requisition requisition_id
  response = RestClient.delete(
    "https://bankaccountdata.gocardless.com/api/v2/requisitions/#{requisition_id}/",
    headers=@request_header)
  JSON.parse(response.body)
  response
end

#get_access_token(secret_id, secret_key) ⇒ Object

> Name: get_access_token

> Description: Retrieve the access token that will be used to access all

other endpoints in Nordigen's backend.

> Parameters: secret_id: The Secret ID part of the credentials,

           provided by Nordigen.

secret_key: The Secret Key part of the credentials,
            provided by Nordigen.

> Returns: The access token



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nordigen_ob_client.rb', line 25

def get_access_token secret_id, secret_key
  access_token_params = {
    "secret_id" => secret_id,
    "secret_key" => secret_key
  }.to_json

  puts "????????????????????"
  puts access_token_params
  puts "????????????????????"

  response_json = RestClient.post("https://bankaccountdata.gocardless.com/api/v2/token/new/",
                                  access_token_params,
                                  {content_type: :json, accept: :json})
  response = JSON.parse(response_json.body)
  puts response
  @access_token = response["access"]

  @request_header = {
    content_type: :json,
    accept: :json,
    authorization: "Bearer #{@access_token}"
  }

  @access_token
end

#get_account_balances(account_id) ⇒ Object

> Name: get_account_balances

> Description: Return’s the balances for the given account. The balances

can be more than one, since accounts allow overdraft or
might have frozen limits.

> Parameters: account_id: The id of the account (IBAN)

for which the balances will be returned.

> Returns: The details available for the account. They can vary from bank

to bank. The fields we see been returned always are:
  - Balance amount
  - Currency
  - Type of balances
  - Balance date


147
148
149
150
151
152
153
# File 'lib/nordigen_ob_client.rb', line 147

def  
  response = RestClient.get(
    "https://bankaccountdata.gocardless.com/api/v2/accounts/#{account_id}/balances/",
    headers=@request_header)
  accounts = JSON.parse(response.body)
  accounts
end

#get_account_details(account_id) ⇒ Object

> Name: get_account_details

> Description: Return’s all the information available for the account.

> Parameters: account_id: The id of the account (IBAN)

for which the information will be returned.

> Returns: The details available for the account. They can vary from bank

to bank. The fields we see been returned always are:
  - IBAN
  - Currency
  - Owner Name
  - Product /  type (e.g. Savings, holding, etc.)
  - BIC
  - Usage: Private / Business


118
119
120
121
122
123
124
# File 'lib/nordigen_ob_client.rb', line 118

def  
  response = RestClient.get(
    "https://bankaccountdata.gocardless.com/api/v2/accounts/#{account_id}/details/",
    headers=@request_header)
  accounts = JSON.parse(response.body)
  accounts
end

#get_account_overview(account_id) ⇒ Object

> Name: get_account_overview

> Description: Return’s the basic information available for the account.

> Parameters: account_id: The id of the account (IBAN)

for which the information will be returned.

> Returns: A summaru available for the account. THe fields included are:

- IBAN
- Nordigen's institution ID
- Status: ready, inactive
- Owner's name


173
174
175
176
177
178
179
# File 'lib/nordigen_ob_client.rb', line 173

def  
  response = RestClient.get(
    "https://bankaccountdata.gocardless.com/api/v2/accounts/#{account_id}/",
    headers=@request_header)
  accounts = JSON.parse(response.body)
  accounts
end

#get_account_transactions(account_id) ⇒ Object

> Name: get_account_transactions

> Description: Return’s the account statement for the last 90 days.

> Parameters: account_id: The id of the account (IBAN)

for which the information will be returned.

> Returns: The list of transactions performed. THe fields included are:

- Booking date, when the transaction was logged on the .
- Reference date, when it actually occured.
- Transaction amount
- Currency
- Debitor BIC
- Creditor BIC


201
202
203
204
205
206
207
# File 'lib/nordigen_ob_client.rb', line 201

def  
  response = RestClient.get(
    "https://bankaccountdata.gocardless.com/api/v2/accounts/#{account_id}/transactions/",
    headers=@request_header)
  accounts = JSON.parse(response.body)
  accounts
end

#get_banks_by_country(country) ⇒ Object

> Name: get_banks_by_country

> Description: Returns a list of the available institutions by country,

including

> Parameters: country: The selected country, in ISO 3166 format.

Supported countries are EEA countries.

> Returns: The list of supported institutions in the selected country.



65
66
67
68
69
70
71
72
73
# File 'lib/nordigen_ob_client.rb', line 65

def get_banks_by_country country
  response = RestClient.get(
    "https://bankaccountdata.gocardless.com/api/v2/institutions/?country=#{country}",
    headers=@request_header)

  available_banks = JSON.parse(response.body,
                              :external_encoding => 'iso-8859-1')
  available_banks
end

#list_accounts(requisition_id) ⇒ Object

> Name: list_accounts

> Description: Return a list of the available accounts connected to the

given user .

> Parameters: requisition_id: The id of the requisition (bank login)

for which the parameters will be parsed.

> Returns: The list of available accounts.



90
91
92
93
94
95
96
# File 'lib/nordigen_ob_client.rb', line 90

def list_accounts requisition_id
  response = RestClient.get(
    "https://bankaccountdata.gocardless.com/api/v2/requisitions/#{requisition_id}/",
    headers=@request_header)
  accounts = JSON.parse(response.body)
  accounts
end