bank_api 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cee9e57c567fd883f0dd381ac9dcd9c9799b444
4
- data.tar.gz: e420ad79895f4a9c3cb8c44a5ec381aee0cc30bf
3
+ metadata.gz: 78c1fa23cbaa3821ad25cb93a3445d2d9b69a6ff
4
+ data.tar.gz: 54e5a83c97de439674cd4a377af8c8674744faa6
5
5
  SHA512:
6
- metadata.gz: d15d43f09094eca46d701f8edefc481664ca48854c6fb40fac112c6fbc5ecc7c2348cc0fa7044e800f2ee653d8ef6e22a356bd44199601b0fd191b4f5b5d169c
7
- data.tar.gz: '009e75302dae2e829745844e7adba6d88f5a85cce5e93f44f6a7a5f91b27c0bbe06d31db9a62a066a6cad8abb630e25d976a463bae2055bb4725dd1c1f5d3e30'
6
+ metadata.gz: 4ecac1f35b3c585fba52ef6477f1f975ff363a41fc2e53764a30d728f2d6bde235c4351f8f58c56b7c526c98afd330c2cb103e43969da485b07898757b6c0bfa
7
+ data.tar.gz: 5e83f38a6882c06c4c0ac1dec33f7bbc799da44e417ed2bbb86bafb31ab8cc2441877bddfbf0c4c74e96ed721c303210b982b4ac6192aa157ea8b2b3e1e75d04
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bank_api (0.2.1)
4
+ bank_api (0.2.2)
5
5
  pincers
6
6
  timezone (~> 1.0)
7
7
 
data/README.md CHANGED
@@ -20,25 +20,78 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- For now, the gem can only get recent deposits of Banco de Chile accounts (only Enterprise accounts have been tested). To add your credentials so the client can login, create the following initializer:
23
+ For now, the gem can get recent deposits of Banco de Chile accounts (only Enterprise accounts have been tested) and BancoSecurity's accounts. To add your credentials so the client can login, create the following initializer:
24
24
 
25
25
  ```
26
26
  # config/initializers/bank_api.rb
27
27
 
28
28
  BankApi.configure do |config|
29
- # Add the rut linked to the account
29
+ # Banco de Chile config
30
30
  config.bdc_user_rut = '12345678-9'
31
31
  # Add the account's password
32
32
  config.bdc_password = 'secretpassword'
33
- # Add the account's enterprise rut
34
33
  config.bdc_company_rut = '98765432-1'
34
+
35
+ # Deposits config
35
36
  config.days_to_check = 3
37
+
38
+ # BancoSecurity config
39
+ config.banco_security.user_rut = '12345678-9'
40
+ config.banco_security.password = 'secretpassword'
41
+ config.banco_security.company_rut = '98765432-1'
42
+ config.banco_security.dynamic_card_entries = "[['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10'], ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10'], ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10'], ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10'], ['E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'E10']]"
36
43
  end
37
44
 
38
45
  ```
39
46
 
40
47
  The days to check is set by default to 6, and can be configured as seen in the initializer.
41
48
 
49
+ For BancoSecurity's account there's also de posibility to make transfers to third party's accounts using the dynamic card. To use this feature, you must specify the `dynamic_card_entries` variable in the config, then call:
50
+
51
+ ```
52
+ BankApi.company_transfer({
53
+ amount: 1000,
54
+ name: "John Doe",
55
+ rut: "12.345.678-9",
56
+ account_number: "11111111",
57
+ bank: :banco_estado,
58
+ account_type: :cuenta_corriente,
59
+ email: "doe@platan.us",
60
+ comment: "This is a comment",
61
+ origin: "9.876.543-2"
62
+ })
63
+ ```
64
+
65
+ If you don't setup the origin on the transfer's data, the default'll be `config.banco_security.company_rut`. You can also make transfers on batches:
66
+
67
+ ```
68
+ BankApi.company_batch_transfers([
69
+ {
70
+ amount: 1000,
71
+ name: "John Doe",
72
+ rut: "12.345.678-9",
73
+ account_number: "11111111",
74
+ bank: :banco_estado,
75
+ account_type: :cuenta_corriente,
76
+ email: "doe@platan.us",
77
+ comment: "This is a comment",
78
+ origin: "9.876.543-2"
79
+ }, {
80
+ amount: 2000,
81
+ name: "John Does",
82
+ rut: "12.345.678-9",
83
+ account_number: "11111111",
84
+ bank: :banco_estado,
85
+ account_type: :cuenta_corriente,
86
+ email: "does@platan.us",
87
+ comment: "This is a comment",
88
+ origin: "9.876.543-2"
89
+ }
90
+ ])
91
+ ```
92
+
93
+ Checkout the available banks and account types in [this file](./lib/bank_api/utils/banco_security.rb).
94
+
42
95
  ## Development
43
96
 
44
97
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/bank_api.rb CHANGED
@@ -29,5 +29,14 @@ module BankApi
29
29
  def self.get_recent_company_deposits
30
30
  Clients::BancoSecurity::CompanyClient.new(BankApi.configuration).get_recent_deposits
31
31
  end
32
+
33
+ def self.company_transfer(transfer_data)
34
+ Clients::BancoSecurity::CompanyClient.new(BankApi.configuration).transfer(transfer_data)
35
+ end
36
+
37
+ def self.company_batch_transfers(transfers_data)
38
+ Clients::BancoSecurity::CompanyClient.new(BankApi.configuration)
39
+ .batch_transfers(transfers_data)
40
+ end
32
41
  end
33
42
  end
@@ -23,6 +23,10 @@ module BankApi::Clients
23
23
  super
24
24
  end
25
25
 
26
+ def bank_name
27
+ :bancochile
28
+ end
29
+
26
30
  private
27
31
 
28
32
  def validate_credentials
@@ -1,150 +1,62 @@
1
1
  require 'timezone'
2
2
 
3
3
  require 'bank_api/clients/base_client'
4
+ require 'bank_api/clients/banco_security/concerns/deposits'
5
+ require 'bank_api/clients/banco_security/concerns/login'
6
+ require 'bank_api/clients/banco_security/concerns/transfers'
7
+ require 'bank_api/clients/navigation/banco_security/company_navigation'
8
+ require 'bank_api/utils/banco_security'
4
9
 
5
10
  module BankApi::Clients::BancoSecurity
6
11
  class CompanyClient < BankApi::Clients::BaseClient
7
- BASE_URL = 'https://empresas.bancosecurity.cl/'
8
-
9
- DATE_COLUMN = 0
10
- RUT_COLUMN = 2
11
- AMOUNT_COLUMN = 5
12
-
13
- NUMBER_OF_COLUMNS = 7
12
+ include BankApi::Clients::Navigation::BancoSecurity::CompanyNavigation
13
+ include BankApi::Clients::BancoSecurity::Deposits
14
+ include BankApi::Clients::BancoSecurity::Transfers
15
+ include BankApi::Clients::BancoSecurity::Login
14
16
 
15
17
  def initialize(config = BankApi::Configuration.new)
16
18
  @user_rut = config.banco_security.user_rut
17
19
  @password = config.banco_security.password
18
20
  @company_rut = config.banco_security.company_rut
21
+ @dynamic_card = config.banco_security.dynamic_card
19
22
  super
20
23
  end
21
24
 
25
+ def bank_name
26
+ :security
27
+ end
28
+
22
29
  def get_deposits
23
30
  login
24
31
  goto_company_dashboard
25
32
  goto_deposits
26
33
  select_deposits_range
27
- deposits = any_deposits? ? extract_deposits_from_html : []
34
+ deposits = extract_deposits_from_html
28
35
  browser.close
29
36
  deposits
30
37
  end
31
38
 
32
- def validate_credentials
33
- raise BankApi::MissingCredentialsError if [
34
- @user_rut,
35
- @password,
36
- @company_rut
37
- ].any?(&:nil?)
38
- end
39
-
40
- def login
41
- goto_login
42
- set_login_values
43
- click_login_button
44
- end
45
-
46
- def goto_login
47
- if session_expired?
48
- browser.search("button:contains('Ingresa nuevamente')").click
49
- browser.search("a:contains('Empresas')").click
50
- else
51
- browser.goto BASE_URL
52
- browser.search('#mrcBtnIngresa').click
53
- end
54
- end
55
-
56
- def session_expired?
57
- browser.search("button:contains('Ingresa nuevamente')").any?
58
- end
59
-
60
- def set_login_values
61
- browser.search('#lrut').set @user_rut
62
- browser.search('#lpass').set @password
63
- end
64
-
65
- def click_login_button
66
- browser.search('input[name="Entrar"]').click
67
- end
68
-
69
- def goto_company_dashboard
70
- goto_frame query: '#mainFrame'
71
- goto_frame(query: 'iframe[name="central"]', should_reset: false)
72
- selenium_browser.execute_script(
73
- "submitEntrar(true,1,#{without_verifier_digit_or_separators(@company_rut)}," +
74
- "'#{verifier_digit(@company_rut)}');"
75
- )
76
- end
77
-
78
- def goto_deposits
79
- goto_frame query: '#topFrame'
80
- selenium_browser.execute_script(
81
- "MM_goToURL('parent.frames[\\'topFrame\\']','../menu/MenuTopTransferencias.asp'," +
82
- "'parent.frames[\\'leftFrame\\']','../menu/MenuTransferencias.asp'," +
83
- "'parent.frames[\\'mainFrame\\']','../../../noticias/transferencias.asp');"
84
- )
85
- selenium_browser.execute_script(
86
- "MM_goToURL('parent.frames[\\'mainFrame\\']'," +
87
- "'/empresas/RedirectConvivencia.asp?urlRedirect=CartolasTEF/Home/Index')"
88
- )
89
- goto_frame query: '#mainFrame'
90
- goto_frame query: 'iframe[name="central"]', should_reset: false
91
- wait('a.k-link:contains("Recibidas")').click
92
- end
93
-
94
- def select_deposits_range
95
- browser.search('.BusquedaPorDefectoRecibida a:contains("búsqueda avanzada")').click
96
- browser.search('#RadioEntreFechasRecibido').click
97
- browser.search('#datePickerInicioRecibidas').set deposit_range[:start]
98
- browser.search('#datePickerFinRecibido').set deposit_range[:end]
99
- browser.search('.ContenedorSubmitRecibidas .btn_buscar').click
100
- wait_for_deposits_fetch
101
- end
102
-
103
- def wait_for_deposits_fetch
104
- goto_frame query: '#mainFrame'
105
- goto_frame query: 'iframe[name="central"]', should_reset: false
106
- wait('.k-loading-image') { browser.search('.k-loading-image').count.zero? }
107
- end
108
-
109
- def extract_deposits_from_html
110
- deposits = []
111
- deposit = {}
112
- browser.search('#gridPrincipalRecibidas tbody td').each_with_index do |div, index|
113
- if (index % NUMBER_OF_COLUMNS) == RUT_COLUMN
114
- deposit[:rut] = div.text
115
- elsif (index % NUMBER_OF_COLUMNS) == DATE_COLUMN
116
- deposit[:date] = Date.parse div.text
117
- elsif (index % NUMBER_OF_COLUMNS) == AMOUNT_COLUMN
118
- deposit[:amount] = div.text.gsub(/[\. $]/, '').to_i
119
- elsif ((index + 1) % NUMBER_OF_COLUMNS).zero?
120
- deposits << deposit
121
- deposit = {}
122
- end
123
- end
124
- deposits
39
+ def execute_transfer(transfer_data)
40
+ login
41
+ goto_company_dashboard(transfer_data[:origin] || @company_rut)
42
+ goto_transfer_form
43
+ submit_transfer_form(transfer_data)
44
+ fill_coordinates
125
45
  end
126
46
 
127
- def deposit_range
128
- @deposit_range ||= begin
129
- timezone = Timezone['America/Santiago']
130
- {
131
- start: (timezone.utc_to_local(Time.now).to_date - @days_to_check).strftime('%d/%m/%Y'),
132
- end: timezone.utc_to_local(Time.now).to_date.strftime('%d/%m/%Y')
133
- }
47
+ def execute_batch_transfers(transfers_data)
48
+ login
49
+ transfers_data.each do |transfer_data|
50
+ goto_company_dashboard(transfer_data[:origin] || @company_rut)
51
+ goto_transfer_form
52
+ submit_transfer_form(transfer_data)
53
+ fill_coordinates
134
54
  end
135
55
  end
136
56
 
137
- def any_deposits?
138
- browser.search(
139
- ".k-label:contains('No se han encontrado transacciones para la búsqueda seleccionada.')"
140
- ).any?
141
- end
142
-
143
57
  def goto_frame(query: nil, should_reset: true)
144
58
  sleep 1
145
- browser.goto frame: :top if should_reset
146
- frame = wait(query) if query
147
- browser.goto(frame: frame)
59
+ super
148
60
  sleep 0.2
149
61
  end
150
62
  end
@@ -0,0 +1,85 @@
1
+ # coding: utf-8
2
+
3
+ module BankApi::Clients::BancoSecurity
4
+ module Deposits
5
+ DATE_COLUMN = 0
6
+ RUT_COLUMN = 2
7
+ AMOUNT_COLUMN = 5
8
+
9
+ NUMBER_OF_COLUMNS = 7
10
+
11
+ def select_deposits_range
12
+ browser.search('.BusquedaPorDefectoRecibida a:contains("búsqueda avanzada")').click
13
+ browser.search('#RadioEntreFechasRecibido').click
14
+ browser.search('#datePickerInicioRecibidas').set deposit_range[:start]
15
+ browser.search('#datePickerFinRecibido').set deposit_range[:end]
16
+ browser.search('.ContenedorSubmitRecibidas .btn_buscar').click
17
+ wait_for_deposits_fetch
18
+ end
19
+
20
+ def wait_for_deposits_fetch
21
+ goto_frame query: '#mainFrame'
22
+ goto_frame query: 'iframe[name="central"]', should_reset: false
23
+ sleep 0.5
24
+ wait('.k-loading-image') { browser.search('.k-loading-image').count.zero? }
25
+ end
26
+
27
+ def extract_deposits_from_html
28
+ deposits = []
29
+
30
+ return deposits unless any_deposits?
31
+
32
+ deposits += deposits_from_page
33
+
34
+ ((total_results - 1) / 50).times do
35
+ goto_next_page
36
+ deposits += deposits_from_page
37
+ end
38
+
39
+ deposits.sort_by { |d| d[:date] }
40
+ end
41
+
42
+ def deposits_from_page
43
+ deposits = []
44
+ deposit = {}
45
+ browser.search('#gridPrincipalRecibidas tbody td').each_with_index do |div, index|
46
+ if (index % NUMBER_OF_COLUMNS) == RUT_COLUMN
47
+ deposit[:rut] = div.text
48
+ elsif (index % NUMBER_OF_COLUMNS) == DATE_COLUMN
49
+ deposit[:date] = Date.parse div.text
50
+ elsif (index % NUMBER_OF_COLUMNS) == AMOUNT_COLUMN
51
+ deposit[:amount] = div.text.gsub(/[\. $]/, '').to_i
52
+ elsif ((index + 1) % NUMBER_OF_COLUMNS).zero?
53
+ deposits << deposit
54
+ deposit = {}
55
+ end
56
+ end
57
+ deposits
58
+ end
59
+
60
+ def goto_next_page
61
+ browser.search('#gridPrincipalRecibidas a.k-link[title="Go to the next page"]').click
62
+ end
63
+
64
+ def deposit_range
65
+ @deposit_range ||= begin
66
+ timezone = Timezone['America/Santiago']
67
+ {
68
+ start: (timezone.utc_to_local(Time.now).to_date - @days_to_check).strftime('%d/%m/%Y'),
69
+ end: timezone.utc_to_local(Time.now).to_date.strftime('%d/%m/%Y')
70
+ }
71
+ end
72
+ end
73
+
74
+ def any_deposits?
75
+ browser.search(
76
+ ".k-label:contains('No se han encontrado transacciones para la búsqueda seleccionada.')"
77
+ ).none?
78
+ end
79
+
80
+ def total_results
81
+ browser.search('#gridPrincipalRecibidas .k-pager-info')
82
+ .text.scan(/\d+/).last.to_i
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,26 @@
1
+ module BankApi::Clients::BancoSecurity
2
+ module Login
3
+ def validate_credentials
4
+ raise BankApi::MissingCredentialsError if [
5
+ @user_rut,
6
+ @password,
7
+ @company_rut
8
+ ].any?(&:nil?)
9
+ end
10
+
11
+ def login
12
+ goto_login
13
+ set_login_values
14
+ click_login_button
15
+ end
16
+
17
+ def set_login_values
18
+ browser.search('#lrut').set @user_rut
19
+ browser.search('#lpass').set @password
20
+ end
21
+
22
+ def click_login_button
23
+ browser.search('input[name="Entrar"]').click
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,63 @@
1
+ module BankApi::Clients::BancoSecurity
2
+ module Transfers
3
+ def validate_transfer_missing_data(transfer_data)
4
+ if [transfer_data[:origin] || @company_rut].all?(&:nil?)
5
+ raise BankApi::Transfer::MissingTransferData
6
+ end
7
+ if [
8
+ transfer_data[:amount],
9
+ transfer_data[:name],
10
+ transfer_data[:rut],
11
+ transfer_data[:account_number],
12
+ transfer_data[:email]
13
+ ].any?(&:nil?)
14
+ raise BankApi::Transfer::MissingTransferData
15
+ end
16
+ end
17
+
18
+ def validate_transfer_valid_data(transfer_data)
19
+ unless Utils::BancoSecurity.valid_banks.include? transfer_data[:bank]
20
+ raise BankApi::Transfer::InvalidBank
21
+ end
22
+ unless Utils::BancoSecurity.valid_account_types.include? transfer_data[:account_type]
23
+ raise BankApi::Transfer::InvalidAccountType
24
+ end
25
+ end
26
+
27
+ def submit_transfer_form(transfer_data)
28
+ set_transfer_transaction_data(transfer_data)
29
+ set_transfer_user_data(transfer_data)
30
+ browser.search('.active #enviar-paso-1').click
31
+ end
32
+
33
+ def set_transfer_user_data(transfer_data)
34
+ browser.search('.active #destinatario-nombre').set(transfer_data[:name])
35
+ browser.search('.active #destinatario-rut').set(transfer_data[:rut])
36
+ browser.search('.active #Email').set(transfer_data[:email])
37
+ end
38
+
39
+ def set_transfer_transaction_data(transfer_data)
40
+ browser.search('.active #Monto').set(transfer_data[:amount])
41
+ browser.search('.active #destinatario-cuenta').set(transfer_data[:account_number])
42
+ browser.search('.active #destinatario-banco').set(
43
+ Utils::BancoSecurity.bank_name(transfer_data[:bank])
44
+ )
45
+ browser.search(
46
+ ".active [name=\"tipo-cuenta\"][data-nombre=\"" +
47
+ Utils::BancoSecurity.account_type(transfer_data[:account_type]) +
48
+ "\"]"
49
+ ).set
50
+ browser.search('.active #Comentario').set(transfer_data[:comment])
51
+ end
52
+
53
+ def fill_coordinates
54
+ browser.search("[name=\"clave-dinamica-radio\"][value=\"tarjeta-clave\"]").set
55
+ (1..3).each do |i|
56
+ coordinate = browser.search("label[for=\"coordenada-#{i}\"").text
57
+ value = @dynamic_card.get_coordinate_value(coordinate)
58
+ browser.search("#coordenada-#{i}").set(value)
59
+ end
60
+ browser.search('#enviar-paso-2').click
61
+ end
62
+ end
63
+ end
@@ -16,8 +16,28 @@ module BankApi::Clients
16
16
  parse_entries(get_deposits)
17
17
  end
18
18
 
19
+ def transfer(transfer_data)
20
+ validate_credentials
21
+ validate_transfer_missing_data(transfer_data)
22
+ validate_transfer_valid_data(transfer_data)
23
+ execute_transfer(transfer_data)
24
+ end
25
+
26
+ def batch_transfers(transfers_data)
27
+ validate_credentials
28
+ transfers_data.each do |transfer_data|
29
+ validate_transfer_missing_data(transfer_data)
30
+ validate_transfer_valid_data(transfer_data)
31
+ end
32
+ execute_batch_transfers(transfers_data)
33
+ end
34
+
19
35
  private
20
36
 
37
+ def bank_name
38
+ raise NotImplementedError
39
+ end
40
+
21
41
  def validate_credentials
22
42
  raise NotImplementedError
23
43
  end
@@ -26,6 +46,22 @@ module BankApi::Clients
26
46
  raise NotImplementedError
27
47
  end
28
48
 
49
+ def validate_transfer_missing_data(_transfer_data)
50
+ raise NotImplementedError
51
+ end
52
+
53
+ def validate_transfer_valid_data(_transfer_data)
54
+ raise NotImplementedError
55
+ end
56
+
57
+ def execute_transfer(_transfer_data)
58
+ raise NotImplementedError
59
+ end
60
+
61
+ def execute_batch_transfers(_transfers_data)
62
+ raise NotImplementedError
63
+ end
64
+
29
65
  def without_verifier_digit_or_separators(rut)
30
66
  rut.split("-")[0].delete('.')
31
67
  end
@@ -75,12 +111,19 @@ module BankApi::Clients
75
111
  browser.search(query)
76
112
  end
77
113
 
114
+ def goto_frame(query: nil, should_reset: true)
115
+ browser.goto frame: :top if should_reset
116
+ frame = wait(query) if query
117
+ browser.goto(frame: frame)
118
+ end
119
+
78
120
  def parse_entries(entries)
79
121
  deposit_entries = entries.map do |entry|
80
122
  BankApi::Values::DepositEntry.new(
81
123
  entry[:amount],
82
124
  entry[:date],
83
- entry[:rut]
125
+ entry[:rut],
126
+ bank_name
84
127
  )
85
128
  end
86
129
  BankApi::SignDeposits.sign(deposit_entries)
@@ -0,0 +1,69 @@
1
+ module BankApi::Clients::Navigation
2
+ module BancoSecurity
3
+ module CompanyNavigation
4
+ BASE_URL = 'https://empresas.bancosecurity.cl/'
5
+
6
+ def goto_login
7
+ if session_expired?
8
+ browser.search("button:contains('Ingresa nuevamente')").click
9
+ browser.search("a:contains('Empresas')").click
10
+ else
11
+ browser.goto BASE_URL
12
+ browser.search('#mrcBtnIngresa').click
13
+ end
14
+ end
15
+
16
+ def session_expired?
17
+ browser.search("button:contains('Ingresa nuevamente')").any?
18
+ end
19
+
20
+ def goto_company_dashboard(company_rut = nil)
21
+ goto_frame query: '#topFrame'
22
+ if browser.search(".empresa a:contains(\"cambiar\")").any?
23
+ selenium_browser.execute_script(
24
+ "MM_goToURL('parent.frames[\\'mainFrame\\']'," +
25
+ "'/empresas/RedirectConvivencia.asp?urlRedirect=Perfilamiento/Home/Index')"
26
+ )
27
+ end
28
+ goto_frame query: '#mainFrame'
29
+ goto_frame(query: 'iframe[name="central"]', should_reset: false)
30
+ selenium_browser.execute_script(
31
+ "submitEntrar(true,1," +
32
+ "#{without_verifier_digit_or_separators(company_rut || @company_rut)}," +
33
+ "'#{verifier_digit(company_rut || @company_rut)}');"
34
+ )
35
+ end
36
+
37
+ def goto_deposits
38
+ goto_frame query: '#topFrame'
39
+ selenium_browser.execute_script(
40
+ "MM_goToURL('parent.frames[\\'topFrame\\']','../menu/MenuTopTransferencias.asp'," +
41
+ "'parent.frames[\\'leftFrame\\']','../menu/MenuTransferencias.asp'," +
42
+ "'parent.frames[\\'mainFrame\\']','../../../noticias/transferencias.asp');"
43
+ )
44
+ selenium_browser.execute_script(
45
+ "MM_goToURL('parent.frames[\\'mainFrame\\']'," +
46
+ "'/empresas/RedirectConvivencia.asp?urlRedirect=CartolasTEF/Home/Index')"
47
+ )
48
+ goto_frame query: '#mainFrame'
49
+ goto_frame query: 'iframe[name="central"]', should_reset: false
50
+ wait('a.k-link:contains("Recibidas")').click
51
+ end
52
+
53
+ def goto_transfer_form
54
+ goto_frame query: '#topFrame'
55
+ selenium_browser.execute_script(
56
+ "MM_goToURL('parent.frames[\\'topFrame\\']','../menu/MenuTopTransferencias.asp'," +
57
+ "'parent.frames[\\'leftFrame\\']','../menu/MenuTransferencias.asp'," +
58
+ "'parent.frames[\\'mainFrame\\']','../../../noticias/transferencias.asp');"
59
+ )
60
+ selenium_browser.execute_script(
61
+ "MM_goToURL('parent.frames[\\'mainFrame\\']'," +
62
+ "'/empresas/RedirectConvivencia.asp?urlRedirect=Transferencia/Tabs/Home')"
63
+ )
64
+ goto_frame query: '#mainFrame'
65
+ goto_frame query: 'iframe[name="central"]', should_reset: false
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,11 +1,18 @@
1
+ require 'bank_api/values/dynamic_card'
2
+
1
3
  module BankApi::Configs
2
4
  class BancoSecurity
3
- attr_accessor :user_rut, :password, :company_rut
5
+ attr_accessor :user_rut, :password, :company_rut, :dynamic_card_entries
4
6
 
5
7
  def initialize
6
8
  @user_rut = nil
7
9
  @password = nil
8
10
  @company_rut = nil
11
+ @dynamic_card_entries = nil
12
+ end
13
+
14
+ def dynamic_card
15
+ DynamicCard.new(@dynamic_card_entries) unless @dynamic_card_entries.nil?
9
16
  end
10
17
  end
11
18
  end
@@ -1,3 +1,8 @@
1
1
  module BankApi
2
2
  class MissingCredentialsError < StandardError; end
3
+ module Transfer
4
+ class InvalidBank < StandardError; end
5
+ class InvalidAccountType < StandardError; end
6
+ class MissingTransferData < StandardError; end
7
+ end
3
8
  end
@@ -35,10 +35,10 @@ module BankApi::SignDeposits
35
35
 
36
36
  def entry_signature(entry, occurrencies)
37
37
  key = entry_key(entry)
38
- Digest::SHA1.hexdigest("#{key}|#{occurrencies}")
38
+ Digest::SHA1.hexdigest("#{key}|#{occurrencies}") + Time.now.to_i.to_s
39
39
  end
40
40
 
41
41
  def entry_key(entry)
42
- "#{entry.amount}|#{entry.date}|#{entry.rut}"
42
+ "#{entry.amount}|#{entry.date}|#{entry.rut}|#{entry.bank}"
43
43
  end
44
44
  end
@@ -0,0 +1,49 @@
1
+ module Utils
2
+ module BancoSecurity
3
+ extend self
4
+
5
+ BANKS = {
6
+ banco_de_chile: 'Banco Chile-Edwards-Citi',
7
+ banco_consorcio: 'Banco Consorcio',
8
+ banco_del_desarrollo: 'Banco del Desarrollo',
9
+ banco_estado: 'Banco Estado',
10
+ banco_falabella: 'Banco Falabella',
11
+ banco_internacional: 'Banco Internacional',
12
+ banco_itau: 'Banco Ita\u00FA',
13
+ banco_paris: 'Banco Paris',
14
+ banco_rabobank: 'Banco Rabobank',
15
+ banco_ripley: 'Banco Ripley',
16
+ banco_santander: 'Banco Santander',
17
+ banco_security: 'Banco Security',
18
+ bbva: 'BBVA',
19
+ bci: 'BCI',
20
+ bice: 'BICE',
21
+ coopeuch: 'COOPEUCH',
22
+ corpbanca: 'Corpbanca',
23
+ hsbc: 'HSBC BANK',
24
+ scotiabank: 'Scotiabank'
25
+ }
26
+
27
+ def bank_name(bank)
28
+ BANKS[bank]
29
+ end
30
+
31
+ def valid_banks
32
+ BANKS.keys.sort
33
+ end
34
+
35
+ ACCOUNT_TYPES = {
36
+ cuenta_corriente: 'Cuenta Corriente',
37
+ cuenta_vista: 'Cuenta Vista',
38
+ cuenta_de_ahorro: 'Cuenta de Ahorro'
39
+ }
40
+
41
+ def account_type(type)
42
+ ACCOUNT_TYPES[type]
43
+ end
44
+
45
+ def valid_account_types
46
+ ACCOUNT_TYPES.keys.sort
47
+ end
48
+ end
49
+ end
@@ -1,11 +1,12 @@
1
1
  module BankApi::Values
2
2
  class DepositEntry
3
- attr_accessor :amount, :date, :rut, :signature
3
+ attr_accessor :amount, :date, :rut, :signature, :bank
4
4
 
5
- def initialize(amount, date, rut)
5
+ def initialize(amount, date, rut, bank)
6
6
  @amount = amount
7
7
  @date = date
8
8
  @rut = rut
9
+ @bank = bank
9
10
  end
10
11
  end
11
12
  end
@@ -0,0 +1,13 @@
1
+ require 'yaml'
2
+
3
+ class DynamicCard
4
+ def initialize(entries)
5
+ @coordinates_array = YAML::safe_load(entries.gsub(/,\s*([^\s])/, ', \1'))
6
+ end
7
+
8
+ def get_coordinate_value(coordinate)
9
+ col = ('A'..'J').to_a.index(coordinate[0])
10
+ row = (1..5).to_a.index(coordinate[1].to_i)
11
+ @coordinates_array[row][col]
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module BankApi
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - oaestay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-09 00:00:00.000000000 Z
11
+ date: 2018-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pincers
@@ -117,12 +117,18 @@ files:
117
117
  - lib/bank_api.rb
118
118
  - lib/bank_api/clients/banco_de_chile_company_client.rb
119
119
  - lib/bank_api/clients/banco_security/company_client.rb
120
+ - lib/bank_api/clients/banco_security/concerns/deposits.rb
121
+ - lib/bank_api/clients/banco_security/concerns/login.rb
122
+ - lib/bank_api/clients/banco_security/concerns/transfers.rb
120
123
  - lib/bank_api/clients/base_client.rb
124
+ - lib/bank_api/clients/navigation/banco_security/company_navigation.rb
121
125
  - lib/bank_api/configs/banco_security.rb
122
126
  - lib/bank_api/configuration.rb
123
127
  - lib/bank_api/exceptions.rb
124
128
  - lib/bank_api/sign_deposits.rb
129
+ - lib/bank_api/utils/banco_security.rb
125
130
  - lib/bank_api/values/deposit_entry.rb
131
+ - lib/bank_api/values/dynamic_card.rb
126
132
  - lib/bank_api/version.rb
127
133
  homepage: https://github.com/platanus/bank-api-gem
128
134
  licenses: