super_good-solidus_taxjar 0.18.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +48 -6
- data/CHANGELOG.md +103 -1
- data/Gemfile +26 -10
- data/PULL_REQUEST_TEMPLATE.md +0 -1
- data/README.md +299 -39
- data/Rakefile +3 -0
- data/app/controllers/spree/admin/taxjar_settings_controller.rb +86 -1
- data/app/controllers/spree/admin/taxjar_transactions_controller.rb +37 -0
- data/app/controllers/spree/admin/transaction_sync_batches_controller.rb +18 -0
- data/app/jobs/super_good/solidus_taxjar/backfill_transaction_sync_batch_job.rb +23 -0
- data/app/jobs/super_good/solidus_taxjar/replace_transaction_job.rb +26 -0
- data/app/jobs/super_good/solidus_taxjar/report_transaction_job.rb +22 -0
- data/app/models/super_good/solidus_taxjar/configuration.rb +27 -0
- data/app/models/super_good/solidus_taxjar/order_transaction.rb +16 -0
- data/app/models/super_good/solidus_taxjar/refund_transaction.rb +13 -0
- data/app/models/super_good/solidus_taxjar/transaction_sync_batch.rb +11 -0
- data/app/models/super_good/solidus_taxjar/transaction_sync_log.rb +8 -0
- data/app/overrides/spree/admin/orders_controller_override.rb +12 -0
- data/app/overrides/spree/admin/shared/_order_submenu/add_taxjar_sync_history_tab.html.erb.deface +6 -0
- data/app/overrides/spree/admin/shared/_order_summary/add_taxjar_reported_at.html.erb.deface +30 -0
- data/app/overrides/spree/admin/shared/_taxes_tabs/add_configuration_menu_items.html.erb.deface +5 -0
- data/app/overrides/super_good/solidus_taxjar/spree/order_override.rb +21 -0
- data/app/views/spree/admin/orders/taxjar_transactions.html.erb +4 -0
- data/app/views/spree/admin/shared/_transaction_sync_log_table.html.erb +35 -0
- data/app/views/spree/admin/taxjar_settings/_nexus_regions.html.erb +23 -0
- data/app/views/spree/admin/taxjar_settings/_tax_categories.html.erb +41 -0
- data/app/views/spree/admin/taxjar_settings/edit.html.erb +17 -0
- data/app/views/spree/admin/taxjar_settings/edit_no_api_key.html.erb +21 -0
- data/app/views/spree/admin/transaction_sync_batches/index.html.erb +50 -0
- data/app/views/spree/admin/transaction_sync_batches/show.html.erb +7 -0
- data/bin/console +2 -0
- data/bin/rails-engine +1 -1
- data/bin/sandbox +43 -36
- data/bin/setup +3 -3
- data/config/routes.rb +13 -1
- data/db/migrate/20210908205201_create_taxjar_order_transactions.rb +16 -0
- data/db/migrate/20211008175113_create_taxjar_refund_transaction.rb +15 -0
- data/db/migrate/20211008183858_add_transaction_date_to_order_transaction.rb +5 -0
- data/db/migrate/20211119143354_create_configuration.rb +8 -0
- data/db/migrate/20220405213958_create_transaction_sync_batches.rb +7 -0
- data/db/migrate/20220405215225_create_transaction_sync_logs.rb +14 -0
- data/db/migrate/20220908181655_add_dates_to_transaction_sync_batch.rb +6 -0
- data/db/migrate/20220912182210_allow_null_transaction_sync_batches_on_logs.rb +5 -0
- data/db/migrate/20230320211309_add_refund_transaction_to_sync_logs.rb +5 -0
- data/lib/generators/super_good/solidus_taxjar/install/install_generator.rb +68 -0
- data/lib/super_good/solidus_taxjar/api.rb +41 -9
- data/lib/super_good/solidus_taxjar/api_params.rb +92 -25
- data/lib/super_good/solidus_taxjar/backfill_transactions.rb +11 -0
- data/lib/super_good/solidus_taxjar/cached_api.rb +23 -0
- data/lib/super_good/solidus_taxjar/calculator_helper.rb +33 -4
- data/lib/super_good/solidus_taxjar/discount_calculator.rb +1 -1
- data/lib/super_good/solidus_taxjar/overrides/request_override.rb +15 -0
- data/lib/super_good/solidus_taxjar/reportable.rb +91 -0
- data/lib/super_good/solidus_taxjar/reporting.rb +44 -0
- data/lib/super_good/solidus_taxjar/spree/legacy_reporting_subscriber.rb +41 -0
- data/lib/super_good/solidus_taxjar/spree/reporting_subscriber.rb +40 -0
- data/lib/super_good/solidus_taxjar/tax_calculator.rb +7 -1
- data/lib/super_good/solidus_taxjar/testing_support/factories/address_factory.rb +11 -0
- data/lib/super_good/solidus_taxjar/testing_support/factories/configuration_factory.rb +11 -0
- data/lib/super_good/solidus_taxjar/testing_support/factories/order_transaction_factory.rb +22 -0
- data/lib/super_good/solidus_taxjar/testing_support/factories/refund_transaction_factory.rb +7 -0
- data/lib/super_good/solidus_taxjar/testing_support/factories/transaction_sync_batch_factory.rb +9 -0
- data/lib/super_good/solidus_taxjar/testing_support/factories/transaction_sync_log_factory.rb +18 -0
- data/lib/super_good/solidus_taxjar/transaction_id_generator.rb +45 -0
- data/lib/super_good/solidus_taxjar/version.rb +1 -1
- data/lib/super_good/solidus_taxjar.rb +29 -2
- data/spec/features/spree/admin/backfill_transactions_spec.rb +138 -0
- data/spec/features/spree/admin/refund_spec.rb +167 -0
- data/spec/features/spree/admin/reporting_to_taxjar_spec.rb +156 -0
- data/spec/features/spree/admin/taxjar_settings_spec.rb +58 -16
- data/spec/features/spree/checkout_spec.rb +58 -0
- data/spec/fixtures/cassettes/Admin_TaxJar_Settings/GET_sync_nexus_regions/Taxjar_API_token_is_not_set/doesn_t_make_a_request_for_the_nexus_regions.yml +57 -0
- data/spec/fixtures/cassettes/Admin_TaxJar_Settings/GET_sync_tax_categories/Taxjar_API_token_is_not_set/doesn_t_make_a_request_for_the_tax_categories.yml +57 -0
- data/spec/fixtures/cassettes/Admin_TaxJar_Settings/Taxjar_settings_tab/Taxjar_API_token_is_set/shows_the_settings_page.yml +2437 -0
- data/spec/fixtures/cassettes/Admin_TaxJar_Settings/Taxjar_settings_tab/Taxjar_API_token_isn_t_set/doesn_t_show_any_other_TaxJar_features.yml +57 -0
- data/spec/fixtures/cassettes/Admin_TaxJar_Settings/Taxjar_settings_tab/Taxjar_API_token_isn_t_set/shows_a_descriptive_error_message.yml +57 -0
- data/spec/fixtures/cassettes/Admin_TaxJar_Settings/Taxjar_settings_tab/Taxjar_reporting_is_enabled/shows_that_reporting_is_enabled.yml +2382 -0
- data/spec/fixtures/cassettes/Admin_TaxJar_Settings/Taxjar_settings_tab/order_is_shipped/the_user_backfills_their_transactions.yml +2511 -0
- data/spec/fixtures/cassettes/Admin_TaxJar_Settings/Taxjar_settings_tab/the_user_navigates_to_the_TaxJar_Settings.yml +2382 -0
- data/spec/fixtures/cassettes/Admin_Transaction_Sync_Batches/user_has_a_shipped_order/starts_a_transaction_backfill.yml +370 -0
- data/spec/fixtures/cassettes/Reporting_orders_to_TaxJar/shipping_a_complete_and_paid_order.yml +310 -0
- data/spec/fixtures/cassettes/Reporting_orders_to_TaxJar/updating_an_order_which_was_not_reported_due_to_failure/it_reports_the_order_instead_of_trying_to_replace_it.yml +794 -0
- data/spec/fixtures/cassettes/Reporting_orders_to_TaxJar/with_an_order_with_invalid_zipcode/retry_of_a_previously_failed_transaction_sync.yml +418 -0
- data/spec/fixtures/cassettes/Spree_Admin_TransactionSyncBatchesController/_create/creates_a_batch.yml +250 -0
- data/spec/fixtures/cassettes/Spree_Admin_TransactionSyncBatchesController/_create/creates_a_log_in_the_batch_with_an_order.yml +250 -0
- data/spec/fixtures/cassettes/Spree_Admin_TransactionSyncBatchesController/_create/user_supplies_a_start_date/creates_a_batch.yml +250 -0
- data/spec/fixtures/cassettes/Spree_Admin_TransactionSyncBatchesController/_create/user_supplies_a_start_date/user_supplies_start_and_end_date/creates_a_batch.yml +250 -0
- data/spec/fixtures/cassettes/SuperGood_SolidusTaxjar_CalculatorHelper/_taxable_address_/when_taxable_address_check_returns_true/with_US_address/when_the_address_is_not_within_a_nexus_region/1_3_2_2_2_1.yml +58 -0
- data/spec/fixtures/cassettes/SuperGood_SolidusTaxjar_CalculatorHelper/_taxable_address_/when_taxable_address_check_returns_true/with_US_address/when_the_address_is_within_a_nexus_region/1_3_2_2_1_1.yml +58 -0
- data/spec/fixtures/cassettes/SuperGood_SolidusTaxjar_Reporting/_refund_and_create_transaction/when_Taxjar_cannot_create_a_refund_transaction/doesn_t_create_a_new_transaction.yml +393 -0
- data/spec/fixtures/cassettes/SuperGood_SolidusTaxjar_Reporting/_refund_and_create_transaction/when_Taxjar_cannot_create_a_refund_transaction/raises_an_error.yml +393 -0
- data/spec/fixtures/cassettes/Taxjar_API_Request/logging_is_disabled/doesn_t_call_the_logger.yml +158 -0
- data/spec/fixtures/cassettes/Taxjar_API_Request/logging_is_enabled/calls_the_logger.yml +158 -0
- data/spec/fixtures/cassettes/features/spree/admin/checkout.yml +238 -0
- data/spec/fixtures/cassettes/features/spree/admin/refund.yml +1162 -0
- data/spec/jobs/super_good/solidus_taxjar/backfill_transaction_sync_batch_job_spec.rb +117 -0
- data/spec/jobs/super_good/solidus_taxjar/replace_transaction_job_spec.rb +95 -0
- data/spec/jobs/super_good/solidus_taxjar/report_transaction_job_spec.rb +76 -0
- data/spec/models/super_good/solidus_taxjar/configuration_spec.rb +79 -0
- data/spec/models/super_good/solidus_taxjar/order_transaction_spec.rb +36 -0
- data/spec/models/super_good/solidus_taxjar/transaction_sync_batch_spec.rb +48 -0
- data/spec/requests/spree/admin/order_request_spec.rb +121 -0
- data/spec/requests/spree/admin/taxjar_settings_request_spec.rb +198 -0
- data/spec/requests/spree/admin/taxjar_transactions_request_spec.rb +62 -0
- data/spec/requests/spree/admin/transaction_sync_batches_request_spec.rb +82 -0
- data/spec/spec_helper.rb +46 -3
- data/spec/subscribers/super_good/solidus_taxjar/spree/reporting_subscriber_spec.rb +278 -0
- data/spec/super_good/solidus_taxjar/addresses_spec.rb +0 -14
- data/spec/super_good/solidus_taxjar/api_params_spec.rb +261 -89
- data/spec/super_good/solidus_taxjar/api_spec.rb +152 -29
- data/spec/super_good/solidus_taxjar/backfill_transactions_spec.rb +24 -0
- data/spec/super_good/solidus_taxjar/cached_api_spec.rb +58 -0
- data/spec/super_good/solidus_taxjar/calculator_helper_spec.rb +131 -0
- data/spec/super_good/solidus_taxjar/discount_calculator_spec.rb +19 -2
- data/spec/super_good/solidus_taxjar/reportable_spec.rb +194 -0
- data/spec/super_good/solidus_taxjar/reporting_spec.rb +243 -0
- data/spec/super_good/solidus_taxjar/tax_calculator_spec.rb +19 -19
- data/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb +8 -3
- data/spec/super_good/solidus_taxjar/transaction_id_generator_spec.rb +77 -0
- data/spec/super_good/solidus_taxjar_spec.rb +84 -0
- data/spec/support/checkoutable_store_shared_context.rb +19 -0
- data/spec/support/solidus_events_helper.rb +26 -0
- data/spec/taxjar/api/request_spec.rb +52 -0
- data/super_good-solidus_taxjar.gemspec +3 -2
- metadata +169 -17
- data/app/decorators/super_good/solidus_taxjar/spree/order_updater/fire_recalculated_event.rb +0 -18
- data/app/overrides/spree/admin/shared/_configuration_menu.rb +0 -11
- data/app/views/spree/admin/taxjar_settings/show.html.erb +0 -13
- data/spec/models/spree/order_updater_spec.rb +0 -12
@@ -10,8 +10,6 @@ RSpec.describe SuperGood::SolidusTaxjar::Addresses do
|
|
10
10
|
address1: "475 North Beverly Drive",
|
11
11
|
city: "Los Angeles",
|
12
12
|
country: country_us,
|
13
|
-
first_name: "Chuck",
|
14
|
-
last_name: "Schuldiner",
|
15
13
|
phone: "1-250-555-4444",
|
16
14
|
state: state_california,
|
17
15
|
zipcode: "90210"
|
@@ -79,8 +77,6 @@ RSpec.describe SuperGood::SolidusTaxjar::Addresses do
|
|
79
77
|
address1: "475 N Beverly Dr",
|
80
78
|
city: "Beverly Hills",
|
81
79
|
country: country_us,
|
82
|
-
first_name: "Chuck",
|
83
|
-
last_name: "Schuldiner",
|
84
80
|
phone: "1-250-555-4444",
|
85
81
|
state: state_california,
|
86
82
|
zipcode: "90210-4606"
|
@@ -123,8 +119,6 @@ RSpec.describe SuperGood::SolidusTaxjar::Addresses do
|
|
123
119
|
address1: "475 N Beverly Dr",
|
124
120
|
city: "Beverly Hills",
|
125
121
|
country: country_us,
|
126
|
-
first_name: "Chuck",
|
127
|
-
last_name: "Schuldiner",
|
128
122
|
phone: "1-250-555-4444",
|
129
123
|
state: state_california,
|
130
124
|
zipcode: "90210-4606"
|
@@ -143,8 +137,6 @@ RSpec.describe SuperGood::SolidusTaxjar::Addresses do
|
|
143
137
|
address1: "475 North Beverly Drive",
|
144
138
|
city: "Los Angeles",
|
145
139
|
country: country_us,
|
146
|
-
first_name: "Chuck",
|
147
|
-
last_name: "Schuldiner",
|
148
140
|
phone: "1-250-555-4444",
|
149
141
|
state: state_california,
|
150
142
|
zipcode: "90210"
|
@@ -212,8 +204,6 @@ RSpec.describe SuperGood::SolidusTaxjar::Addresses do
|
|
212
204
|
address1: "475 N Beverly Dr",
|
213
205
|
city: "Beverly Hills",
|
214
206
|
country: country_us,
|
215
|
-
first_name: "Chuck",
|
216
|
-
last_name: "Schuldiner",
|
217
207
|
phone: "1-250-555-4444",
|
218
208
|
state: state_california,
|
219
209
|
zipcode: "90210-4606"
|
@@ -264,8 +254,6 @@ RSpec.describe SuperGood::SolidusTaxjar::Addresses do
|
|
264
254
|
address1: "475 N Beverly Dr",
|
265
255
|
city: "Beverly Hills",
|
266
256
|
country: country_us,
|
267
|
-
first_name: "Chuck",
|
268
|
-
last_name: "Schuldiner",
|
269
257
|
phone: "1-250-555-4444",
|
270
258
|
state: state_california,
|
271
259
|
zipcode: "90210-4606"
|
@@ -275,8 +263,6 @@ RSpec.describe SuperGood::SolidusTaxjar::Addresses do
|
|
275
263
|
address1: "473 N Beverly Dr",
|
276
264
|
city: "Phoenix",
|
277
265
|
country: country_us,
|
278
|
-
first_name: "Chuck",
|
279
|
-
last_name: "Schuldiner",
|
280
266
|
phone: "1-250-555-4444",
|
281
267
|
state: state_arizona,
|
282
268
|
zipcode: "90213-1234"
|
@@ -2,24 +2,27 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
4
4
|
let(:order) do
|
5
|
-
|
6
|
-
additional_tax_total: BigDecimal("9.87"),
|
7
|
-
item_total: BigDecimal("28.00"),
|
8
|
-
line_items: [line_item],
|
5
|
+
create(:order,
|
9
6
|
number: "R111222333",
|
10
7
|
ship_address: ship_address,
|
8
|
+
line_items: line_items_attributes.map { |attributes| build(:line_item, attributes) },
|
11
9
|
store: store,
|
12
|
-
total: order_total,
|
13
10
|
shipments: [shipment],
|
14
|
-
user_id: 12345
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
user_id: 12345,
|
12
|
+
completed_at: DateTime.new(2018, 3, 6, 12, 10, 33),
|
13
|
+
payments: payments).tap do |order|
|
14
|
+
order.update_columns(additional_tax_total: 9.87, item_total: 28.00, total: order_total)
|
15
|
+
order.line_items.each_with_index do |line_item, idx|
|
16
|
+
line_item.update_columns(line_items_attributes[idx])
|
17
|
+
end
|
18
|
+
end
|
18
19
|
end
|
19
20
|
let(:order_total) { BigDecimal("123.45") }
|
21
|
+
let(:payments) { build_list(:payment, 1, :completed, amount: 110.45) }
|
20
22
|
|
21
23
|
let(:store) do
|
22
|
-
|
24
|
+
create(
|
25
|
+
:store,
|
23
26
|
cart_tax_country_iso: "US",
|
24
27
|
code: "store",
|
25
28
|
mail_from_address: "contact@example.com",
|
@@ -28,58 +31,70 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
28
31
|
)
|
29
32
|
end
|
30
33
|
|
31
|
-
let(:ship_address) do
|
32
|
-
|
34
|
+
let!(:ship_address) do
|
35
|
+
create(
|
36
|
+
:address,
|
33
37
|
address1: "475 N Beverly Dr",
|
38
|
+
address2: nil,
|
34
39
|
city: "Los Angeles",
|
35
40
|
country: country_us,
|
36
|
-
first_name: "Chuck",
|
37
|
-
last_name: "Schuldiner",
|
38
41
|
phone: "1-250-555-4444",
|
39
|
-
|
42
|
+
state_code: "CA",
|
40
43
|
zipcode: "90210"
|
41
44
|
)
|
42
45
|
end
|
43
46
|
|
44
47
|
let(:country_us) do
|
45
|
-
|
46
|
-
|
48
|
+
create(
|
49
|
+
:country,
|
47
50
|
iso: "US",
|
48
|
-
iso_name: "UNITED STATES",
|
49
|
-
name: "United States",
|
50
|
-
numcode: 840,
|
51
51
|
states_required: true
|
52
52
|
)
|
53
53
|
end
|
54
54
|
|
55
|
-
let(:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
let(:line_items_attributes) do
|
56
|
+
[
|
57
|
+
attributes_for(
|
58
|
+
:line_item,
|
59
|
+
additional_tax_total: 4,
|
60
|
+
price: 10,
|
61
|
+
promo_total: -2,
|
62
|
+
quantity: 3,
|
63
|
+
variant_id: variant.id
|
64
|
+
)
|
65
|
+
]
|
61
66
|
end
|
62
67
|
|
63
|
-
let(:
|
64
|
-
|
65
|
-
|
68
|
+
let(:variant) do
|
69
|
+
create(
|
70
|
+
:variant,
|
66
71
|
price: 10,
|
67
|
-
|
68
|
-
|
69
|
-
|
72
|
+
product: product,
|
73
|
+
sku: "G00D-PR0DUCT",
|
74
|
+
option_values: [option_value]
|
70
75
|
)
|
71
76
|
end
|
72
77
|
|
73
|
-
let(:
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
let(:option_value) do
|
79
|
+
create(
|
80
|
+
:option_value,
|
81
|
+
name: "Red",
|
82
|
+
presentation: "red",
|
83
|
+
option_type: option_type
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:option_type) do
|
88
|
+
create(
|
89
|
+
:option_type,
|
90
|
+
name: "Color",
|
91
|
+
presentation: "color"
|
78
92
|
)
|
79
93
|
end
|
80
94
|
|
81
95
|
let(:product) do
|
82
|
-
|
96
|
+
create(
|
97
|
+
:product,
|
83
98
|
master: master_variant,
|
84
99
|
name: "Product Name",
|
85
100
|
shipping_category: shipping_category,
|
@@ -88,12 +103,11 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
88
103
|
)
|
89
104
|
end
|
90
105
|
|
91
|
-
let(:shipping_category)
|
92
|
-
Spree::ShippingCategory.create!(name: "Default Category")
|
93
|
-
end
|
106
|
+
let(:shipping_category){ create(:shipping_category) }
|
94
107
|
|
95
108
|
let(:tax_category) do
|
96
|
-
|
109
|
+
create(
|
110
|
+
:tax_category,
|
97
111
|
is_default: true,
|
98
112
|
name: "Default",
|
99
113
|
tax_code: "A_GEN_TAX"
|
@@ -101,29 +115,52 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
101
115
|
end
|
102
116
|
|
103
117
|
let(:master_variant) do
|
104
|
-
|
118
|
+
build(
|
119
|
+
:variant,
|
105
120
|
is_master: true,
|
106
121
|
price: 10
|
107
122
|
)
|
108
123
|
end
|
109
124
|
|
110
125
|
let(:reimbursement) do
|
111
|
-
|
126
|
+
build(
|
127
|
+
:reimbursement,
|
112
128
|
number: "RI123123123",
|
113
129
|
order: order,
|
114
130
|
return_items: [
|
115
|
-
|
116
|
-
|
131
|
+
build(:return_item, additional_tax_total: 0.33),
|
132
|
+
build(:return_item, additional_tax_total: 33.0)
|
117
133
|
],
|
118
134
|
total: 333.33
|
119
135
|
)
|
120
136
|
end
|
121
137
|
|
122
|
-
let(:shipment) {
|
138
|
+
let(:shipment) { create(:shipment, cost: BigDecimal("3.01")) }
|
139
|
+
|
140
|
+
before do
|
141
|
+
create :state, state_code: "CA"
|
142
|
+
create :state, state_code: "NY"
|
123
143
|
|
124
|
-
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
describe ".order_params" do
|
125
148
|
subject { described_class.order_params(order) }
|
126
149
|
|
150
|
+
before do
|
151
|
+
# The discount calculator relies on the line item adjustments existing in
|
152
|
+
# order to calculate the correct discount amount for TaxJar.
|
153
|
+
create(
|
154
|
+
:adjustment,
|
155
|
+
order: order,
|
156
|
+
adjustable: order.line_items.first,
|
157
|
+
amount: line_items_attributes.first[:promo_total],
|
158
|
+
source_type: "Spree::Promotion::Action::CreateItemAdjustments",
|
159
|
+
label: "Promo",
|
160
|
+
finalized: true # Prevents this adjustment from being recalculated.
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
127
164
|
it "returns params for fetching the tax for the order" do
|
128
165
|
expect(subject).to eq(
|
129
166
|
customer_id: "12345",
|
@@ -191,14 +228,17 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
191
228
|
end
|
192
229
|
|
193
230
|
context "when the line item has zero quantity" do
|
194
|
-
let(:
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
231
|
+
let(:line_items_attributes) do
|
232
|
+
[
|
233
|
+
attributes_for(
|
234
|
+
:line_item,
|
235
|
+
additional_tax_total: 4,
|
236
|
+
price: 10,
|
237
|
+
promo_total: -2,
|
238
|
+
quantity: 0,
|
239
|
+
variant_id: variant.id
|
240
|
+
)
|
241
|
+
]
|
202
242
|
end
|
203
243
|
|
204
244
|
it "excludes the line item" do
|
@@ -216,7 +256,7 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
216
256
|
end
|
217
257
|
end
|
218
258
|
|
219
|
-
describe "
|
259
|
+
describe ".address_params" do
|
220
260
|
subject { described_class.address_params(ship_address) }
|
221
261
|
|
222
262
|
it "returns params for fetching the tax info for that address" do
|
@@ -232,7 +272,7 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
232
272
|
end
|
233
273
|
end
|
234
274
|
|
235
|
-
describe "
|
275
|
+
describe ".tax_rate_address_params" do
|
236
276
|
subject { described_class.tax_rate_address_params(ship_address) }
|
237
277
|
|
238
278
|
it "returns params for fetching the tax rate for that address" do
|
@@ -250,17 +290,32 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
250
290
|
end
|
251
291
|
end
|
252
292
|
|
253
|
-
describe "
|
293
|
+
describe ".transaction_params" do
|
254
294
|
subject { described_class.transaction_params(order) }
|
255
295
|
|
296
|
+
before do
|
297
|
+
# The discount calculator relies on the line item adjustments existing in
|
298
|
+
# order to calculate the correct discount amount for TaxJar.
|
299
|
+
create(
|
300
|
+
:adjustment,
|
301
|
+
order: order,
|
302
|
+
adjustable: order.line_items.first,
|
303
|
+
amount: line_items_attributes.first[:promo_total],
|
304
|
+
source_type: "Spree::Promotion::Action::CreateItemAdjustments",
|
305
|
+
label: "Promo",
|
306
|
+
finalized: true # Prevents this adjustment from being recalculated.
|
307
|
+
)
|
308
|
+
end
|
309
|
+
|
256
310
|
it "returns params for creating/updating an order transaction" do
|
257
311
|
expect(subject).to eq({
|
258
|
-
amount: BigDecimal("
|
312
|
+
amount: BigDecimal("100.58"),
|
259
313
|
customer_id: "12345",
|
260
314
|
line_items: [{
|
261
315
|
discount: 2,
|
262
|
-
id:
|
316
|
+
id: order.line_items.first.id,
|
263
317
|
product_identifier: "G00D-PR0DUCT",
|
318
|
+
description: "Product Name - color: red",
|
264
319
|
product_tax_code: "A_GEN_TAX",
|
265
320
|
quantity: 3,
|
266
321
|
sales_tax: 4,
|
@@ -280,6 +335,7 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
280
335
|
|
281
336
|
context "when the order is adjusted to 0" do
|
282
337
|
let(:order_total) { BigDecimal("0") }
|
338
|
+
let(:payments) { [] }
|
283
339
|
|
284
340
|
it "sends the order total as zero" do
|
285
341
|
expect(subject[:amount]).to be_zero
|
@@ -292,8 +348,9 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
292
348
|
it "sends the sales tax on the line items as zero" do
|
293
349
|
expect(subject[:line_items]).to contain_exactly({
|
294
350
|
discount: 2,
|
295
|
-
id:
|
351
|
+
id: order.line_items.first.id,
|
296
352
|
product_identifier: "G00D-PR0DUCT",
|
353
|
+
description: "Product Name - color: red",
|
297
354
|
product_tax_code: "A_GEN_TAX",
|
298
355
|
quantity: 3,
|
299
356
|
sales_tax: 0,
|
@@ -303,19 +360,22 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
303
360
|
end
|
304
361
|
|
305
362
|
context "when the line item has 0 quantity" do
|
306
|
-
let(:
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
363
|
+
let(:line_items_attributes) do
|
364
|
+
[
|
365
|
+
attributes_for(
|
366
|
+
:line_item,
|
367
|
+
additional_tax_total: 4,
|
368
|
+
price: 10,
|
369
|
+
promo_total: -2,
|
370
|
+
quantity: 0,
|
371
|
+
variant_id: variant.id
|
372
|
+
)
|
373
|
+
]
|
314
374
|
end
|
315
375
|
|
316
376
|
it "excludes the line item" do
|
317
377
|
expect(subject).to eq({
|
318
|
-
amount: BigDecimal("
|
378
|
+
amount: BigDecimal("100.58"),
|
319
379
|
customer_id: "12345",
|
320
380
|
line_items: [],
|
321
381
|
sales_tax: BigDecimal("9.87"),
|
@@ -330,6 +390,87 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
330
390
|
})
|
331
391
|
end
|
332
392
|
end
|
393
|
+
|
394
|
+
context "with an optional transaction_id specified" do
|
395
|
+
subject {
|
396
|
+
described_class.transaction_params(order, custom_transaction_id)
|
397
|
+
}
|
398
|
+
|
399
|
+
let(:custom_transaction_id) { "R0123456789" }
|
400
|
+
|
401
|
+
it "uses the specified transaction_id" do
|
402
|
+
expect(subject).to include(transaction_id: "R0123456789")
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context "when all line items have been returned and reimbursed" do
|
407
|
+
let(:reimbursement_total) { 10 }
|
408
|
+
let(:reimbursement_tax) { 1.02 }
|
409
|
+
|
410
|
+
before do
|
411
|
+
reimbursement = create(:reimbursement)
|
412
|
+
reimbursement.return_items.first.update_columns(additional_tax_total: reimbursement_tax)
|
413
|
+
refund = create(:refund, reimbursement: reimbursement, payment: order.payments.first)
|
414
|
+
reimbursement.update_columns(order_id: order.id, total: reimbursement_total + reimbursement_tax)
|
415
|
+
order.line_items.first.inventory_units.update_all(state: "returned")
|
416
|
+
end
|
417
|
+
|
418
|
+
it "excludes returned line items" do
|
419
|
+
expect(subject).to match(hash_including({ line_items: [] }))
|
420
|
+
end
|
421
|
+
|
422
|
+
it "removes the reimbursed tax from the sales tax amount" do
|
423
|
+
expect(subject[:sales_tax]).to eq(9.87 - reimbursement_tax)
|
424
|
+
end
|
425
|
+
|
426
|
+
it "removes the reimbursements without tax from the total amount" do
|
427
|
+
expect(subject[:amount]).to eq(100.58 - reimbursement_total)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
context "when some line items have been returned and reimbursed" do
|
432
|
+
let(:reimbursement_total) { 10 }
|
433
|
+
let(:reimbursement_tax) { 1.02 }
|
434
|
+
|
435
|
+
before do
|
436
|
+
reimbursement = create(:reimbursement)
|
437
|
+
reimbursement.return_items.first.update_columns(additional_tax_total: reimbursement_tax)
|
438
|
+
refund = create(:refund, reimbursement: reimbursement, payment: order.payments.first)
|
439
|
+
reimbursement.update_columns(order_id: order.id, total: reimbursement_total + reimbursement_tax)
|
440
|
+
first_inventory_unit = order.line_items.first.inventory_units.first
|
441
|
+
first_inventory_unit.update(state: "returned")
|
442
|
+
return_item = create(:return_item, amount: 34, additional_tax_total: reimbursement_tax / 4)
|
443
|
+
return_item.update_columns(inventory_unit_id: first_inventory_unit.id, reimbursement_id: reimbursement.id)
|
444
|
+
end
|
445
|
+
|
446
|
+
it "removes the reimbursed tax from the specific line item" do
|
447
|
+
expect(subject[:line_items].first[:sales_tax]).to eq(order.line_items.first.additional_tax_total - (reimbursement_tax / 4))
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
|
452
|
+
context "when a refund without a reimbursement exists" do
|
453
|
+
let(:refund_amount) { 10 }
|
454
|
+
|
455
|
+
before do
|
456
|
+
create(:refund, payment: order.payments.first, amount: refund_amount)
|
457
|
+
end
|
458
|
+
|
459
|
+
it "removes the orphaned refunds from the total amount" do
|
460
|
+
expect(subject[:amount]).to eq(100.58 - refund_amount)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
context "part of a line item has been returned" do
|
465
|
+
before do
|
466
|
+
order.line_items.first.inventory_units.first.update(state: "returned")
|
467
|
+
order.line_items.first.inventory_units.second.update(state: "canceled")
|
468
|
+
end
|
469
|
+
|
470
|
+
it "adjusts the line item quanity" do
|
471
|
+
expect(subject).to match(hash_including({ line_items: [hash_including({quantity:1})] }))
|
472
|
+
end
|
473
|
+
end
|
333
474
|
end
|
334
475
|
|
335
476
|
describe "#refund_params" do
|
@@ -352,6 +493,44 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
352
493
|
end
|
353
494
|
end
|
354
495
|
|
496
|
+
describe "#refund_transaction_params" do
|
497
|
+
subject { described_class.refund_transaction_params(order, taxjar_order) }
|
498
|
+
|
499
|
+
let(:taxjar_line_item) { {id: 1, quantity: 2, unit_price: 2.00, discount: 0.50, sales_tax: 0.80} }
|
500
|
+
let(:taxjar_order) {
|
501
|
+
Taxjar::Order.new(
|
502
|
+
transaction_id: "R111222333-1",
|
503
|
+
amount: 123.45,
|
504
|
+
sales_tax: 33.33,
|
505
|
+
shipping: 3.01,
|
506
|
+
line_items: [taxjar_line_item]
|
507
|
+
)
|
508
|
+
}
|
509
|
+
|
510
|
+
it "returns params for creating/updating a refund" do
|
511
|
+
expect(subject).to include({
|
512
|
+
amount: -123.45,
|
513
|
+
sales_tax: -33.33,
|
514
|
+
shipping: -3.01,
|
515
|
+
to_city: "Los Angeles",
|
516
|
+
to_country: "US",
|
517
|
+
to_state: "CA",
|
518
|
+
to_street: "475 N Beverly Dr",
|
519
|
+
to_zip: "90210",
|
520
|
+
transaction_date: "2018-03-06T12:10:33Z",
|
521
|
+
transaction_reference_id: "R111222333-1",
|
522
|
+
transaction_id: "R111222333-1-REFUND",
|
523
|
+
line_items: [{
|
524
|
+
id: 1,
|
525
|
+
quantity: 2,
|
526
|
+
unit_price: -2.00,
|
527
|
+
discount: -0.50,
|
528
|
+
sales_tax: -0.80
|
529
|
+
}]
|
530
|
+
})
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
355
534
|
describe "#validate_address_params" do
|
356
535
|
subject { described_class.validate_address_params(ship_address) }
|
357
536
|
|
@@ -366,26 +545,24 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
366
545
|
end
|
367
546
|
|
368
547
|
context "with an address without a state" do
|
369
|
-
let(:ship_address) do
|
370
|
-
|
548
|
+
let!(:ship_address) do
|
549
|
+
create(
|
550
|
+
:address,
|
371
551
|
address1: "72 High St",
|
552
|
+
address2: nil,
|
372
553
|
city: "Birmingham",
|
373
554
|
country: country_uk,
|
374
|
-
first_name: "Chuck",
|
375
|
-
last_name: "Schuldiner",
|
376
555
|
phone: "1-250-555-4444",
|
556
|
+
state: nil,
|
377
557
|
state_name: "West Midlands",
|
378
558
|
zipcode: "B4 7TA"
|
379
559
|
)
|
380
560
|
end
|
381
561
|
|
382
562
|
let(:country_uk) do
|
383
|
-
|
384
|
-
|
563
|
+
create(
|
564
|
+
:country,
|
385
565
|
iso: "GB",
|
386
|
-
iso_name: "UNITED KINGDOM",
|
387
|
-
name: "United Kingdom",
|
388
|
-
numcode: 826,
|
389
566
|
states_required: false
|
390
567
|
)
|
391
568
|
end
|
@@ -402,20 +579,15 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
|
|
402
579
|
end
|
403
580
|
|
404
581
|
context "an address with address2" do
|
405
|
-
let(:ship_address) do
|
406
|
-
|
582
|
+
let!(:ship_address) do
|
583
|
+
create(
|
584
|
+
:address,
|
407
585
|
address1: "1 World Trade CTR",
|
408
586
|
address2: "STE 45A",
|
409
587
|
city: "New York",
|
410
588
|
country: country_us,
|
411
|
-
first_name: "Chuck",
|
412
|
-
last_name: "Schuldiner",
|
413
589
|
phone: "1-250-555-4444",
|
414
|
-
|
415
|
-
abbr: "NY",
|
416
|
-
country: country_us,
|
417
|
-
name: "New York"
|
418
|
-
),
|
590
|
+
state_code: "NY",
|
419
591
|
zipcode: "10007"
|
420
592
|
)
|
421
593
|
end
|