Class: Spree::Integrations::Kashflow

Inherits:
Spree::Integration
  • Object
show all
Defined in:
app/models/spree/integrations/kashflow.rb

Overview

Per-store KashFlow credentials and posting configuration.

The four numeric preferences decide which ledger accounts money lands in and deliberately have no defaults: a wrong nominal code silently posts revenue to the wrong place, so the integration cannot be saved until an operator chooses them.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.icon_pathString

Returns path to the bundled logo, relative to the asset root.

Returns:

  • (String)

    path to the bundled logo, relative to the asset root



38
39
40
# File 'app/models/spree/integrations/kashflow.rb', line 38

def self.icon_path
  "integration_icons/kashflow-logo.png"
end

.integration_groupString

Returns the admin group this integration is listed under.

Returns:

  • (String)

    the admin group this integration is listed under



31
32
33
# File 'app/models/spree/integrations/kashflow.rb', line 31

def self.integration_group
  "Accounting"
end

.integration_nameString

Returns the name shown in the admin.

Returns:

  • (String)

    the name shown in the admin



45
46
47
# File 'app/models/spree/integrations/kashflow.rb', line 45

def self.integration_name
  Spree.t("admin.integrations.kashflow.brand_name")
end

Instance Method Details

#bank_account_optionsArray<Array(String, Integer)>

Returns bank account [name, id] pairs for options_for_select; empty when credentials are absent or the lookup fails.

Returns:

  • (Array<Array(String, Integer)>)

    bank account [name, id] pairs for options_for_select; empty when credentials are absent or the lookup fails



80
81
82
# File 'app/models/spree/integrations/kashflow.rb', line 80

def 
  @bank_account_options ||= options_from { client.bank_accounts }
end

#can_connect?TrueClass, FalseClass

Verifies the stored credentials against the KashFlow API.

Returns:

  • (TrueClass, FalseClass)

    true when KashFlow accepts the credentials



54
55
56
57
58
59
# File 'app/models/spree/integrations/kashflow.rb', line 54

def can_connect?
  client.verify_credentials
rescue Spree::Kashflow::Error => e
  self.connection_error_message = e.message
  false
end

#clientSpree::Kashflow::Client

Returns a client bound to this integration's credentials.

Returns:



64
65
66
# File 'app/models/spree/integrations/kashflow.rb', line 64

def client
  Spree::Kashflow::Client.new(username: preferred_username, password: preferred_password)
end

#nominal_code_optionsArray<Array(String, Integer)>

Returns nominal code [name, id] pairs for options_for_select; empty when credentials are absent or the lookup fails.

Returns:

  • (Array<Array(String, Integer)>)

    nominal code [name, id] pairs for options_for_select; empty when credentials are absent or the lookup fails



72
73
74
# File 'app/models/spree/integrations/kashflow.rb', line 72

def nominal_code_options
  @nominal_code_options ||= options_from { client.nominal_codes }
end

#payment_method_optionsArray<Array(String, Integer)>

Returns invoice payment method [name, id] pairs for options_for_select; empty when credentials are absent or the lookup fails.

Returns:

  • (Array<Array(String, Integer)>)

    invoice payment method [name, id] pairs for options_for_select; empty when credentials are absent or the lookup fails



88
89
90
# File 'app/models/spree/integrations/kashflow.rb', line 88

def payment_method_options
  @payment_method_options ||= options_from { client.payment_methods }
end