Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Gather tax identifier validation under one namespace
Łukasz Adamczyk93102dabf05d
diff --git a/docs/plans/6.0-tax-provider.md b/docs/plans/6.0-tax-provider.mdindex 179cd4e025..c887670909 100644--- a/docs/plans/6.0-tax-provider.md+++ b/docs/plans/6.0-tax-provider.md@@ -255,23 +255,23 @@ end```ruby# Extensions register the kinds they cover; a tax provider gem may register# itself for the kinds its service can check.- Spree.tax_id_validators['eu_vat'] = 'SpreeEuVat::TaxIdValidator'+ Spree.tax_identifier_validators['eu_vat'] = 'SpreeEuVat::TaxIdentifierValidator'- # Each validator subclasses Spree::TaxIdValidator::Base: a class-level+ # Each validator subclasses Spree::TaxIdentifiers::Validator::Base: a class-level# valid_format? for the synchronous check, and call(tax_identifier:) →# ValidationResult for the registry call. The row carries kind, value and its# owner, so a credentialed validator reaches the store's Integration through# the owner — no extra arguments.```- Lookup is deterministic from the row itself, two extensions covering different kinds coexist (a single swappable service would give the second one to load the slot and silently disable the first), and core can answer "can this installation validate this kind?" with `Spree.tax_id_validators.key?(kind)` — which is what the admin needs to distinguish *queued*, *no validator installed* and *checked and not registered*.+ Lookup is deterministic from the row itself, two extensions covering different kinds coexist (a single swappable service would give the second one to load the slot and silently disable the first), and core can answer "can this installation validate this kind?" with `Spree.tax_identifier_validators.key?(kind)` — which is what the admin needs to distinguish *queued*, *no validator installed* and *checked and not registered*.**When it runs:** after the identifier is saved, in a background job — following the address-geocoding precedent (`Spree::Address#async_geocode` → `Spree::Addresses::GeocodeAddressJob`), which solves the same problem of enriching a row from an external lookup:```TaxIdentifier saved (after_commit, only when kind/value actually changed)→ Spree::TaxIdentifiers::ValidateJob- → Spree.tax_id_validators[kind] → ValidationResult+ → Spree.tax_identifier_validators[kind] → ValidationResult→ Spree::TaxIdentifiers::Validate writes status / validated_at /evidence / normalized value with update_columns```@@ -293,7 +293,7 @@ end# outcome from an external service (outcome + human-readable message + raw# payload) — built as an ActiveModel value object per# Spree::PickupPointOption. Never persisted, never a Struct.- class Spree::TaxIdentifier::ValidationResult+ class Spree::TaxIdentifiers::ValidationResultinclude ActiveModel::Modelinclude ActiveModel::Attributes@@ -568,7 +568,7 @@ module Spreeend```-Two methods are deliberately absent. There is no `exempt?` — exemption enters through `estimate`'s `exemptions:` and leaves as a reason on the written rows. And there is no `validate_tax_id` — validating a registration number is keyed to the number's kind, not to a market's tax engine, so it lives in `Spree.tax_id_validators` (see "Buyer tax identity"). A provider gem may register itself there for the kinds its service can check.+Two methods are deliberately absent. There is no `exempt?` — exemption enters through `estimate`'s `exemptions:` and leaves as a reason on the written rows. And there is no `validate_tax_id` — validating a registration number is keyed to the number's kind, not to a market's tax engine, so it lives in `Spree.tax_identifier_validators` (see "Buyer tax identity"). A provider gem may register itself there for the kinds its service can check.### Estimate flow (the single totals seam)@@ -649,17 +649,18 @@ The registry is engine config holding **class names**, constantized at call time```ruby# config/initializers/spree.rb in an app, or the extension's engine-Spree.tax_id_validators['eu_vat'] = 'SpreeEuVat::TaxIdValidator'-Spree.tax_id_validators['gb_vat'] = 'SpreeUkVat::TaxIdValidator'+Spree.tax_identifier_validators['eu_vat'] = 'SpreeEuVat::TaxIdentifierValidator'+Spree.tax_identifier_validators['gb_vat'] = 'SpreeUkVat::TaxIdentifierValidator'```**The contract** — a `Base` like every other pluggable seam, so the defaults live in one place and core never has to `respond_to?`-check. A validator is a provider, not an internal service: a plain class returning a value object, same as `Spree::TaxProvider::Base`.```ruby-# app/models/spree/tax_id_validator/base.rb+# app/models/spree/tax_identifiers/validator/base.rbmodule Spree- module TaxIdValidator- class Base+ module TaxIdentifiers+ module Validator+ class Base# Synchronous, offline, no network — used by the model's format validation# at entry time. Class-level and cheap, the same shape as# Spree::SearchProvider::Base.indexing_required?, which core calls as@@ -679,9 +680,10 @@ module Spree# @param tax_identifier [Spree::TaxIdentifier] carries kind, value and its# owner — reach the store through the owner when the registry needs# credentials (owner.store.integrations…)- # @return [Spree::TaxIdentifier::ValidationResult]- def call(tax_identifier:)- raise NotImplementedError, "Please implement 'call' in your tax ID validator: #{self.class.name}"+ # @return [Spree::TaxIdentifiers::ValidationResult]+ def call(tax_identifier:)+ raise NotImplementedError, "Please implement 'call' in your tax ID validator: #{self.class.name}"+ endendendend@@ -691,9 +693,9 @@ end**What an implementer writes** — both halves of Stripe's split in one class: the offline format check, and the registry call:```ruby-# the extension's app/models/spree_eu_vat/tax_id_validator.rb+# the extension's app/models/spree_eu_vat/tax_identifier_validator.rbmodule SpreeEuVat- class TaxIdValidator < Spree::TaxIdValidator::Base+ class TaxIdentifierValidator < Spree::TaxIdentifiers::Validator::Base# 27 member states, each with its own length and letter positions — the# jurisdiction knowledge core deliberately does not carry.PATTERNS = { 'DE' => /\ADE\d{9}\z/, 'FR' => /\AFR\w{2}\d{9}\z/, … }.freeze@@ -705,7 +707,7 @@ module SpreeEuVatdef call(tax_identifier:)response = client.check(tax_identifier.value) # country comes from the prefix- Spree::TaxIdentifier::ValidationResult.new(+ Spree::TaxIdentifiers::ValidationResult.new(status: response.registered? ? 'verified' : 'unverified',normalized_value: response.normalized_value,message: response.message,@@ -719,7 +721,7 @@ module SpreeEuVat})rescue SpreeEuVat::RegistryUnavailable => error- Spree::TaxIdentifier::ValidationResult.new(+ Spree::TaxIdentifiers::ValidationResult.new(status: 'unavailable', message: error.message, checked_at: Time.current)end@@ -758,7 +760,7 @@ class Spree::TaxIdentifier < Spree.base_class# business customer rather than catching a typo. Kinds with no validator are# accepted as entered.def value_format- validator = Spree.tax_id_validators[kind]+ validator = Spree.tax_identifier_validators[kind]return if validator.blank?return if validator.to_s.constantize.valid_format?(value)@@ -788,7 +790,7 @@ class Spree::TaxIdentifier < Spree.base_class# validators, so it never enqueues a job that could only write a column.def should_validate?order_id.nil? &&- Spree.tax_id_validators.key?(kind) &&+ Spree.tax_identifier_validators.key?(kind) &&(saved_changes.key?('value') || saved_changes.key?('kind'))endend@@ -796,7 +798,7 @@ endOne mechanism covers every entry point — customer profile, cart override, admin, console, seeds — because they all end in a saved row. The callback only enqueues; the external call is the job's.-Because of the registry guard, `validation_status` stays **nil** on an installation with no validator for that kind, and the admin tells the two nil cases apart by asking the registry: `Spree.tax_id_validators.key?(kind)` false means "this installation cannot check this kind", true means "queued, or not yet attempted". That is the discoverability the registry was chosen for. The stored `unsupported` therefore covers only the narrow race where a validator is deregistered between enqueue and run.+Because of the registry guard, `validation_status` stays **nil** on an installation with no validator for that kind, and the admin tells the two nil cases apart by asking the registry: `Spree.tax_identifier_validators.key?(kind)` false means "this installation cannot check this kind", true means "queued, or not yet attempted". That is the discoverability the registry was chosen for. The stored `unsupported` therefore covers only the narrow race where a validator is deregistered between enqueue and run.```ruby# app/jobs/spree/tax_identifiers/validate_job.rb@@ -827,7 +829,7 @@ module Spreeprepend Spree::ServiceModule::Basedef call(tax_identifier:)- validator = Spree.tax_id_validators[tax_identifier.kind]+ validator = Spree.tax_identifier_validators[tax_identifier.kind]return persist(tax_identifier, unsupported_result) if validator.blank?persist(tax_identifier, validator.to_s.constantize.new.call(tax_identifier: tax_identifier))@@ -939,7 +941,7 @@ module SpreeTaxAvalara# Validation is not part of the provider contract — the gem registers a# validator for the kinds Avalara can check:- # Spree.tax_id_validators['eu_vat'] = 'SpreeTaxAvalara::TaxIdValidator'+ # Spree.tax_identifier_validators['eu_vat'] = 'SpreeTaxAvalara::TaxIdentifierValidator'private@@ -976,7 +978,7 @@ Conventions per `6.0-admin-api.md`: flat params, prefixed IDs, secret-key scopesSerializer split. The **store** side exposes `id`, `kind` and `value` — nothing else. All validation state is admin-only, because none of it is customer-actionable: at entry only the format check has run (a bad format is a 422 with a field error, which is the feedback that matters), and a verdict arriving later changes nothing for the buyer, since the treatment follows the number's format rather than its verdict. Exposing the status would mainly invite storefronts to build polling UX around a field we deliberately made non-blocking. Stripe draws the same line — its `verification` hash is a secret-key resource, absent from the client-side Checkout payload.-The **admin** side adds `validation_status`, `validated_at`, `validation_evidence`, `source`, timestamps, and a computed **`validatable`** boolean. That flag is admin-only on purpose: it answers "can this installation check this kind at all", which is a fact about the merchant's configuration rather than about the customer's number. It has to exist because the registry lookup core relies on (`Spree.tax_id_validators.key?(kind)`) has no HTTP equivalent — without it the dashboard cannot tell "no validator installed for this kind" from "queued, or not yet attempted", and the discoverability argument that chose a keyed registry over a single swappable service would stop at the API boundary.+The **admin** side adds `validation_status`, `validated_at`, `validation_evidence`, `source`, timestamps, and a computed **`validatable`** boolean. That flag is admin-only on purpose: it answers "can this installation check this kind at all", which is a fact about the merchant's configuration rather than about the customer's number. It has to exist because the registry lookup core relies on (`Spree.tax_identifier_validators.key?(kind)`) has no HTTP equivalent — without it the dashboard cannot tell "no validator installed for this kind" from "queued, or not yet attempted", and the discoverability argument that chose a keyed registry over a single swappable service would stop at the API boundary.**Tax lines.** The store serializer already exists (`label`, `rate`, `included`, `amount`) but no store endpoint consumes it — only `/admin/orders/:id/tax_lines`. Two changes:@@ -1020,7 +1022,7 @@ Shipped with the core-rewrite waves, not as originally phased: no "Internal dele- API: `/admin/tax_rates` CRUD (without it the Internal provider cannot be configured or verified through the API — see the API surface section), tax identifier endpoints (with admin `validatable` + the re-validate action), tax lines exposed on the Store API, admin tax-line serializer gaining `taxability_reason`/jurisdiction/`data`, and the Ransack allowlist for tax reporting.- `estimate` signature: `tax_date:`/`tax_identifier:`/`exemptions:`/`context:`; `refund(order, return_items, tax_date:)` replaces `refund(owner, amount)`; `exempt?` removed.- `Spree::TaxExemption` + `ItemOverride` value objects; `tax_resolve_exemptions_service` dependency (default empty); `#resolved_tax_identifier` on `Spree::Purchase::Taxation`.-- `Spree::TaxIdValidator::Base` + `Spree.tax_id_validators` registry (empty by default, class names) + `Spree::TaxIdentifiers::Validate` (sole writer of the validation columns) + `ValidateJob` + `Spree.queues.tax_identifiers` + the `after_commit` enqueue guarded on kind/value changes.+- `Spree::TaxIdentifiers::Validator::Base` + `Spree.tax_identifier_validators` registry (empty by default, class names) + `Spree::TaxIdentifiers::Validate` (sole writer of the validation columns) + `ValidateJob` + `Spree.queues.tax_identifiers` + the `after_commit` enqueue guarded on kind/value changes.- Synchronous format validation on `TaxIdentifier`: whitespace/case normalization, presence, and the registered validator's class-level `valid_format?` (no format rules in core). Hard validation — a number a validator rejects never persists.- Capability declarations + Internal's unsupported list.- **Store binding** (the 2026-07-29 note above): `store_id` on `spree_tax_rates` and `spree_tax_categories` via `Spree::SingleStoreResource`, a backfill rake task, and store-scoped fetching in the endpoints above; `null: false` waits for 6.1 once the backfill has run everywhere. `TaxIdentifier`, `TaxLine` and the other typed rows deliberately get **no** `store_id` — they are owned rows whose owner already carries the store, matching `spree_tax_lines` as shipped; a denormalized copy would only be a second thing to keep in sync.@@ -1173,7 +1175,7 @@ manifest, so every install arriving at 6.1 has run them.- **Don't put typed tax inputs in `set_tax_line_context`.** Exemptions, tax identifiers and dates are named `estimate` parameters, assembled by `tax_resolve_exemptions_service` and `#resolved_tax_identifier`; the hook carries untyped provider extras only.- **No exemption flags on customer, order or line items.** The claim is an ephemeral `Spree::TaxExemption`; the outcome is TaxLines with reasons. Don't add ad-hoc exemption checks in controllers or services — swap `tax_resolve_exemptions_service`.- **Order-owned TaxIdentifier rows are immutable.** No correction path; don't add one. Don't read customer tax data live for anything post-completion — use the order snapshot.-- **Don't validate a tax ID from the tax provider, and don't validate during estimate.** Register a validator for the kind in `Spree.tax_id_validators`; the estimate path reads the stored result. No registry client (for any jurisdiction) belongs in core.+- **Don't validate a tax ID from the tax provider, and don't validate during estimate.** Register a validator for the kind in `Spree.tax_identifier_validators`; the estimate path reads the stored result. No registry client (for any jurisdiction) belongs in core.- **Don't make a registry call block a save or a checkout, and don't gate the tax treatment on a verdict.** Format is checked synchronously and offline; the registry answer is asynchronous and advisory. Reverse charge follows the number's format, so a `pending` identifier still prices correctly. Making it synchronous imports the registry's downtime into checkout — see the rejected Magento model.- **Don't add tax-related global configuration beyond `Spree::Config[:tax_using_ship_address]`** (the sourcing default). Provider-specific config belongs on the Integration.- **TaxCategory stays as the product-level tax classification** — external providers use it as the tax-code mapping (e.g. TaxCategory "Clothing" → Avalara `PC040100`). Product taxability never flows through the exemption input.diff --git a/docs/plans/decisions.md b/docs/plans/decisions.mdindex 4c2ef27193..26520b4d98 100644--- a/docs/plans/decisions.md+++ b/docs/plans/decisions.md@@ -386,7 +386,7 @@ saves a tax ID on a profile before any order exists, so a provider-hung`validate_tax_id` would force an arbitrary choice (a US sales-tax engineasked to check an EU number, or an EU market on Internal declining whilea connected Avalara sits unused). The seam is therefore-`Spree.tax_id_validators`, a registry keyed by kind and empty by default —+`Spree.tax_identifier_validators`, a registry keyed by kind and empty by default —core ships no registry client for any jurisdiction — so two extensionscovering different kinds coexist where a single swappable service wouldlet the second loaded silently disable the first. Validation splits the way Stripe's does: **formatdiff --git a/spree/api/spec/controllers/spree/api/v3/admin/customers/tax_identifiers_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/customers/tax_identifiers_controller_spec.rbindex 84ec430299..4a12c181d0 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/customers/tax_identifiers_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/customers/tax_identifiers_controller_spec.rb@@ -70,10 +70,10 @@ RSpec.describe Spree::Api::V3::Admin::Customers::TaxIdentifiersController, type:describe 'POST #validate' docontext 'when a validator is registered for the kind' doaround do |example|- Spree.tax_id_validators['eu_vat'] = 'Spree::TaxIdValidator::Base'+ Spree.tax_identifier_validators['eu_vat'] = 'Spree::TaxIdentifiers::Validator::Base'example.runensure- Spree.tax_id_validators.delete('eu_vat')+ Spree.tax_identifier_validators.delete('eu_vat')endit 'queues a fresh registry check' dodiff --git a/spree/api/spec/requests/spree/api/v3/store/tax_identifiers_spec.rb b/spree/api/spec/requests/spree/api/v3/store/tax_identifiers_spec.rbindex 3ef11dd3fd..4f56493571 100644--- a/spree/api/spec/requests/spree/api/v3/store/tax_identifiers_spec.rb+++ b/spree/api/spec/requests/spree/api/v3/store/tax_identifiers_spec.rb@@ -47,12 +47,12 @@ RSpec.describe 'Store tax identifiers', type: :request doendit 'rejects a malformed number when this installation can check the kind' do- stub_const('SpecStoreValidator', Class.new(Spree::TaxIdValidator::Base) do+ stub_const('SpecStoreValidator', Class.new(Spree::TaxIdentifiers::Validator::Base) dodef self.valid_format?(value)value.start_with?('DE')endend)- Spree.tax_id_validators['eu_vat'] = 'SpecStoreValidator'+ Spree.tax_identifier_validators['eu_vat'] = 'SpecStoreValidator'put "/api/v3/store/carts/#{cart.prefixed_id}/tax_identifier",params: { kind: 'eu_vat', value: '123' },@@ -60,7 +60,7 @@ RSpec.describe 'Store tax identifiers', type: :request doexpect(response).to have_http_status(:unprocessable_content)ensure- Spree.tax_id_validators.delete('eu_vat')+ Spree.tax_identifier_validators.delete('eu_vat')endenddiff --git a/spree/core/app/models/spree/tax_id_validator/base.rb b/spree/core/app/models/spree/tax_id_validator/base.rbdeleted file mode 100644index 946cf3fdfd..0000000000--- a/spree/core/app/models/spree/tax_id_validator/base.rb+++ /dev/null@@ -1,40 +0,0 @@-module Spree- module TaxIdValidator- # Contract for checking a buyer's tax registration. Registered per kind in- # {Spree.tax_id_validators}, because whether a number is well-formed and- # whether it is really registered are questions for the jurisdiction that- # issued it — not for the market's tax engine.- #- # Two halves, deliberately split by cost: the format check is synchronous,- # offline and cheap enough to run on every save; the registry check makes a- # network call and runs in a job.- class Base- # Whether the value looks like a number of this kind. Called on save, so- # it must not touch the network.- #- # Permissive by default: a validator that only knows how to talk to a- # registry accepts anything core allowed through.- #- # @param value [String] already normalized (whitespace stripped, upcased)- # @return [Boolean]- def self.valid_format?(_value)- true- end-- # Asks the registry whether the number is registered. Runs in- # {Spree::TaxIdentifiers::ValidateJob}.- #- # A registry that cannot answer must return an +unavailable+ result rather- # than raise: the number stays usable and the platform records that nobody- # could answer.- #- # @param tax_identifier [Spree::TaxIdentifier] carries the kind, the value- # and its owner — reach the store through the owner when the registry- # needs credentials- # @return [Spree::TaxIdentifier::ValidationResult]- def call(tax_identifier:)- raise NotImplementedError, "Please implement 'call' in your tax ID validator: #{self.class.name}"- end- end- end-enddiff --git a/spree/core/app/models/spree/tax_identifier.rb b/spree/core/app/models/spree/tax_identifier.rbindex 776cba4055..a312b5d3fc 100644--- a/spree/core/app/models/spree/tax_identifier.rb+++ b/spree/core/app/models/spree/tax_identifier.rb@@ -17,7 +17,7 @@ module Spree# and core ships neither.## It does have to match the key that validator is registered under in- # {Spree.tax_id_validators}, because that lookup is by exact string. A kind+ # {Spree.tax_identifier_validators}, because that lookup is by exact string. A kind# nothing is registered for is stored and used as entered — never# format-checked, never sent to a registry — and {#validatable?} reports as# much. So a misspelled kind fails silently rather than loudly.@@ -93,7 +93,7 @@ module Spree## @return [Boolean]def validatable?- order_id.nil? && Spree.tax_id_validators.key?(kind)+ order_id.nil? && Spree.tax_identifier_validators.key?(kind)endprivate@@ -113,7 +113,7 @@ module Spree# and its failure mode is turning away a real business customer. Kinds with# no validator are accepted as entered.def value_format- validator = Spree.tax_id_validators[kind]+ validator = Spree.tax_identifier_validators[kind]return if validator.blank?return if validator.to_s.constantize.valid_format?(value)diff --git a/spree/core/app/models/spree/tax_identifier/validation_result.rb b/spree/core/app/models/spree/tax_identifiers/validation_result.rbsimilarity index 98%rename from spree/core/app/models/spree/tax_identifier/validation_result.rbrename to spree/core/app/models/spree/tax_identifiers/validation_result.rbindex 1d96eed523..8d7af78ab7 100644--- a/spree/core/app/models/spree/tax_identifier/validation_result.rb+++ b/spree/core/app/models/spree/tax_identifiers/validation_result.rb@@ -1,5 +1,5 @@module Spree- class TaxIdentifier+ module TaxIdentifiers# What a validator reports back about a registration. Ephemeral: the# validation service is what writes it onto the row.class ValidationResultdiff --git a/spree/core/app/models/spree/tax_identifiers/validator/base.rb b/spree/core/app/models/spree/tax_identifiers/validator/base.rbnew file mode 100644index 0000000000..f7792391c5--- /dev/null+++ b/spree/core/app/models/spree/tax_identifiers/validator/base.rb@@ -0,0 +1,42 @@+module Spree+ module TaxIdentifiers+ module Validator+ # Contract for checking a buyer's tax registration. Registered per kind in+ # {Spree.tax_identifier_validators}, because whether a number is+ # well-formed and whether it is really registered are questions for the+ # jurisdiction that issued it — not for the market's tax engine.+ #+ # Two halves, deliberately split by cost: the format check is synchronous,+ # offline and cheap enough to run on every save; the registry check makes+ # a network call and runs in a job.+ class Base+ # Whether the value looks like a number of this kind. Called on save, so+ # it must not touch the network.+ #+ # Permissive by default: a validator that only knows how to talk to a+ # registry accepts anything core allowed through.+ #+ # @param value [String] already normalized (whitespace stripped, upcased)+ # @return [Boolean]+ def self.valid_format?(_value)+ true+ end++ # Asks the registry whether the number is registered. Runs in+ # {Spree::TaxIdentifiers::ValidateJob}.+ #+ # A registry that cannot answer must return an +unavailable+ result+ # rather than raise: the number stays usable and the platform records+ # that nobody could answer.+ #+ # @param tax_identifier [Spree::TaxIdentifier] carries the kind, the+ # value and its owner — reach the store through the owner when the+ # registry needs credentials+ # @return [Spree::TaxIdentifiers::ValidationResult]+ def call(tax_identifier:)+ raise NotImplementedError, "Please implement 'call' in your tax ID validator: #{self.class.name}"+ end+ end+ end+ end+enddiff --git a/spree/core/app/services/spree/tax_identifiers/validate.rb b/spree/core/app/services/spree/tax_identifiers/validate.rbindex 31f9ef3916..235d5fa14e 100644--- a/spree/core/app/services/spree/tax_identifiers/validate.rb+++ b/spree/core/app/services/spree/tax_identifiers/validate.rb@@ -10,7 +10,7 @@ module Spree# @param tax_identifier [Spree::TaxIdentifier]# @return [Spree::TaxIdentifier]def call(tax_identifier:)- validator = Spree.tax_id_validators[tax_identifier.kind]+ validator = Spree.tax_identifier_validators[tax_identifier.kind]# Narrow race: the validator was deregistered between enqueue and run.return persist(tax_identifier, unsupported_result) if validator.blank?@@ -42,11 +42,11 @@ module Spreeenddef unsupported_result- Spree::TaxIdentifier::ValidationResult.new(status: 'unsupported', checked_at: Time.current)+ Spree::TaxIdentifiers::ValidationResult.new(status: 'unsupported', checked_at: Time.current)enddef unavailable_result(message)- Spree::TaxIdentifier::ValidationResult.new(status: 'unavailable', message: message, checked_at: Time.current)+ Spree::TaxIdentifiers::ValidationResult.new(status: 'unavailable', message: message, checked_at: Time.current)endendenddiff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rbindex eef249694f..21a43f0bdd 100644--- a/spree/core/lib/spree/core.rb+++ b/spree/core/lib/spree/core.rb@@ -156,7 +156,7 @@ module Spree# no registry client, because VAT number rules live in 27 different statute# books and a guess would reject real business customers.#- # Spree.tax_id_validators['eu_vat'] = 'SpreeEuVat::TaxIdValidator'+ # Spree.tax_identifier_validators['eu_vat'] = 'SpreeEuVat::TaxIdentifierValidator'## Class names are stored as strings and constantized at call time, so an# initializer can register a validator before its class is autoloaded.@@ -164,8 +164,8 @@ module Spree# reasons a registration has no verdict: unchecked, or uncheckable here.## @return [Hash{String => String}]- def self.tax_id_validators- @@tax_id_validators ||= {}+ def self.tax_identifier_validators+ @@tax_identifier_validators ||= {}end# Returns the events adapter class used for publishing and subscribing to events.diff --git a/spree/core/spec/jobs/spree/tax_identifiers/validate_job_spec.rb b/spree/core/spec/jobs/spree/tax_identifiers/validate_job_spec.rbindex 182493e675..1c14cf3ec2 100644--- a/spree/core/spec/jobs/spree/tax_identifiers/validate_job_spec.rb+++ b/spree/core/spec/jobs/spree/tax_identifiers/validate_job_spec.rb@@ -5,15 +5,15 @@ describe Spree::TaxIdentifiers::ValidateJob dolet(:tax_identifier) { create(:tax_identifier, customer: customer, kind: 'eu_vat') }before do- stub_const('SpecJobValidator', Class.new(Spree::TaxIdValidator::Base) do+ stub_const('SpecJobValidator', Class.new(Spree::TaxIdentifiers::Validator::Base) dodef call(tax_identifier:)- Spree::TaxIdentifier::ValidationResult.new(status: 'verified', checked_at: Time.current)+ Spree::TaxIdentifiers::ValidationResult.new(status: 'verified', checked_at: Time.current)endend)- Spree.tax_id_validators['eu_vat'] = 'SpecJobValidator'+ Spree.tax_identifier_validators['eu_vat'] = 'SpecJobValidator'end- after { Spree.tax_id_validators.delete('eu_vat') }+ after { Spree.tax_identifier_validators.delete('eu_vat') }it 'records the registry verdict on the row' dodescribed_class.perform_now(tax_identifier.id)diff --git a/spree/core/spec/models/spree/tax_identifier_spec.rb b/spree/core/spec/models/spree/tax_identifier_spec.rbindex 022caf072d..21f7d5bbf6 100644--- a/spree/core/spec/models/spree/tax_identifier_spec.rb+++ b/spree/core/spec/models/spree/tax_identifier_spec.rb@@ -57,7 +57,7 @@ describe Spree::TaxIdentifier, type: :model dodescribe 'format validation' dolet(:validator) do- Class.new(Spree::TaxIdValidator::Base) do+ Class.new(Spree::TaxIdentifiers::Validator::Base) dodef self.valid_format?(value)value.start_with?('DE')end@@ -67,10 +67,10 @@ describe Spree::TaxIdentifier, type: :model dobefore { stub_const('SpecEuVatValidator', validator) }around do |example|- Spree.tax_id_validators['eu_vat'] = 'SpecEuVatValidator'+ Spree.tax_identifier_validators['eu_vat'] = 'SpecEuVatValidator'example.runensure- Spree.tax_id_validators.delete('eu_vat')+ Spree.tax_identifier_validators.delete('eu_vat')endit 'rejects a malformed number as a typo to fix' do@@ -91,10 +91,10 @@ describe Spree::TaxIdentifier, type: :model dodescribe 'the registry check' doaround do |example|- Spree.tax_id_validators['eu_vat'] = 'Spree::TaxIdValidator::Base'+ Spree.tax_identifier_validators['eu_vat'] = 'Spree::TaxIdentifiers::Validator::Base'example.runensure- Spree.tax_id_validators.delete('eu_vat')+ Spree.tax_identifier_validators.delete('eu_vat')endit 'is queued when a checkable number is entered, and marked pending' do@@ -137,10 +137,10 @@ describe Spree::TaxIdentifier, type: :model doidentifier = create(:tax_identifier, customer: customer, kind: 'eu_vat')expect(identifier).not_to be_validatable- Spree.tax_id_validators['eu_vat'] = 'Spree::TaxIdValidator::Base'+ Spree.tax_identifier_validators['eu_vat'] = 'Spree::TaxIdentifiers::Validator::Base'expect(identifier).to be_validatableensure- Spree.tax_id_validators.delete('eu_vat')+ Spree.tax_identifier_validators.delete('eu_vat')endendenddiff --git a/spree/core/spec/services/spree/tax_identifiers/validate_spec.rb b/spree/core/spec/services/spree/tax_identifiers/validate_spec.rbindex 78c2ede119..6814276ec3 100644--- a/spree/core/spec/services/spree/tax_identifiers/validate_spec.rb+++ b/spree/core/spec/services/spree/tax_identifiers/validate_spec.rb@@ -6,16 +6,16 @@ describe Spree::TaxIdentifiers::Validate dodef register(validator_class)stub_const('SpecRegistryValidator', validator_class)- Spree.tax_id_validators['eu_vat'] = 'SpecRegistryValidator'+ Spree.tax_identifier_validators['eu_vat'] = 'SpecRegistryValidator'end- after { Spree.tax_id_validators.delete('eu_vat') }+ after { Spree.tax_identifier_validators.delete('eu_vat') }context 'when the registry answers' dobefore do- register(Class.new(Spree::TaxIdValidator::Base) do+ register(Class.new(Spree::TaxIdentifiers::Validator::Base) dodef call(tax_identifier:)- Spree::TaxIdentifier::ValidationResult.new(+ Spree::TaxIdentifiers::ValidationResult.new(status: 'verified',normalized_value: tax_identifier.value,checked_at: Time.current,@@ -53,9 +53,9 @@ describe Spree::TaxIdentifiers::Validate docontext 'when the registry cannot answer' dobefore do- register(Class.new(Spree::TaxIdValidator::Base) do+ register(Class.new(Spree::TaxIdentifiers::Validator::Base) dodef call(tax_identifier:)- Spree::TaxIdentifier::ValidationResult.new(status: 'unavailable', message: 'VIES timed out',+ Spree::TaxIdentifiers::ValidationResult.new(status: 'unavailable', message: 'VIES timed out',checked_at: Time.current)endend)@@ -80,7 +80,7 @@ describe Spree::TaxIdentifiers::Validate docontext 'when the validator raises' dobefore do- register(Class.new(Spree::TaxIdValidator::Base) do+ register(Class.new(Spree::TaxIdentifiers::Validator::Base) dodef call(tax_identifier:)raise 'boom'end