| 1 |
<?php |
| 2 |
/** |
| 3 |
* Tax ID Settings. |
| 4 |
* |
| 5 |
* Centralises the Tax-ID-related settings: per-type write-map overrides plus |
| 6 |
* the capture/display toggles surfaced in the admin SPA. Values come from |
| 7 |
* WCPOS settings (the top-level `tax_ids` section, allowing the existing |
| 8 |
* settings service to handle persistence) and fall back to sensible defaults. |
| 9 |
* |
| 10 |
* @package WCPOS\WooCommercePOS |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace WCPOS\WooCommercePOS\Services; |
| 14 |
|
| 15 |
use WCPOS\WooCommercePOS\Services\Settings; |
| 16 |
|
| 17 |
/** |
| 18 |
* Tax_Id_Settings class. |
| 19 |
*/ |
| 20 |
class Tax_Id_Settings { |
| 21 |
/** |
| 22 |
* Default per-type → meta-key write map. |
| 23 |
* |
| 24 |
* `_billing_vat_number` is the WC EU VAT Number current key and is read |
| 25 |
* out-of-the-box by most VAT-aware plugins, so we use it as the catch-all |
| 26 |
* for VAT-shaped types when no plugin and no override are present. |
| 27 |
* |
| 28 |
* @return array<string,string> |
| 29 |
*/ |
| 30 |
public static function default_write_map(): array { |
| 31 |
return array( |
| 32 |
Tax_Id_Types::TYPE_EU_VAT => '_billing_vat_number', |
| 33 |
Tax_Id_Types::TYPE_GB_VAT => '_billing_vat_number', |
| 34 |
Tax_Id_Types::TYPE_SA_VAT => '_billing_vat_number', |
| 35 |
Tax_Id_Types::TYPE_AU_ABN => '_billing_vat_number', |
| 36 |
Tax_Id_Types::TYPE_CA_GST_HST => '_billing_vat_number', |
| 37 |
Tax_Id_Types::TYPE_US_EIN => '_billing_vat_number', |
| 38 |
Tax_Id_Types::TYPE_OTHER => '_billing_vat_number', |
| 39 |
Tax_Id_Types::TYPE_BR_CPF => '_billing_cpf', |
| 40 |
Tax_Id_Types::TYPE_BR_CNPJ => '_billing_cnpj', |
| 41 |
Tax_Id_Types::TYPE_IN_GST => '_billing_gstin', |
| 42 |
Tax_Id_Types::TYPE_IT_CF => '_billing_cf', |
| 43 |
Tax_Id_Types::TYPE_IT_PIVA => '_billing_piva', |
| 44 |
Tax_Id_Types::TYPE_ES_NIF => '_billing_nif', |
| 45 |
Tax_Id_Types::TYPE_AR_CUIT => '_billing_cuit', |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* User-configured per-type overrides for the write map. |
| 51 |
* |
| 52 |
* Reads from the `tax_ids.write_map` settings tree, including the legacy |
| 53 |
* `general.tax_ids.write_map` fallback provided by Settings. Invalid types |
| 54 |
* or empty keys are silently dropped. |
| 55 |
* |
| 56 |
* @return array<string,string> |
| 57 |
*/ |
| 58 |
public static function get_overrides(): array { |
| 59 |
$raw = Settings::instance()->tax_id_write_map(); |
| 60 |
|
| 61 |
$out = array(); |
| 62 |
foreach ( $raw as $type => $meta_key ) { |
| 63 |
if ( ! \is_string( $type ) || ! Tax_Id_Types::is_valid_type( $type ) ) { |
| 64 |
continue; |
| 65 |
} |
| 66 |
if ( ! \is_string( $meta_key ) || '' === $meta_key ) { |
| 67 |
continue; |
| 68 |
} |
| 69 |
$out[ $type ] = $meta_key; |
| 70 |
} |
| 71 |
|
| 72 |
return $out; |
| 73 |
} |
| 74 |
} |
| 75 |
|