2020-02-24 14:22:58 +01:00
|
|
|
class BankAccountConnector
|
|
|
|
class TextItem
|
|
|
|
def initialize(text)
|
|
|
|
@text = text
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2023-01-06 16:27:41 +01:00
|
|
|
attr_reader :text
|
2020-02-24 14:22:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
class TextField
|
|
|
|
def initialize(name, value, label)
|
|
|
|
@name = name
|
|
|
|
@value = value
|
|
|
|
@label = label
|
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2023-01-06 16:27:41 +01:00
|
|
|
attr_reader :name, :value
|
2020-02-24 14:22:58 +01:00
|
|
|
|
|
|
|
def label
|
|
|
|
@label || @name.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class PasswordField < TextField
|
|
|
|
def type
|
|
|
|
:password
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class HiddenField < TextField
|
|
|
|
def type
|
|
|
|
:hidden
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
@registered_classes = Set.new
|
2020-02-24 14:22:58 +01:00
|
|
|
|
|
|
|
def self.register(klass)
|
2023-05-12 13:01:12 +02:00
|
|
|
@registered_classes.add klass
|
2020-02-24 14:22:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.find(iban)
|
2023-05-12 13:01:12 +02:00
|
|
|
@registered_classes.each do |klass|
|
2020-02-24 14:22:58 +01:00
|
|
|
return klass if klass.handles(iban)
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(bank_account)
|
|
|
|
@bank_account = bank_account
|
|
|
|
@auto_submit = nil
|
|
|
|
@controls = []
|
|
|
|
@count = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def iban
|
|
|
|
@bank_account.iban
|
|
|
|
end
|
|
|
|
|
2023-01-06 16:27:41 +01:00
|
|
|
attr_reader :auto_submit, :controls, :count
|
2020-02-24 14:22:58 +01:00
|
|
|
|
|
|
|
def text(data)
|
|
|
|
@controls += [TextItem.new(data)]
|
|
|
|
end
|
|
|
|
|
2020-07-29 19:18:12 +02:00
|
|
|
def confirm_text(code)
|
|
|
|
text t('.confirm', code: code)
|
|
|
|
end
|
|
|
|
|
|
|
|
def wait_with_text(auto_submit, code)
|
2020-02-24 14:22:58 +01:00
|
|
|
@auto_submit = auto_submit
|
2020-07-29 19:18:12 +02:00
|
|
|
confirm_text code
|
2020-02-24 14:22:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def wait_for_app(code)
|
|
|
|
hidden_field :twofactor, code
|
2020-07-29 19:18:12 +02:00
|
|
|
wait_with_text 3000, code
|
2020-02-24 14:22:58 +01:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2021-03-01 15:27:26 +01:00
|
|
|
def text_field(name, value = nil)
|
2020-02-24 14:22:58 +01:00
|
|
|
@controls += [TextField.new(name, value, t(name))]
|
|
|
|
end
|
|
|
|
|
|
|
|
def hidden_field(name, value)
|
|
|
|
@controls += [HiddenField.new(name, value, 'HIDDEN')]
|
|
|
|
end
|
|
|
|
|
2021-03-01 15:27:26 +01:00
|
|
|
def password_field(name, value = nil)
|
2020-02-24 14:22:58 +01:00
|
|
|
@controls += [PasswordField.new(name, value, t(name))]
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_balance(amount)
|
|
|
|
@bank_account.balance = amount
|
|
|
|
end
|
|
|
|
|
2020-07-29 19:18:12 +02:00
|
|
|
def set_balance_as_sum
|
|
|
|
@bank_account.balance = @bank_account.bank_transactions.sum(:amount)
|
|
|
|
end
|
|
|
|
|
2020-02-24 14:22:58 +01:00
|
|
|
def continuation_point
|
|
|
|
@bank_account.import_continuation_point
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_continuation_point(data)
|
|
|
|
@bank_account.import_continuation_point = data
|
|
|
|
end
|
|
|
|
|
2021-03-01 15:27:26 +01:00
|
|
|
def update_or_create_transaction(external_id, data = {})
|
2020-02-24 14:22:58 +01:00
|
|
|
@bank_account.bank_transactions.where(external_id: external_id).first_or_create.update(data)
|
|
|
|
@count += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def finish
|
|
|
|
@bank_account.last_import = Time.now
|
|
|
|
@bank_account.save!
|
|
|
|
end
|
|
|
|
|
2023-01-06 16:27:41 +01:00
|
|
|
def load(data); end
|
2020-02-24 14:22:58 +01:00
|
|
|
|
2023-01-06 16:27:41 +01:00
|
|
|
def dump; end
|
2020-02-24 14:22:58 +01:00
|
|
|
|
2021-03-01 15:27:26 +01:00
|
|
|
def t(key, args = {})
|
2020-02-24 14:22:58 +01:00
|
|
|
return t(".fields.#{key}") unless key.is_a? String
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2020-02-24 14:22:58 +01:00
|
|
|
I18n.t 'bank_account_connector' + key, args
|
|
|
|
end
|
|
|
|
end
|