Class: Spree::Integrations::Avalara
- Inherits:
-
Spree::Integration
- Object
- Spree::Integration
- Spree::Integrations::Avalara
- Defined in:
- app/models/spree/integrations/avalara.rb
Constant Summary collapse
- SANDBOX_ENDPOINT =
'https://sandbox-rest.avatax.com'.freeze
- PRODUCTION_ENDPOINT =
'https://rest.avatax.com'.freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.icon_path ⇒ Object
22 23 24 |
# File 'app/models/spree/integrations/avalara.rb', line 22 def self.icon_path 'integration_icons/avalara-logo.png' end |
.integration_group ⇒ Object
18 19 20 |
# File 'app/models/spree/integrations/avalara.rb', line 18 def self.integration_group 'tax' end |
Instance Method Details
#avatax_client ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/spree/integrations/avalara.rb', line 47 def avatax_client AvaTax::Client.new( app_name: SpreeAvataxOfficial::Base::APP_NAME, app_version: SpreeAvataxOfficial::Base::APP_VERSION, connection_options: SpreeAvataxOfficial::Base::CONNECTION_OPTIONS, logger: SpreeAvataxOfficial::Config.log, faraday_response: true, endpoint: preferred_endpoint, username: preferred_account_number, password: preferred_license_key ) end |
#can_connect? ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/spree/integrations/avalara.rb', line 26 def can_connect? response = avatax_client.ping body = response.respond_to?(:body) ? response.body : response return true if body.is_a?(Hash) && body['authenticated'] @connection_error_message = if body.is_a?(Hash) && body.key?('authenticated') 'Invalid credentials' elsif body.is_a?(Hash) && body['error'].is_a?(Hash) body['error']['message'].presence || 'Could not connect to AvaTax' else 'Could not connect to AvaTax' end false rescue StandardError => e @connection_error_message = e. false end |