From 78325743a926eda4fda83202bf2948854da7b9e0 Mon Sep 17 00:00:00 2001 From: EvgenPalich Date: Mon, 22 Dec 2025 13:25:13 +0300 Subject: [PATCH] add new vats --- README.md | 5 ++ lib/config/plugin.php | 2 +- lib/config/settings.php | 32 ++++++++++++ lib/payselectionPayment.class.php | 81 +++++++++++++++++-------------- 4 files changed, 83 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 29c28ad..e36fa5f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ PaySelection - универсальное платежное решение дл Плагин не учитывает настройку налогообложения по отдельным товарам. +**Поддерживаемые ставки НДС:** 22%, 20%, 10%, 7%, 5%, Без НДС. + ## Установка Плагин можно установить с помощью Инсталера со [страницы плагина](https://www.webasyst.ru/store/plugin/payment/payselection/) либо вручную из этого репозитория. @@ -63,6 +65,9 @@ CVC 123 # Changelog Все значимые изменения плагина перечислены здесь. +## [1.0.4] - 2025-12-22 + - Добавлены новые ставки НДС + ## [1.0.3] - 2023-04-06 - Добавлена возможность настроить СНО, признак способа расчета и вид оплаты diff --git a/lib/config/plugin.php b/lib/config/plugin.php index 743d2fa..c8f60a9 100644 --- a/lib/config/plugin.php +++ b/lib/config/plugin.php @@ -4,7 +4,7 @@ 'description' => 'Online payment service', 'logo' => 'img/payselection2.png', 'icon' => 'img/payselection.png', - 'version' => '1.0.3', + 'version' => '1.0.4', 'vendor' => '1274583', 'partial_refund' => true, 'partial_capture' => false, diff --git a/lib/config/settings.php b/lib/config/settings.php index 4011a62..79608e1 100644 --- a/lib/config/settings.php +++ b/lib/config/settings.php @@ -139,10 +139,26 @@ 'title' => /*_w*/('Из карточки товара'), 'value' => '' ), + array( + 'title' => /*_w*/('НДС 22%'), + 'value' => '22' + ), array( 'title' => /*_w*/('НДС 20%'), 'value' => '20' ), + array( + 'title' => /*_w*/('НДС 10%'), + 'value' => '10' + ), + array( + 'title' => /*_w*/('НДС 7%'), + 'value' => '7' + ), + array( + 'title' => /*_w*/('НДС 5%'), + 'value' => '5' + ), array( 'title' => /*_w*/('Без НДС'), 'value' => '-1' @@ -154,10 +170,26 @@ 'title' => /*_w*/('Источник значения НДС для доставки'), 'control_type' => waHtmlControl::SELECT, 'options' => array( + array( + 'title' => /*_w*/('НДС 22%'), + 'value' => '22' + ), array( 'title' => /*_w*/('НДС 20%'), 'value' => '20' ), + array( + 'title' => /*_w*/('НДС 10%'), + 'value' => '10' + ), + array( + 'title' => /*_w*/('НДС 7%'), + 'value' => '7' + ), + array( + 'title' => /*_w*/('НДС 5%'), + 'value' => '5' + ), array( 'title' => /*_w*/('Без НДС'), 'value' => '-1' diff --git a/lib/payselectionPayment.class.php b/lib/payselectionPayment.class.php index 487579b..02890ac 100644 --- a/lib/payselectionPayment.class.php +++ b/lib/payselectionPayment.class.php @@ -49,6 +49,41 @@ public function getWebhookSignature() return $signature; } + /** + * Map numeric tax percentage to API vat type string + * Supported: 22, 20, 10, 7, 5, none + */ + protected function mapVatType($tax) + { + $t = (float)$tax; + if ($t <= 0) { + return 'none'; + } + if (abs($t - 22) < 0.01) { + return 'vat22'; + } + if (abs($t - 20) < 0.01) { + return 'vat20'; + } + if (abs($t - 10) < 0.01) { + return 'vat10'; + } + if (abs($t - 7) < 0.01) { + return 'vat7'; + } + if (abs($t - 5) < 0.01) { + return 'vat5'; + } + // Fallbacks for non-standard values + if ($t >= 20) { + return 'vat20'; + } + if ($t > 10) { + return 'vat10'; + } + return 'none'; + } + public function query($api_method, $content, $method = waNet::METHOD_POST, $type_host = 'gw') { $url = $this->getUrl($api_method, $type_host); @@ -138,17 +173,11 @@ public function apiCreateArray($order_data) } else { foreach ($order_data['items'] as $item) { $tax = empty($this->tax) ? $item['tax_rate'] : $this->tax; - if ($tax > 10) { - $tax = 'vat20'; - } else if ($tax > 0) { - $tax = 'vat10'; - } else { - $tax = 'none'; - } + $tax = $this->mapVatType($tax); - if($this->payment_type == 'Block') { - $tax = str_replace('vat', 'vat1', $tax); - } + // if($this->payment_type == 'Block') { + // $tax = str_replace('vat', 'vat1', $tax); + // } $content['ReceiptData']['receipt']['items'][] = array( 'name' => mb_substr($item['name'], 0, 128), @@ -164,18 +193,11 @@ public function apiCreateArray($order_data) } if (!empty($order_data['shipping'])) { - $tax = $this->tax_delivery; - if ($tax > 10) { - $tax = 'vat20'; - } else if ($tax > 0) { - $tax = 'vat10'; - } else { - $tax = 'none'; - } + $tax = $this->mapVatType($this->tax_delivery); - if($this->payment_type == 'Block') { - $tax = str_replace('vat', 'vat1', $tax); - } + // if($this->payment_type == 'Block') { + // $tax = str_replace('vat', 'vat1', $tax); + // } $content['ReceiptData']['receipt']['items'][] = array( 'name' => 'Доставка', 'price' => round($order_data['shipping'],2), @@ -243,13 +265,7 @@ public function apiRefundArray($transaction_raw_data, $order_data) $refund_items = waRequest::post('refund_items', array()); foreach ($order_data['items'] as $item) { $tax = empty($this->tax) ? $item['tax_rate'] : $this->tax; - if ($tax > 10) { - $tax = 'vat20'; - } else if ($tax > 0) { - $tax = 'vat10'; - } else { - $tax = 'none'; - } + $tax = $this->mapVatType($tax); if(waRequest::post('refund_mode') == 'full') { $content['ReceiptData']['receipt']['items'][] = array( @@ -284,14 +300,7 @@ public function apiRefundArray($transaction_raw_data, $order_data) } if (!empty($order_data['shipping']) && waRequest::post('refund_mode') == 'full') { - $tax = $this->tax_delivery; - if ($tax > 10) { - $tax = 'vat20'; - } else if ($tax > 0) { - $tax = 'vat10'; - } else { - $tax = 'none'; - } + $tax = $this->mapVatType($this->tax_delivery); $content['ReceiptData']['receipt']['items'][] = array( 'name' => 'Доставка',