| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\Renderer; |
| 4 |
|
| 5 |
|
| 6 |
use FluentCart\Api\StoreSettings; |
| 7 |
use FluentCart\Framework\Support\Arr; |
| 8 |
use FluentCart\App\Modules\Tax\TaxModule; |
| 9 |
use FluentCart\App\Services\Localization\LocalizationManager; |
| 10 |
|
| 11 |
class EUVatRenderer |
| 12 |
{ |
| 13 |
protected $isEUCountry = false; |
| 14 |
protected $taxSettings = []; |
| 15 |
protected $taxApplicableCountry = ''; |
| 16 |
|
| 17 |
public function __construct($isEUCountry = false, $taxApplicableCountry = '') |
| 18 |
{ |
| 19 |
$this->taxSettings = (new TaxModule())->getSettings(); |
| 20 |
$this->isEUCountry = $isEUCountry; |
| 21 |
$this->taxApplicableCountry = $taxApplicableCountry; |
| 22 |
} |
| 23 |
|
| 24 |
public function render($cart) |
| 25 |
{ |
| 26 |
$euVatEnabled = Arr::get($this->taxSettings, 'eu_vat_settings.require_vat_number', 'no'); |
| 27 |
|
| 28 |
if ($this->isEUCountry && $euVatEnabled === 'yes') { |
| 29 |
$vatNumber = Arr::get($cart->checkout_data, 'tax_data.vat_number', ''); |
| 30 |
?> |
| 31 |
<div class="fct_checkout_form_section" role="region" aria-labelledby="eu-vat-heading"> |
| 32 |
<div class="fct_form_section_header"> |
| 33 |
<h4 id="eu-vat-heading" class="fct_form_section_header_label"> |
| 34 |
<?php echo esc_html__('EU VAT', 'fluent-cart'); ?> |
| 35 |
</h4> |
| 36 |
</div> |
| 37 |
<div class="fct_form_section_body"> |
| 38 |
<div class="fct_tax_field"> |
| 39 |
<div data-fluent-cart-checkout-page-form-input-wrapper class="fct_tax_input_wrapper" |
| 40 |
id="fct_billing_tax_id_wrapper" |
| 41 |
> |
| 42 |
<label for="fct_billing_tax_id" class="sr-only"> |
| 43 |
<?php echo esc_html__('VAT Number', 'fluent-cart'); ?> |
| 44 |
</label> |
| 45 |
|
| 46 |
<input |
| 47 |
data-fluent-cart-checkout-page-tax-id |
| 48 |
type="text" |
| 49 |
name="fct_billing_tax_id" |
| 50 |
autocomplete="tax-id" |
| 51 |
placeholder="<?php echo esc_html__('Enter Tax ID', 'fluent-cart'); ?>" |
| 52 |
id="fct_billing_tax_id" |
| 53 |
value="<?php echo esc_attr($vatNumber) ?? ''; ?>" |
| 54 |
aria-describedby="fct_billing_tax_id_error" |
| 55 |
/> |
| 56 |
|
| 57 |
<button |
| 58 |
type="button" |
| 59 |
data-fluent-cart-checkout-page-tax-apply-btn |
| 60 |
aria-label="<?php echo esc_attr__('Apply VAT number', 'fluent-cart'); ?>" |
| 61 |
> |
| 62 |
<?php echo esc_html__('Apply', 'fluent-cart'); ?> |
| 63 |
</button> |
| 64 |
</div> |
| 65 |
<span |
| 66 |
data-fluent-cart-checkout-page-tax-loading |
| 67 |
class="fct_tax_loading" |
| 68 |
role="status" |
| 69 |
aria-live="polite" |
| 70 |
aria-label="<?php echo esc_attr__('Validating VAT number', 'fluent-cart'); ?>"> |
| 71 |
</span> |
| 72 |
|
| 73 |
<span |
| 74 |
data-fluent-cart-checkout-page-form-error |
| 75 |
class="fct_form_error" |
| 76 |
id="fct_billing_tax_id_error" |
| 77 |
role="alert" |
| 78 |
aria-live="assertive"> |
| 79 |
</span> |
| 80 |
|
| 81 |
<?php $this->renderValidNote($cart->checkout_data); ?> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
</div> |
| 85 |
<?php |
| 86 |
} else { |
| 87 |
return ''; |
| 88 |
} |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
public function renderValidNote($checkoutData) |
| 93 |
{ |
| 94 |
$isValid = Arr::get($checkoutData, 'tax_data.valid', false); |
| 95 |
$name = Arr::get($checkoutData, 'tax_data.name', ''); |
| 96 |
$taxTotal = Arr::get($checkoutData, 'tax_data.tax_total', 0); |
| 97 |
|
| 98 |
?> |
| 99 |
|
| 100 |
<div |
| 101 |
class="fct_vat_valid_note <?php echo !$isValid ? 'is-hidden' : ''; ?>" |
| 102 |
data-fluent-cart-tax-valid-note-wrapper role="status" |
| 103 |
aria-live="polite" |
| 104 |
<?php echo $isValid ? '' : 'aria-hidden="true"'; ?> |
| 105 |
> |
| 106 |
<span data-fluent-cart-tax-valid-note > |
| 107 |
<span class="sr-only"> |
| 108 |
<?php echo esc_html__('Valid VAT number for:', 'fluent-cart'); ?> |
| 109 |
</span> |
| 110 |
<?php echo esc_html($name); ?> |
| 111 |
|
| 112 |
<?php if ($taxTotal != 0): ?> |
| 113 |
<span style="color: #ffa500;"> |
| 114 |
<?php echo esc_html__('(Reverse Charge not applied)', 'fluent-cart'); ?> |
| 115 |
</span> |
| 116 |
<?php endif; ?> |
| 117 |
</span> |
| 118 |
|
| 119 |
<button |
| 120 |
type="button" |
| 121 |
data-fluent-cart-tax-remove-btn |
| 122 |
aria-label="<?php echo esc_attr__('Remove VAT number', 'fluent-cart'); ?>" |
| 123 |
> |
| 124 |
<?php echo esc_html__('Remove', 'fluent-cart'); ?> |
| 125 |
</button> |
| 126 |
</div> |
| 127 |
|
| 128 |
<?php |
| 129 |
} |
| 130 |
} |
| 131 |
|