module Nordea::Siirto

Gem specific errors

This module is intended as the sole public API of this gem.

AccessToken and Lookup requests are needed for actual processing requests, such as Pay, to work. Client should not need to call them directly, and therefore they are not directly callable from this module.

A method handle for each request meant to be called directly by client, should be included in this API.

Constants

ALLOWED_BIC

Only Nordea and OP supported at the moment

ENDPOINT

Nordea endpoints

ERROR

Error messages

MUTEX

Make sure initialization is thread safe

VERSION

Attributes

api_token[R]

Mandatory params: Client must provide these at setup

logger[R]

Optional params: Client may provide these at setup

protocol[R]

Optional params: Client may provide these at setup

redis[R]

Optional params: Client may provide these at setup

server[R]

Mandatory params: Client must provide these at setup

tag[R]

Optional params: Client may provide these at setup

username[R]

Mandatory params: Client must provide these at setup

Public Class Methods

endpoint() click to toggle source

Convenience method for requests @return [String]

# File lib/nordea/siirto/siirto.rb, line 86
def endpoint
  ENDPOINT[server]
end
initialized?() click to toggle source

Checks if gem is already initialized with required parameters. @return [Boolean]

# File lib/nordea/siirto/siirto.rb, line 69
def initialized?
  server.present? && username.present? && api_token.present?
end
log(msg) click to toggle source

Convenience method for requests @param msg [String]

# File lib/nordea/siirto/siirto.rb, line 92
def log(msg)
  logger.info("#{tag} #{msg}")
end
pay(payload) click to toggle source

8.2. Send a payment using IBAN account number POST /payment/pay

@param payload [Hash] See README @raise [Nordea::Siirto::Pay::InvalidIBAN] @raise [Nordea::Siirto::Pay::InvalidPayload] @return [Nordea::Siirto::Response]

# File lib/nordea/siirto/siirto.rb, line 80
def pay(payload)
  Pay.pay(payload)
end
setup(opts) click to toggle source

Client must initialize Nordea::Siirto module before calling other methods.

@params opts [Hash] See README for details @raise [Nordea::Siirto::InitializationError] @return [Boolean] rubocop:disable MethodLength

# File lib/nordea/siirto/siirto.rb, line 38
def setup(opts)
  MUTEX.synchronize do
    allow_initialize?(opts)

    # Initialize
    opts.each do |key, val|
      attr = "@#{key}".to_sym
      instance_variable_set(attr, val)
    end

    # Client can inject logger of choice
    @logger ||= Rails.logger

    # Client can inject logging tag
    @tag ||= 'Nordea::Siirto --'

    # Client can inject REDIS instance of choice, or adapter.
    @redis ||= REDIS

    # Client can inject another Protocol
    @protocol ||= Protocols::NetHttp.new

    # Initialization complete
    log('Initialized!')
    true
  end
end

Private Class Methods

allow_initialize?(opts) click to toggle source

Checks that module has not been previously initialized, and that arguments are more or less acceptable. @raise [Nordea::Siirto::InitializationError] rubocop:disable AbcSize,CyclomaticComplexity,GuardClause

# File lib/nordea/siirto/siirto.rb, line 112
def allow_initialize?(opts)
  raise InitializationError, ERROR[:already_initialized] if initialized?
  raise InitializationError, ERROR[:missing_args] if missing_args?(opts)
  if opts[:logger] && !opts[:logger].respond_to?(:info)
    raise InitializationError, ERROR[:invalid_logger]
  end
  if opts[:protocol] && !opts[:protocol].respond_to?(:send!)
    raise InitializationError, ERROR[:invalid_protocol]
  end
end
missing_args?(opts) click to toggle source

Checks that required parameters are present. @return [Boolean]

# File lib/nordea/siirto/siirto.rb, line 126
def missing_args?(opts)
  !(opts[:server] && opts[:username] && opts[:api_token] &&
    ENDPOINT.keys.include?(opts[:server].to_sym))
end