Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions .circleci/config.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

jobs:
Comment thread
Copilot marked this conversation as resolved.
Resolved
rspec:
runs-on: ubuntu-latest
steps:
- uses: solidusio/test-solidus-extension@435ede6aecf3adbe1cc5093a57f1d91c022c8b62 # main, 2026-09-17
with:
database: sqlite
rails-version: "8.1"
ruby-version: "4.0"
solidus-branch: v4.8
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ solidus_branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
gem 'solidus', github: 'solidusio/solidus', branch: solidus_branch
gem 'solidus_auth_devise'

# The solidus_frontend gem has been pulled out since v3.2
if solidus_branch >= 'v3.2'
gem 'solidus_frontend'
elsif solidus_branch == 'main'
gem 'solidus_frontend', github: 'solidusio/solidus_frontend'
# The solidus_frontend gem has been pulled out since v3.2. The 4.8.0 release
# depends on canonical-rails, which caps actionview below 8.1, so pin the
# GitHub commit that vendors the canonical tag helper instead.
if solidus_branch == 'main' || solidus_branch >= 'v3.2'
gem 'solidus_frontend', github: 'solidusio/solidus_frontend', ref: '16546d19'
else
gem 'solidus_frontend', github: 'solidusio/solidus', branch: solidus_branch
end

# Needed to help Bundler figure out how to resolve dependencies,
# otherwise it takes forever to resolve them.
# See https://github.com/bundler/bundler/issues/6677
gem 'rails', '>0.a'
gem 'rails', ENV.key?('RAILS_VERSION') ? "~> #{ENV['RAILS_VERSION']}.0" : '>0.a'

case ENV['DB']
when 'postgresql'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# solidus_avatax_certified

[![CircleCI](https://circleci.com/gh/boomerdigital/solidus_avatax_certified.svg?style=svg)](https://circleci.com/gh/boomerdigital/solidus_avatax_certified)
[![Test](https://github.com/FrameworkComputer/solidus_avatax_certified/actions/workflows/test.yml/badge.svg)](https://github.com/FrameworkComputer/solidus_avatax_certified/actions/workflows/test.yml)

solidus_avatax_certified is the *only* [officially certified AvaTax solution](https://www.avalara.com/legal/avalara-certified.html)
that integrates with Solidus. With this extension, you can add instantaneous sales tax decisions to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//= require spree/backend/use_code_picker
//= require spree/address_validator

Spree.routes = Spree.routes || {}
Spree.routes.use_code_search = Spree.pathFor("admin/avalara_entity_use_codes")
Spree.routes.validate_address = Spree.pathFor("admin/avatax_settings/validate_address")
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//= require spree/address_validator
//= require spree/frontend/flash

Spree.routes = Spree.routes || {}
Spree.routes.validate_address = Spree.pathFor("checkout/validate_address")
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def index
format.json { render json: @avalara_entity_use_codes }
end
end

private

def permitted_resource_params
params.require(:avalara_entity_use_code).permit(:use_code, :use_code_description)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module UsersControllerDecorator
def avalara_information
if request.put?
if @user.update(user_params)
flash.now[:success] = I18n.t(:account_updated)
flash.now[:success] = I18n.t('spree.account_updated')
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/avalara_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def post_order_to_avalara(commit = false, doc_type = nil)
mytax = TaxSvc.new
response = mytax.get_tax(request)

return { 'totalTax' => 0.0 } if response.error?
return if response.error?
Comment thread
filippoliverani marked this conversation as resolved.
Resolved

response.tax_result
end
Expand Down
33 changes: 23 additions & 10 deletions app/models/spree/calculator/avalara_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Spree
class Calculator::AvalaraTransaction < Calculator::DefaultTax
LOOKUP_FAILED = 'Avalara lookup failed'

def self.description
"Avalara Transaction Calculator"
end
Expand Down Expand Up @@ -53,12 +55,24 @@ def can_calculate_tax?(order)
end

def get_avalara_response(order)
Rails.cache.fetch(cache_key(order), time_to_idle: 5.minutes) do
if order.can_commit?
order.avalara_capture_finalize
else
order.avalara_capture
end
key = cache_key(order)
cached = Rails.cache.read(key)
return cached unless cached.nil?
Comment thread
filippoliverani marked this conversation as resolved.
Resolved

if order.can_commit? && Spree::Avatax::Config.document_commit
cache_response(key, order.avalara_capture_finalize)
Comment thread
filippoliverani marked this conversation as resolved.
Resolved
else
cache_response(key, order.avalara_capture, expires_in: 5.minutes)
Comment thread
filippoliverani marked this conversation as resolved.
Resolved
end
end

def cache_response(key, response, **options)
if response
Rails.cache.write(key, response, **options)
response
else
Rails.cache.write(key, LOOKUP_FAILED, expires_in: 1.minute)
LOOKUP_FAILED
end
end

Expand All @@ -82,14 +96,13 @@ def long_cache_key(order)
def cache_key(order)
long_key = long_cache_key(order)
Comment thread
filippoliverani marked this conversation as resolved.
Resolved
short_key = Digest::SHA1.hexdigest(long_key)
"avtx_#{short_key}"
"avtx_v2_#{short_key}"
Comment thread
filippoliverani marked this conversation as resolved.
Resolved
end

def tax_for_item(item, avalara_response)
prev_tax_amount = prev_tax_amount(item)

return prev_tax_amount if avalara_response.nil?
return prev_tax_amount(item) unless avalara_response.is_a?(Hash)
Comment thread
filippoliverani marked this conversation as resolved.
Resolved
return 0 if avalara_response['totalTax'] == 0.0
return 0 if avalara_response['lines'].nil?
Comment thread
filippoliverani marked this conversation as resolved.
Resolved

avalara_response['lines'].each do |line|
if line['lineNumber'] == "#{item.id}-#{item.avatax_line_code}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

<%= form_for [:admin, @avalara_entity_use_code], :method => :put do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<p class="form-buttons" data-hook="buttons"><%= button t('spree.update') %></p>
<%= render :partial => 'spree/admin/shared/edit_resource_links' %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<% content_for :page_actions do %>
<li>
<%= button_link_to t('spree.new_avalara_entity_use_code'), new_object_url, :icon => 'plus', :id => 'admin_new_avalara_entity_use_code_link' %>
<%= link_to t('spree.new_avalara_entity_use_code'), new_object_url, :class => 'btn btn-primary', :id => 'admin_new_avalara_entity_use_code_link' %>
</li>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSpreeAvalaraTransactions < SolidusSupport::Migration[4.2]
class CreateSpreeAvalaraTransactions < ActiveRecord::Migration[4.2]
def change
create_table :spree_avalara_transactions do |t|
t.references :order, index: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSpreeAvalaraEntityUseCodes < SolidusSupport::Migration[4.2]
class CreateSpreeAvalaraEntityUseCodes < ActiveRecord::Migration[4.2]
def change
create_table :spree_avalara_entity_use_codes do |t|
t.string :use_code
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160624155217_add_columns_to_spree_users.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class AddColumnsToSpreeUsers < SolidusSupport::Migration[4.2]
class AddColumnsToSpreeUsers < ActiveRecord::Migration[4.2]
def change
add_column :spree_users, :exemption_number, :string
add_reference :spree_users, :avalara_entity_use_code, index: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CreateSpreeAvalaraPreferences < SolidusSupport::Migration[4.2]
class CreateSpreeAvalaraPreferences < ActiveRecord::Migration[4.2]
def change
create_table :spree_avalara_preferences do |t|
t.string :name, null: false
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20160805193512_add_vat_id_to_spree_users.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class AddVatIdToSpreeUsers < SolidusSupport::Migration[4.2]
class AddVatIdToSpreeUsers < ActiveRecord::Migration[4.2]
def change
add_column :spree_users, :vat_id, :string
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class DropSpreeAvalaraPreferences < SolidusSupport::Migration[4.2]
class DropSpreeAvalaraPreferences < ActiveRecord::Migration[4.2]
def change
drop_table :spree_avalara_preferences
p '****** Remember to reenter your avatax preferences! ******'
Expand Down
14 changes: 8 additions & 6 deletions lib/solidus_avatax_certified/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ class Engine < Rails::Engine

include SolidusSupport::EngineExtensions

# SolidusSupport `load`s each decorator that Zeitwerk also autoloads, so every body ran twice.
# Resolving the constant lets Zeitwerk execute each file once per boot and once per reload.
def self.load_solidus_decorators_from(path)
path.glob('**/*.rb') do |decorator_path|
Rails.autoloaders.main.cpath_expected_at(decorator_path).constantize
Comment thread
filippoliverani marked this conversation as resolved.
Resolved
end
end

config.autoload_paths += %W(#{config.root}/lib)

# use rspec for tests
config.generators do |g|
g.test_framework :rspec
end

config.to_prepare do
Dir.glob(File.join(File.dirname(__FILE__), '../../app/decorators/**/*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

def self.frontend_available?
const_defined?('::Spree::Frontend::Engine')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ship_address
completed_at { nil }
email { user.email }
store
association :store, strategy: :create
state { 'delivery' }

transient do
Expand Down
5 changes: 3 additions & 2 deletions solidus_avatax_certified.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Gem::Specification.new do |s|
s.add_dependency 'avatax'
s.add_dependency 'deface', '>= 1.5'
s.add_dependency 'json', '>= 2.0'
s.add_dependency 'solidus_core', ['>= 4']
s.add_dependency 'solidus_support', [">= 0.8"]
s.add_dependency 'solidus_core', ['>= 4.1']
s.add_dependency 'solidus_support', [">= 0.15"]
Comment thread
Copilot marked this conversation as resolved.
Resolved
Comment thread
filippoliverani marked this conversation as resolved.
Resolved
s.add_dependency 'zeitwerk', '>= 2.6.9'

s.add_development_dependency 'cuprite'
s.add_development_dependency 'shoulda-matchers'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
RSpec.describe Spree::Admin::AvalaraEntityUseCodesController do
let(:avalara_entity_use_code) { FactoryBot.create(:avalara_entity_use_code) }

render_views
Comment thread
filippoliverani marked this conversation as resolved.
Resolved

stub_authorization!

before do
Expand All @@ -14,7 +16,15 @@
describe '#index' do
subject { get :index }

before { avalara_entity_use_code }

it { is_expected.to be_successful }

it 'renders the use code row with its edit link' do
subject

expect(response.body).to include("/admin/avalara_entity_use_codes/#{avalara_entity_use_code.id}/edit")
end
end

describe '#new' do
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/spree/admin/users_controller_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Spree::Admin::UsersController do
let(:user) { FactoryBot.create(:user) }

stub_authorization!

before do
DatabaseCleaner.clean
end

describe 'PUT avalara_information' do
subject do
put :avalara_information, params: { id: user.id, user: { exemption_number: 'FED-EX-12345' } }
end

it 'sets a resolved success flash message, not a missing translation' do
subject
expect(flash[:success]).to eq('Account updated')
end
end
end
Loading
Loading