Changeset 3464118
- Timestamp:
- 02/18/2026 09:32:14 AM (8 months ago)
- Location:
- tiptoppay-gateway-for-woocommerce
- Files:
-
- 22 added
- 5 edited
-
tags/1.0.5 (added)
-
tags/1.0.5/assets (added)
-
tags/1.0.5/assets/admin-scripts.js (added)
-
tags/1.0.5/assets/admin-styles.css (added)
-
tags/1.0.5/assets/blocks (added)
-
tags/1.0.5/assets/blocks/blocks.asset.php (added)
-
tags/1.0.5/assets/blocks/blocks.js (added)
-
tags/1.0.5/assets/scripts.js (added)
-
tags/1.0.5/assets/style.css (added)
-
tags/1.0.5/assets/widget-init.js (added)
-
tags/1.0.5/inc (added)
-
tags/1.0.5/inc/blocks (added)
-
tags/1.0.5/inc/blocks/wc-tiptoppay-blocks.php (added)
-
tags/1.0.5/inc/class-tiptoppay-api.php (added)
-
tags/1.0.5/inc/class-tiptoppay-init.php (added)
-
tags/1.0.5/inc/wc-tiptoppay-gateway.php (added)
-
tags/1.0.5/readme.txt (added)
-
tags/1.0.5/templates (added)
-
tags/1.0.5/templates/payment-fields-checkout.php (added)
-
tags/1.0.5/templates/tiptoppay-widget.php (added)
-
tags/1.0.5/tiptoppay_gateway_for_wc.php (added)
-
tags/1.0.5/visa-mastercard.png (added)
-
trunk/assets/admin-scripts.js (modified) (1 diff)
-
trunk/inc/class-tiptoppay-init.php (modified) (11 diffs)
-
trunk/inc/wc-tiptoppay-gateway.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/tiptoppay_gateway_for_wc.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tiptoppay-gateway-for-woocommerce/trunk/assets/admin-scripts.js
r3200618 r3464118 21 21 }, 3000 ); 22 22 } ); 23 24 $('select[name="woocommerce_wc_tiptoppay_gateway_paymentMethodSequenceOptions"]').on('change', function() { 25 // Получаем текущее значение select 26 var selectedValue = $(this).val(); 27 var inputField = $('input[name="woocommerce_wc_tiptoppay_gateway_paymentMethodSequence"]') 28 var inputFieldValue = inputField.val(); 29 30 if (!inputFieldValue) { 31 inputField.val(selectedValue); 32 return; 33 } 34 35 const valuesArray = inputFieldValue.split(','); 36 37 if (valuesArray.includes(selectedValue)) { 38 return; // Не добавляем дубликат 39 } 40 41 valuesArray.push(selectedValue); 42 inputField.val(valuesArray.join(',')); 43 }); 23 44 }); -
tiptoppay-gateway-for-woocommerce/trunk/inc/class-tiptoppay-init.php
r3303671 r3464118 1 1 <?php 2 2 3 3 if (!defined('ABSPATH')) exit; // Exit if accessed directly 4 4 5 5 class TipTopPay_Init 6 6 { 7 7 8 8 public static function init() 9 9 { … … 17 17 add_action('woocommerce_blocks_loaded', array(__CLASS__, 'woocommerce_gateway_tiptoppay_woocommerce_block_support')); 18 18 } 19 19 20 20 public static function api_remove_enqueues() 21 21 { … … 24 24 global $wp_scripts; 25 25 $wp_scripts->queue = array(); 26 26 27 27 wp_enqueue_script('TipTopPay_Widget', 'https://widget.tiptoppay.kz/bundles/widget.js', array(), time(), false); 28 28 wp_enqueue_script('TipTopPay_Widget_Init', plugins_url('/assets/widget-init.js', TTPGWWC_PLUGIN_FILENAME), array(), time(), false); 29 29 30 30 wp_localize_script('TipTopPay_Widget_Init', 'widget_data', TipTopPay_Init::widget_data()); 31 31 32 32 }, 200); 33 33 34 34 add_action('wp_print_styles', 35 35 function () { … … 38 38 }, 200); 39 39 } 40 40 41 41 public static function tiptoppay_scripts() 42 42 { … … 45 45 wp_enqueue_style('TipTopPay_style', plugins_url('/assets/style.css', TTPGWWC_PLUGIN_FILENAME)); 46 46 } 47 48 } 49 47 48 } 49 50 50 public static function tiptoppay_admin_scripts() 51 51 { … … 53 53 wp_enqueue_style('TipTopPay_admin', plugins_url('/assets/admin-styles.css', TTPGWWC_PLUGIN_FILENAME)); 54 54 } 55 56 public static function widget_data() 57 { 58 global $woocommerce; 59 60 $options = (object)get_option('woocommerce_wc_tiptoppay_gateway_settings'); 61 $current_user = wp_get_current_user(); 62 if (isset($_GET['action']) && $_GET['action'] == 'add_payment_method') { 63 $data['paymentSchema'] = 'Dual'; 64 $data['emailBehavior'] = $options->emailBehavior ?? 'Optional'; 65 $data['paymentMethodsNotfoldedCount'] = (int)$options->paymentMethods > 3 ? $options->paymentMethods : 3; 66 $data['publicTerminalId'] = $options->public_id; 67 $data['description'] = 'Добавление карты'; 68 $data['culture'] = $options->language; 69 $data['amount'] = ($options->currency !== 'siteCurrency') ? 11 : 1; 70 $data['currency'] = ($options->currency !== 'siteCurrency') ? $options->currency : get_woocommerce_currency(); 71 $data['skin'] = $options->skin; 72 $data['userInfo']['accountId'] = $current_user->ID; 73 $data['userInfo']['email'] = $current_user->user_email; 74 $data['metadata'] = array('add_payment_method' => 1); 75 76 return array( 77 'data' => $data, 78 'return_url' => esc_url(sanitize_text_field($_GET['return_ok'])), 79 'cancel_return_url' => esc_url(sanitize_text_field($_GET['return_ok'])), 80 ); 81 } 82 83 $order_id = sanitize_text_field($_GET['order_id']); 84 $order = new WC_Order($order_id); 85 $title = array(); 86 $items_array = array(); 87 $items = $order->get_items(); 88 $shipping_data = array( 89 "label" => "Доставка", 90 "price" => number_format((float)$order->get_total_shipping() + abs((float)$order->get_shipping_tax()), 2, '.', ''), 91 "quantity" => "1.00", 92 "amount" => number_format((float)$order->get_total_shipping() + abs((float)$order->get_shipping_tax()), 2, '.', ''), 93 "vat" => ($options->delivery_taxtype == "null") ? null : $options->delivery_taxtype, 94 'method' => (int)$options->kassa_method, 95 'object' => 4, 96 "ean" => null 97 ); 98 99 if (isset($options->shipping_spic) && isset($options->shipping_package_code)) { 100 $shipping_data['spic'] = $options->shipping_spic; 101 $shipping_data['packageCode'] = $options->shipping_package_code; 102 } 103 104 $AdditionalReceiptInfos = false; 105 106 foreach ($items as $item) { 107 if ($options->kassa_enabled == 'yes') { 108 $product = $item->get_product(); 109 $attributes = $product->get_attributes(); 110 111 $ttp_item = array( 112 "label" => $item['name'], 113 "price" => number_format((float)$product->get_price(), 2, '.', ''), 114 "quantity" => number_format((float)$item['quantity'], 2, '.', ''), 115 "amount" => number_format((float)$item['total'] + abs((float)$item['total_tax']), 2, '.', ''), 116 "vat" => ($options->kassa_taxtype == "null") ? null : $options->kassa_taxtype, 117 'method' => (int)$options->kassa_method, 118 'object' => (int)$options->kassa_object, 119 "ean" => ($options->kassa_skubarcode == 'yes') ? ((strlen($product->get_sku()) < 1) ? null : $product->get_sku()) : null 120 ); 121 122 if (key_exists('pa_packagecode', $attributes) && key_exists('pa_spic', $attributes)) { 123 $ttp_item['packageCode'] = $attributes['pa_packagecode']->get_slugs()[0]; 124 $ttp_item['spic'] = $attributes['pa_spic']->get_slugs()[0]; 125 if (!$AdditionalReceiptInfos) { 126 $AdditionalReceiptInfos = ["Вы стали обладателем права на 1% cashback"]; // Это статичное значение 127 } 128 } 129 130 $items_array[] = $ttp_item; 131 } 132 $title[] = $item['name'] . (isset($item['pa_ver']) ? ' ' . $item['pa_ver'] : ''); 133 } 134 135 if ($options->kassa_enabled == 'yes' && $order->get_total_shipping() > 0) { 136 $items_array[] = $shipping_data; 137 } 138 139 $kassa_array = array( 140 "Items" => $items_array, 141 "taxationSystem" => $options->kassa_taxsystem, 142 'calculationPlace' => sanitize_text_field($_SERVER['SERVER_NAME']), 143 "email" => $order->get_billing_email(), 144 "phone" => $order->get_billing_phone(), 145 ); 146 147 if ($AdditionalReceiptInfos) { 148 $kassa_array['AdditionalReceiptInfos'] = $AdditionalReceiptInfos; 149 } 150 151 $data['paymentSchema'] = 'Single'; 152 153 if ($options->enabledDMS != 'no') { 154 $data['paymentSchema'] = 'Dual'; 155 $data['enabledDMS'] = true; 156 } 157 158 if (is_user_logged_in() && isset($_GET['ttp_save_card']) && !empty($_GET['ttp_save_card'])) { 159 $data['userInfo']['accountId'] = $order->get_user_id(); 160 } 161 162 $data['publicTerminalId'] = $options->public_id; 163 $data['description'] = $options->order_text . ' ' . $order_id; 164 $data['amount'] = (float)$order->get_total(); 165 $data['currency'] = ($options->currency !== 'siteCurrency') ? $options->currency : get_woocommerce_currency(); 166 $data['skin'] = $options->skin; 167 $data['culture'] = $options->language; 168 $data['externalId'] = $order_id; 169 $data['emailBehavior'] = $options->emailBehavior ?? 'Optional'; 170 $data['paymentMethodsNotfoldedCount'] = (int)$options->paymentMethods > 3 ? $options->paymentMethods : 3; 171 $data['userInfo'] = [ 172 "email" => $order->get_billing_email(), 173 "phone" => $order->get_billing_phone(), 174 ]; 175 if ($options->kassa_enabled == 'yes') { 176 $data['receipt'] = $kassa_array; 177 } 178 179 return array( 180 'data' => $data, 181 'return_url' => esc_url(sanitize_text_field($_GET['return_ok'])), 182 'cancel_return_url' => $order->get_cancel_order_url(), 183 ); 184 } 185 55 56 public static function widget_data() 57 { 58 global $woocommerce; 59 60 $options = (object) get_option('woocommerce_wc_tiptoppay_gateway_settings'); 61 62 $data = [ 63 'publicTerminalId' => $options->public_id, 64 'skin' => $options->skin, 65 'culture' => $options->language, 66 'emailBehavior' => $options->emailBehavior ?? 'Optional', 67 'paymentMethodsNotfoldedCount' => max((int) $options->paymentMethods, 3), 68 ]; 69 70 if (isset($_GET['action']) && $_GET['action'] === 'add_payment_method') { 71 $data['paymentSchema'] = 'Dual'; 72 $data['description'] = 'Добавление карты'; 73 $data['amount'] = ($options->currency !== 'siteCurrency') ? 11 : 1; 74 $data['currency'] = ($options->currency !== 'siteCurrency') ? $options->currency : get_woocommerce_currency(); 75 $data['userInfo'] = [ 76 'accountId' => wp_get_current_user()->ID, 77 'email' => wp_get_current_user()->user_email, 78 ]; 79 $data['metadata'] = ['add_payment_method' => 1]; 80 81 } else { 82 $order_id = sanitize_text_field($_GET['order_id']); 83 $order = new WC_Order($order_id); 84 85 $data['paymentSchema'] = ($options->enabledDMS != 'no') ? 'Dual' : 'Single'; 86 $data['description'] = $options->order_text . ' ' . $order_id; 87 $data['amount'] = (float) $order->get_total(); 88 $data['currency'] = ($options->currency !== 'siteCurrency') ? $options->currency : get_woocommerce_currency(); 89 $data['externalId'] = $order_id; 90 91 $data['userInfo'] = [ 92 'accountId' => $order->get_billing_email(), 93 'email' => $order->get_billing_email(), 94 'phone' => $order->get_billing_phone(), 95 ]; 96 97 if (is_user_logged_in() && !empty($_GET['ttp_save_card'])) { 98 $data['userInfo']['accountId'] = $order->get_user_id(); 99 } 100 101 $cancel_url = $order->get_cancel_order_url(); 102 103 if ($options->kassa_enabled === 'yes') { 104 $items = $order->get_items(); 105 $items_array = []; 106 107 foreach ($items as $item) { 108 $product = $item->get_product(); 109 110 $price = (float) $product->get_price(); 111 $total = (float) $item['total'] + abs((float) $item['total_tax']); 112 $quantity = (float) $item['quantity']; 113 114 $items_array[] = [ 115 'label' => $item['name'], 116 'price' => number_format($price, 2, '.', ''), 117 'quantity' => number_format($quantity, 2, '.', ''), 118 'amount' => number_format($total, 2, '.', ''), 119 'vat' => ($options->kassa_taxtype === 'null') ? null : $options->kassa_taxtype, 120 'method' => (int) $options->kassa_method, 121 'object' => (int) $options->kassa_object, 122 'ean' => ($options->kassa_skubarcode === 'yes' && $product->get_sku()) ? $product->get_sku() : null, 123 ]; 124 } 125 126 if ($order->get_total_shipping() > 0) { 127 $shipping_amount = (float) $order->get_total_shipping() + abs((float) $order->get_shipping_tax()); 128 129 $items_array[] = [ 130 'label' => 'Доставка', 131 'price' => number_format($shipping_amount, 2, '.', ''), 132 'quantity' => '1.00', 133 'amount' => number_format($shipping_amount, 2, '.', ''), 134 'vat' => ($options->delivery_taxtype === 'null') ? null : $options->delivery_taxtype, 135 'method' => (int) $options->kassa_method, 136 'object' => 4, 137 'ean' => null, 138 ]; 139 } 140 141 $fees = $order->get_fees(); 142 if (count($fees) > 0) { 143 foreach ($fees as $fee) { 144 $items_array[] = array( 145 "label" => $fee->get_name(), 146 "price" => number_format((float)$fee->get_total(), 2, '.', ''), 147 "quantity" => "1.00", 148 "amount" => number_format((float)$fee->get_total(), 2, '.', ''), 149 ); 150 } 151 } 152 153 $data['receipt'] = [ 154 'Items' => $items_array, 155 'taxationSystem' => $options->kassa_taxsystem, 156 'calculationPlace' => sanitize_text_field($_SERVER['SERVER_NAME']), 157 'email' => $order->get_billing_email(), 158 'phone' => $order->get_billing_phone(), 159 ]; 160 } 161 } 162 163 if (!empty($options->paymentMethodSequence)) { 164 $data['paymentMethodSequence'] = explode(',', $options->paymentMethodSequence); 165 } 166 if (!empty($options->restrictedPaymentMethods)) { 167 $data['restrictedPaymentMethods'] = $options->restrictedPaymentMethods; 168 } 169 170 return [ 171 'data' => $data, 172 'return_url' => esc_url(sanitize_text_field($_GET['return_ok'])), 173 'cancel_return_url' => $cancel_url ?? esc_url(sanitize_text_field($_GET['return_ok'])), 174 ]; 175 } 176 186 177 public static function register_post_statuses() 187 178 { … … 203 194 )); 204 195 } 205 196 206 197 public static function add_order_statuses($order_statuses) 207 198 { 208 199 $order_statuses['wc-pay_au'] = _x('Платеж авторизован', 'WooCommerce Order status', 'text_domain'); 209 200 $order_statuses['wc-pay_delivered'] = _x('Доставлен', 'WooCommerce Order status', 'text_domain'); 210 201 211 202 return $order_statuses; 212 203 } 213 204 214 205 public static function TipTopPay() 215 206 { … … 218 209 } 219 210 add_filter('woocommerce_payment_gateways', [__CLASS__, 'add_gateway_class']); 220 211 221 212 require(TTPGWWC_PLUGIN_DIR . 'inc/class-tiptoppay-api.php'); 222 213 require(TTPGWWC_PLUGIN_DIR . 'inc/wc-tiptoppay-gateway.php'); 223 214 } 224 215 225 216 public static function add_gateway_class($methods) 226 217 { … … 228 219 return $methods; 229 220 } 230 231 221 222 232 223 /** 233 224 * Plugin url. … … 239 230 return untrailingslashit(plugins_url('/', __FILE__)); 240 231 } 241 232 242 233 /** 243 234 * Plugin url. … … 249 240 return trailingslashit(plugin_dir_path(__FILE__)); 250 241 } 251 242 252 243 /** 253 244 * Registers WooCommerce Blocks integration. -
tiptoppay-gateway-for-woocommerce/trunk/inc/wc-tiptoppay-gateway.php
r3303671 r3464118 1 1 <?php 2 3 use Automattic\Jetpack\Constants;4 5 if (!defined('ABSPATH')) exit; // Exit if accessed directly6 7 class WC_TipTopPay_Gateway extends WC_Payment_Gateway8 {9 2 10 public function __construct() 3 use Automattic\Jetpack\Constants; 4 5 if (!defined('ABSPATH')) exit; // Exit if accessed directly 6 7 class WC_TipTopPay_Gateway extends WC_Payment_Gateway 11 8 { 12 $this->id = 'wc_tiptoppay_gateway'; 13 $this->has_fields = true; 14 $this->icon = plugin_dir_url(__FILE__) . '../visa-mastercard.png'; 15 $this->method_title = esc_html__('TipTopPay', 'woocommerce'); 16 $this->method_description = 'TipTopPay – самый простой и удобный способ оплаты. Комиссий нет.'; 17 $this->supports = array( 18 'pre-orders', 19 'products', 20 'subscriptions', 21 'subscription_cancellation', 22 'subscription_suspension', 23 'subscription_reactivation', 24 'subscription_amount_changes', 25 'subscription_date_changes', 26 'multiple_subscriptions', 27 'tokenization' 28 ); 29 30 $this->init_form_fields(); 31 $this->init_settings(); 32 33 $this->title = 'TipTopPay'; 34 $this->description = 'TipTopPay'; 35 36 $this->enabled = $this->get_option('enabled'); 37 $this->enabledDMS = $this->get_option('enabledDMS'); 38 $this->DMS_AU_status = $this->get_option('DMS_AU_status'); 39 $this->DMS_CF_status = $this->get_option('DMS_CF_status'); 40 $this->skin = $this->get_option('skin'); 41 $this->language = $this->get_option('language'); 42 $this->status_chancel = $this->get_option('status_chancel'); 43 $this->status_pay = $this->get_option('status_pay'); 44 $this->title = $this->get_option('title'); 45 $this->description = $this->get_option('description'); 46 $this->public_id = $this->get_option('public_id'); 47 $this->api_pass = $this->get_option('api_pass'); 48 $this->currency = $this->get_option('currency'); 49 $this->url_return = $this->get_option('url_return'); 50 $this->kassa_enabled = $this->get_option('kassa_enabled'); 51 $this->kassa_taxtype = $this->get_option('kassa_taxtype'); 52 $this->delivery_taxtype = $this->get_option('delivery_taxtype'); 53 $this->kassa_taxsystem = $this->get_option('kassa_taxsystem'); 54 $this->kassa_skubarcode = $this->get_option('kassa_skubarcode'); 55 $this->kassa_method = $this->get_option('kassa_method'); 56 $this->kassa_object = $this->get_option('kassa_object'); 57 $this->status_delivered = $this->get_option('status_delivered'); 58 $this->inn = $this->get_option('inn'); 59 $this->order_text = $this->get_option('order_text'); 60 $this->enable_for_methods = $this->get_option('enable_for_methods', array()); 61 $this->shipping_spic = $this->get_option('shipping_spic'); 62 $this->shipping_package_code = $this->get_option('shipping_package_code'); 63 64 if ($this->currency === 'UZS') 65 $this->icon = plugin_dir_url(__FILE__) . '../visa-mastercard-uz.png'; 66 67 if ($this->currency === 'siteCurrency') 68 $this->currency = get_woocommerce_currency(); 69 70 add_action('woocommerce_receipt_wc_tiptoppay_gateway', array($this, 'payment_page')); 71 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 72 add_action('woocommerce_order_status_changed', array($this, 'update_order_status'), 10, 3); 73 add_action('woocommerce_scheduled_subscription_payment_wc_tiptoppay_gateway', array($this, 'scheduled_subscription_payment'), 100, 2); 74 add_action('woocommerce_api_tiptoppay_widget', array($this, 'tiptoppay_widget')); 75 76 /** API init */ 77 $api = new TipTopPay_Api($this->enabledDMS, $this->status_chancel, $this->status_pay, $this->api_pass, $this->DMS_AU_status, $this->public_id); 78 add_action('woocommerce_api_' . strtolower(get_class($this)), array($api, 'processRequest')); 79 } 80 81 public function tiptoppay_widget() 82 { 83 require(TTPGWWC_PLUGIN_DIR . 'templates/tiptoppay-widget.php'); 84 die(); 85 } 86 87 public function process_payment($order_id) 88 { 89 global $woocommerce; 90 $order = new WC_Order($order_id); 91 92 if (empty($_POST['ttp_card']) or $_POST['ttp_card'] == 'widget') { 93 $ttp_save_card = $_POST['ttp_save_card'] ? 1 : 0; // 1 : 1 всегда сохранять токен 94 95 $query = array( 96 'order_id' => $order_id, 97 'return_ok' => $this->get_return_url($order), 98 'ttp_save_card' => $ttp_save_card 99 ); 100 return array( 101 'result' => 'success', 102 'redirect' => home_url('/wc-api/tiptoppay_widget?') . http_build_query($query) 103 ); 104 } 105 106 $title = array(); 107 $items_array = array(); 108 $items = $order->get_items(); 109 $shipping_data = apply_filters( 110 'tiptoppay_process_payment_shipping_data', 111 array( 112 'label' => esc_html__('Shipping', 'woocommerce'), 113 'price' => number_format((float)$order->get_shipping_total() + abs((float)$order->get_shipping_tax()), 2, '.', ''), 114 'quantity' => '1.00', 115 'amount' => number_format((float)$order->get_shipping_total() + abs((float)$order->get_shipping_tax()), 2, '.', ''), 116 'vat' => ('null' == $this->delivery_taxtype) ? null : $this->delivery_taxtype, 117 'method' => (int)$this->kassa_method, 118 'object' => 4, 119 'ean' => null, 120 ), 121 $order, 122 $this 123 ); 124 125 foreach ($items as $item) { 126 if ($this->kassa_enabled == 'yes') { 127 $product = $item->get_product(); 128 $items_array[] = apply_filters( 129 'tiptoppay_process_payment_order_item', 130 array( 131 'label' => $item['name'], 132 'price' => number_format((float)$product->get_price(), 2, '.', ''), 133 'quantity' => number_format((float)$item['quantity'], 2, '.', ''), 134 'amount' => number_format((float)$item['total'] + abs((float)$item['total_tax']), 2, '.', ''), 135 'vat' => $this->kassa_taxtype == 'null' ? null : $this->kassa_taxtype, 136 'method' => (int)$this->kassa_method, 137 'object' => (int)$this->kassa_object, 138 'ean' => $this->kassa_skubarcode == 'yes' && $product->get_sku() ? $product->get_sku() : null 139 ), 140 $product, 141 $item_id, 142 $item, 143 $this 144 ); 145 } 146 $title[] = $item['name'] . (isset($item['pa_ver']) ? ' ' . $item['pa_ver'] : ''); 147 } 148 149 if ($this->kassa_enabled == 'yes' && $order->get_shipping_total() > 0) { 150 $items_array[] = $shipping_data; 151 } 152 153 $kassa_array = array( 154 "PaymentData" => (array( 155 "customerReceipt" => array( 156 "Items" => $items_array, 157 "taxationSystem" => $this->kassa_taxsystem, 158 'calculationPlace' => 'www.' . sanitize_text_field($_SERVER['SERVER_NAME']), 159 "email" => $order->get_billing_email(), 160 "phone" => $order->get_billing_phone() 161 ) 162 )) 163 ); 164 165 $widget_f = 'charge'; 166 167 if ($this->enabledDMS != 'no') { 168 $widget_f = 'auth'; 169 } 170 171 $accesskey = $this->public_id; 172 $access_psw = $this->api_pass; 173 174 $token = WC_Payment_Tokens::get((int)$_POST['ttp_card']); 175 176 $request = array( 177 'Token' => $token->get_token(), 178 'Amount' => $order->get_total(), 179 'Currency' => $this->currency, 180 'InvoiceId' => $order_id, 181 'AccountId' => $token->get_user_id(), 182 'TrInitiatorCode' => 1, 183 'Email' => $order->get_billing_email(), 184 'Description' => 'Оплата заказа № ' . $order_id, 185 'IpAddress' => sanitize_text_field($_SERVER['REMOTE_ADDR']), 186 ); 187 188 if ($this->kassa_enabled == 'yes') { 189 $request['JsonData'] = $kassa_array; 190 } 191 192 //отправляем запрос 193 $auth = base64_encode($accesskey . ":" . $access_psw); 194 $response = wp_remote_post('https://api.tiptoppay.kz/payments/tokens/' . $widget_f, 195 array( 196 'timeout' => 30, 197 'redirection' => 5, 198 'httpversion' => '1.0', 199 'blocking' => true, 200 'headers' => array('Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json'), 201 'body' => json_encode($request, JSON_UNESCAPED_UNICODE) 202 ) 203 ); 204 205 $response['body'] = json_decode($response['body'], true); 206 207 if ($response['body']['Success']) { 208 return array( 209 'result' => 'success', 210 'redirect' => $this->get_return_url($order) 211 ); 212 } 213 214 if ($response['body']['Message'] != null) { 215 216 wc_add_notice(esc_html__('Error:', 'woocommerce') . ' ' . $response['body']['Message'], 'error'); 217 } 218 219 if ($response['body']['Model']['CardHolderMessage'] != null) { 220 221 wc_add_notice(esc_html__('Error:', 'woocommerce') . ' ' . $response['body']['Model']['CardHolderMessage'], 'error'); 222 } 223 224 return false; 225 } 226 227 public function add_payment_method() 228 { 229 return array( 230 'redirect' => home_url('/wc-api/tiptoppay_widget') . '?action=add_payment_method&return_ok=' . wc_get_endpoint_url('payment-methods') 231 ); 232 } 233 234 public function admin_options() 235 { 236 if (!$this->ssl_check()) { 237 ?> 238 <div class="inline error"><p> 239 <strong><?php echo esc_html__('Warning', 'woocommerce'); ?></strong>: <?php echo $this->msg; ?></p> 240 </div> 241 <?php 242 } 243 ?> 244 <h3>TipTopPay</h3> 245 <p>TipTopPay – прямой и простой прием платежей с кредитных карт</p> 246 247 <?php 248 $account_actions = array( 249 'check', 250 'pay', 251 'fail', 252 'confirm', 253 'refund', 254 'cancel', 255 ); 256 257 $action_url_template = home_url('/wc-api/' . strtolower(get_class($this))); 258 ?> 259 <div class="tiptoppay-attention"> 260 <?php foreach ($account_actions as $key => $action) : ?> 261 <div class="account-action"> 262 <label class="account-action__label"> 263 <?php 264 printf( 265 esc_html__('В личном кабинете включите %s-уведомление на адрес', 'tiptoppay'), 266 esc_html(ucfirst($action)) 267 ); 268 ?> 269 </label> 270 <div class="account-action__input copy-to-clipboard-container"> 271 <?php 272 printf( 273 '<input type="text" class="input-text tiptoppay_action_input" id="tiptoppay_account_action_%s_url" value="%s" readonly>', 274 esc_attr($action), 275 esc_attr($action_url_template . '?action=' . $action) 276 ); 277 ?> 278 <?php 279 printf( 280 '<button type="button" class="button copy-tiptoppay-action-url" data-clipboard-target="#tiptoppay_account_action_%s_url" title="%s"><svg class="svg-icon" version="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M14.016 12h5.484l-5.484-5.484v5.484zM15 5.016l6 6v9.984q0 0.797-0.609 1.406t-1.406 0.609h-11.016q-0.797 0-1.383-0.609t-0.586-1.406v-14.016q0-0.797 0.609-1.383t1.406-0.586h6.984zM15.984 0.984v2.016h-12v14.016h-1.969v-14.016q0-0.797 0.586-1.406t1.383-0.609h12z"></path></svg> <span class="screen-reader-text">%s</button>', 281 esc_attr($action), 282 esc_attr__('Copy URL to clipboard'), 283 esc_html__('Copy URL to clipboard') 284 ); 285 ?> 286 <span class="success hidden" aria-hidden="true"><?php esc_html_e('Copied!'); ?></span> 287 </div> 288 </div> 289 <?php endforeach; ?> 9 10 public function __construct() 11 { 12 $this->id = 'wc_tiptoppay_gateway'; 13 $this->has_fields = true; 14 $this->icon = plugin_dir_url(__FILE__) . '../visa-mastercard.png'; 15 $this->method_title = esc_html__('TipTopPay', 'woocommerce'); 16 $this->method_description = 'TipTopPay – самый простой и удобный способ оплаты. Комиссий нет.'; 17 $this->supports = array( 18 'pre-orders', 19 'products', 20 'subscriptions', 21 'subscription_cancellation', 22 'subscription_suspension', 23 'subscription_reactivation', 24 'subscription_amount_changes', 25 'subscription_date_changes', 26 'multiple_subscriptions', 27 'tokenization' 28 ); 29 30 $this->init_form_fields(); 31 $this->init_settings(); 32 33 $this->title = 'TipTopPay'; 34 $this->description = 'TipTopPay'; 35 36 $this->enabled = $this->get_option('enabled'); 37 $this->enabledDMS = $this->get_option('enabledDMS'); 38 $this->DMS_AU_status = $this->get_option('DMS_AU_status'); 39 $this->DMS_CF_status = $this->get_option('DMS_CF_status'); 40 $this->skin = $this->get_option('skin'); 41 $this->language = $this->get_option('language'); 42 $this->status_chancel = $this->get_option('status_chancel'); 43 $this->status_pay = $this->get_option('status_pay'); 44 $this->title = $this->get_option('title'); 45 $this->description = $this->get_option('description'); 46 $this->public_id = $this->get_option('public_id'); 47 $this->api_pass = $this->get_option('api_pass'); 48 $this->currency = $this->get_option('currency'); 49 $this->url_return = $this->get_option('url_return'); 50 $this->kassa_enabled = $this->get_option('kassa_enabled'); 51 $this->kassa_taxtype = $this->get_option('kassa_taxtype'); 52 $this->delivery_taxtype = $this->get_option('delivery_taxtype'); 53 $this->kassa_taxsystem = $this->get_option('kassa_taxsystem'); 54 $this->kassa_skubarcode = $this->get_option('kassa_skubarcode'); 55 $this->kassa_method = $this->get_option('kassa_method'); 56 $this->kassa_object = $this->get_option('kassa_object'); 57 $this->status_delivered = $this->get_option('status_delivered'); 58 $this->inn = $this->get_option('inn'); 59 $this->order_text = $this->get_option('order_text'); 60 $this->enable_for_methods = $this->get_option('enable_for_methods', array()); 61 $this->shipping_spic = $this->get_option('shipping_spic'); 62 $this->shipping_package_code = $this->get_option('shipping_package_code'); 63 64 if ($this->currency === 'UZS') 65 $this->icon = plugin_dir_url(__FILE__) . '../visa-mastercard-uz.png'; 66 67 if ($this->currency === 'siteCurrency') 68 $this->currency = get_woocommerce_currency(); 69 70 add_action('woocommerce_receipt_wc_tiptoppay_gateway', array($this, 'payment_page')); 71 add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 72 add_action('woocommerce_order_status_changed', array($this, 'update_order_status'), 10, 3); 73 add_action('woocommerce_scheduled_subscription_payment_wc_tiptoppay_gateway', array($this, 'scheduled_subscription_payment'), 100, 2); 74 add_action('woocommerce_api_tiptoppay_widget', array($this, 'tiptoppay_widget')); 75 76 /** API init */ 77 $api = new TipTopPay_Api($this->enabledDMS, $this->status_chancel, $this->status_pay, $this->api_pass, $this->DMS_AU_status, $this->public_id); 78 add_action('woocommerce_api_' . strtolower(get_class($this)), array($api, 'processRequest')); 79 } 80 81 public function tiptoppay_widget() 82 { 83 require(TTPGWWC_PLUGIN_DIR . 'templates/tiptoppay-widget.php'); 84 die(); 85 } 86 87 public function process_payment($order_id) 88 { 89 global $woocommerce; 90 $order = new WC_Order($order_id); 91 92 if (empty($_POST['ttp_card']) or $_POST['ttp_card'] == 'widget') { 93 $ttp_save_card = $_POST['ttp_save_card'] ? 1 : 0; // 1 : 1 всегда сохранять токен 94 95 $query = array( 96 'order_id' => $order_id, 97 'return_ok' => $this->get_return_url($order), 98 'ttp_save_card' => $ttp_save_card 99 ); 100 return array( 101 'result' => 'success', 102 'redirect' => home_url('/wc-api/tiptoppay_widget') . '?' . http_build_query($query) 103 ); 104 } 105 106 $title = array(); 107 $items_array = array(); 108 $items = $order->get_items(); 109 $shipping_data = apply_filters( 110 'tiptoppay_process_payment_shipping_data', 111 array( 112 'label' => esc_html__('Shipping', 'woocommerce'), 113 'price' => number_format((float)$order->get_shipping_total() + abs((float)$order->get_shipping_tax()), 2, '.', ''), 114 'quantity' => '1.00', 115 'amount' => number_format((float)$order->get_shipping_total() + abs((float)$order->get_shipping_tax()), 2, '.', ''), 116 'vat' => ('null' == $this->delivery_taxtype) ? null : $this->delivery_taxtype, 117 'method' => (int)$this->kassa_method, 118 'object' => 4, 119 'ean' => null, 120 ), 121 $order, 122 $this 123 ); 124 125 foreach ($items as $item) { 126 if ($this->kassa_enabled == 'yes') { 127 $product = $item->get_product(); 128 $items_array[] = apply_filters( 129 'tiptoppay_process_payment_order_item', 130 array( 131 'label' => $item['name'], 132 'price' => number_format((float)$product->get_price(), 2, '.', ''), 133 'quantity' => number_format((float)$item['quantity'], 2, '.', ''), 134 'amount' => number_format((float)$item['total'] + abs((float)$item['total_tax']), 2, '.', ''), 135 'vat' => $this->kassa_taxtype == 'null' ? null : $this->kassa_taxtype, 136 'method' => (int)$this->kassa_method, 137 'object' => (int)$this->kassa_object, 138 'ean' => $this->kassa_skubarcode == 'yes' && $product->get_sku() ? $product->get_sku() : null 139 ), 140 $product, 141 $item_id, 142 $item, 143 $this 144 ); 145 } 146 $title[] = $item['name'] . (isset($item['pa_ver']) ? ' ' . $item['pa_ver'] : ''); 147 } 148 149 if ($this->kassa_enabled == 'yes' && $order->get_shipping_total() > 0) { 150 $items_array[] = $shipping_data; 151 } 152 153 $kassa_array = array( 154 "PaymentData" => (array( 155 "customerReceipt" => array( 156 "Items" => $items_array, 157 "taxationSystem" => $this->kassa_taxsystem, 158 'calculationPlace' => 'www.' . sanitize_text_field($_SERVER['SERVER_NAME']), 159 "email" => $order->get_billing_email(), 160 "phone" => $order->get_billing_phone() 161 ) 162 )) 163 ); 164 165 $widget_f = 'charge'; 166 167 if ($this->enabledDMS != 'no') { 168 $widget_f = 'auth'; 169 } 170 171 $accesskey = $this->public_id; 172 $access_psw = $this->api_pass; 173 174 $token = WC_Payment_Tokens::get((int)$_POST['ttp_card']); 175 176 $request = array( 177 'Token' => $token->get_token(), 178 'Amount' => $order->get_total(), 179 'Currency' => $this->currency, 180 'InvoiceId' => $order_id, 181 'AccountId' => $token->get_user_id(), 182 'TrInitiatorCode' => 1, 183 'Email' => $order->get_billing_email(), 184 'Description' => 'Оплата заказа № ' . $order_id, 185 'IpAddress' => sanitize_text_field($_SERVER['REMOTE_ADDR']), 186 ); 187 188 if ($this->kassa_enabled == 'yes') { 189 $request['JsonData'] = $kassa_array; 190 } 191 192 //отправляем запрос 193 $auth = base64_encode($accesskey . ":" . $access_psw); 194 $response = wp_remote_post('https://api.tiptoppay.kz/payments/tokens/' . $widget_f, 195 array( 196 'timeout' => 30, 197 'redirection' => 5, 198 'httpversion' => '1.0', 199 'blocking' => true, 200 'headers' => array('Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json'), 201 'body' => json_encode($request, JSON_UNESCAPED_UNICODE) 202 ) 203 ); 204 205 $response['body'] = json_decode($response['body'], true); 206 207 if ($response['body']['Success']) { 208 return array( 209 'result' => 'success', 210 'redirect' => $this->get_return_url($order) 211 ); 212 } 213 214 if ($response['body']['Message'] != null) { 215 216 wc_add_notice(esc_html__('Error:', 'woocommerce') . ' ' . $response['body']['Message'], 'error'); 217 } 218 219 if ($response['body']['Model']['CardHolderMessage'] != null) { 220 221 wc_add_notice(esc_html__('Error:', 'woocommerce') . ' ' . $response['body']['Model']['CardHolderMessage'], 'error'); 222 } 223 224 return false; 225 } 226 227 public function add_payment_method() 228 { 229 return array( 230 'redirect' => home_url('/wc-api/tiptoppay_widget') . '?action=add_payment_method&return_ok=' . wc_get_endpoint_url('payment-methods') 231 ); 232 } 233 234 public function admin_options() 235 { 236 if (!$this->ssl_check()) { 237 ?> 238 <div class="inline error"><p> 239 <strong><?php echo esc_html__('Warning', 'woocommerce'); ?></strong>: <?php echo $this->msg; ?> 240 </p> 241 </div> 242 <?php 243 } 244 ?> 245 <h3>TipTopPay</h3> 246 <p>TipTopPay – прямой и простой прием платежей с кредитных карт</p> 247 248 <?php 249 $account_actions = array( 250 'check', 251 'pay', 252 'fail', 253 'confirm', 254 'refund', 255 'cancel', 256 ); 257 258 $action_url_template = home_url('/wc-api/' . strtolower(get_class($this))); 259 ?> 260 <div class="tiptoppay-attention"> 261 <?php foreach ($account_actions as $key => $action) : ?> 262 <div class="account-action"> 263 <label class="account-action__label"> 264 <?php 265 printf( 266 esc_html__('В личном кабинете включите %s-уведомление на адрес', 'tiptoppay'), 267 esc_html(ucfirst($action)) 268 ); 269 ?> 270 </label> 271 <div class="account-action__input copy-to-clipboard-container"> 272 <?php 273 printf( 274 '<input type="text" class="input-text tiptoppay_action_input" id="tiptoppay_account_action_%s_url" value="%s" readonly>', 275 esc_attr($action), 276 esc_attr($action_url_template . '?action=' . $action) 277 ); 278 ?> 279 <?php 280 printf( 281 '<button type="button" class="button copy-tiptoppay-action-url" data-clipboard-target="#tiptoppay_account_action_%s_url" title="%s"><svg class="svg-icon" version="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M14.016 12h5.484l-5.484-5.484v5.484zM15 5.016l6 6v9.984q0 0.797-0.609 1.406t-1.406 0.609h-11.016q-0.797 0-1.383-0.609t-0.586-1.406v-14.016q0-0.797 0.609-1.383t1.406-0.586h6.984zM15.984 0.984v2.016h-12v14.016h-1.969v-14.016q0-0.797 0.586-1.406t1.383-0.609h12z"></path></svg> <span class="screen-reader-text">%s</button>', 282 esc_attr($action), 283 esc_attr__('Copy URL to clipboard'), 284 esc_html__('Copy URL to clipboard') 285 ); 286 ?> 287 <span class="success hidden" aria-hidden="true"><?php esc_html_e('Copied!'); ?></span> 288 </div> 289 </div> 290 <?php endforeach; ?> 290 291 291 <p>Кодировка UTF-8, HTTP-метод POST, Формат запроса TipTopPay.</p> 292 </div> 293 294 <?php 295 296 echo '<table class="form-table">'; 297 $this->generate_settings_html(); 298 echo '</table>'; 299 } 300 301 public function payment_fields() 302 { 303 if (is_account_page()) { 304 return; 305 } 306 require(TTPGWWC_PLUGIN_DIR . 'templates/payment-fields-checkout.php'); 307 } 308 309 public function init_form_fields() 310 { 311 $array_status = wc_get_order_statuses(); 312 $this->form_fields = array( 313 'enabled' => array( 314 'title' => esc_html__('Enable/Disable', 'woocommerce'), 315 'type' => 'checkbox', 316 'label' => esc_html__('Включить TipTopPay', 'woocommerce'), 317 'default' => 'yes' 318 ), 319 'enabledDMS' => array( 320 'title' => esc_html__('Включить DMS', 'woocommerce'), 321 'type' => 'checkbox', 322 'label' => esc_html__('Включить DMS', 'woocommerce'), 323 'default' => 'no' 324 ), 325 'order_text' => array( 326 'title' => esc_html__('Текст оплаты заказа', 'woocommerce'), 327 'type' => 'text', 328 'default' => esc_html__('Оплата заказа:', 'woocommerce'), 329 'desc_tip' => true, 330 ), 331 'status_pay' => array( 332 'title' => esc_html__('Статус для оплаченного заказа', 'woocommerce'), 333 'type' => 'select', 334 'class' => 'wc-enhanced-select', 335 'description' => esc_html__('', 'woocommerce'), 336 'default' => 'wc-completed', 337 'desc_tip' => true, 338 'options' => $array_status, 339 ), 340 'status_chancel' => array( 341 'title' => esc_html__('Статус для отмененного заказа', 'woocommerce'), 342 'type' => 'select', 343 'class' => 'wc-enhanced-select', 344 'description' => esc_html__('', 'woocommerce'), 345 'default' => 'wc-cancelled', 346 'desc_tip' => true, 347 'options' => $array_status, 348 ), 349 'DMS_AU_status' => array( 350 'title' => esc_html__('Статус авторизованного платежа (DMS)', 'woocommerce'), 351 'type' => 'select', 352 'class' => 'wc-enhanced-select', 353 'description' => esc_html__('', 'woocommerce'), 354 'default' => 'wc-pay_au', 355 'desc_tip' => true, 356 'options' => $array_status, 357 ), 358 'title' => array( 359 'title' => esc_html__('Title', 'woocommerce'), 360 'type' => 'text', 361 'description' => esc_html__('This controls the title which the user sees during checkout.', 'woocommerce'), 362 'default' => esc_html__('Банковская карта', 'woocommerce'), 363 'desc_tip' => true, 364 ), 365 'description' => array( 366 'title' => esc_html__('Description', 'woocommerce'), 367 'type' => 'textarea', 368 'description' => esc_html__('Payment method description that the customer will see on your checkout.', 'woocommerce'), 369 'default' => esc_html__('TipTopPay – самый простой и удобный способ оплаты. Комиссий нет.', 'woocommerce'), 370 'desc_tip' => true, 371 ), 372 'public_id' => array( 373 'title' => esc_html__('Public ID', 'woocommerce'), 374 'type' => 'text', 375 'description' => 'Возьмите из личного кабинета TipTopPay', 376 'default' => '', 377 'desc_tip' => false, 378 ), 379 'api_pass' => array( 380 'title' => esc_html__('Пароль для API', 'woocommerce'), 381 'type' => 'text', 382 'description' => 'Возьмите из личного кабинета TipTopPay', 383 'default' => '', 384 'desc_tip' => false, 385 ), 386 'currency' => array( 387 'title' => esc_html__('Валюта магазина', 'woocommerce'), 388 'type' => 'select', 389 'class' => 'wc-enhanced-select', 390 'default' => 'KZT', 391 'options' => array( 392 'siteCurrency' => esc_html__('Валюта магазина', 'woocomerce'), 393 'RUB' => esc_html__('Российский рубль', 'woocommerce'), 394 'EUR' => esc_html__('Евро', 'woocommerce'), 395 'USD' => esc_html__('Доллар США', 'woocommerce'), 396 'KZT' => esc_html__('Казахский тенге', 'woocommerce'), 397 ), 398 ), 399 'skin' => array( 400 'title' => esc_html__('Дизайн виджета', 'woocommerce'), 401 'type' => 'select', 402 'class' => 'wc-enhanced-select', 403 'default' => 'classic', 404 'options' => array( 405 'classic' => esc_html__('Классический', 'woocommerce'), 406 'modern' => esc_html__('Модерн', 'woocommerce'), 407 'mini' => esc_html__('Мини', 'woocommerce'), 408 ), 409 ), 410 'language' => array( 411 'title' => esc_html__('Язык виджета', 'woocommerce'), 412 'type' => 'select', 413 'class' => 'wc-enhanced-select', 414 'default' => 'ru-RU', 415 'options' => array( 416 'ru-RU' => esc_html__('Русский', 'woocommerce'), 417 'en-US' => esc_html__('Английский', 'woocommerce'), 418 'kk-KZ' => esc_html__('Казахский', 'woocommerce'), 419 ), 420 ), 421 'emailBehavior' => array( 422 'title' => __('Email на форме оплаты', 'woocommerce'), 423 'type' => 'select', 424 'class' => 'wc-enhanced-select', 425 'default' => 'Optional', 426 'options' => array( 427 'Required' => __('Обязательно', 'woocommerce'), 428 'Optional' => __('Опционально', 'woocommerce'), 429 'Hidden' => __('Скрыто', 'woocommerce'), 430 ), 431 ), 432 'paymentMethods' => array( 433 'title' => __('Количество платёжных методов вне кнопки “Другие способы”', 'woocommerce'), 434 'type' => 'text', 435 'description' => '', 436 ), 437 'enable_for_methods' => array( 438 'title' => esc_html__('Enable for shipping methods', 'woocommerce'), 439 'type' => 'multiselect', 440 'class' => 'wc-enhanced-select', 441 'css' => 'width: 400px;', 442 'default' => '', 443 'description' => esc_html__('Если TipTopPay доступен только для определенных методов доставки, выберите их здесь. Оставьте поле пустым, чтобы включить TipTopPay для всех методов доставки.', 'tiptoppay'), 444 'options' => $this->load_shipping_method_options(), 445 'desc_tip' => true, 446 'custom_attributes' => array( 447 'data-placeholder' => esc_html__('Select shipping methods', 'woocommerce'), 448 ), 449 ), 450 'kassa_section' => array( 451 'title' => esc_html__('Онлайн-касса', 'woocommerce'), 452 'type' => 'title', 453 'description' => '', 454 ), 455 'kassa_enabled' => array( 456 'title' => esc_html__('Enable/Disable', 'woocommerce'), 457 'type' => 'checkbox', 458 'label' => esc_html__('Включить отправку данных для онлайн-кассы', 'woocommerce'), 459 'default' => 'no' 460 ), 461 'inn' => array( 462 'title' => esc_html__('ИИН/БИН', 'woocommerce'), 463 'type' => 'text', 464 'description' => '', 465 'default' => '', 466 'desc_tip' => true, 467 ), 468 'kassa_taxtype' => array( 469 'title' => esc_html__('Ставка НДС', 'woocommerce'), 470 'type' => 'select', 471 'class' => 'wc-enhanced-select', 472 'description' => esc_html__('Выберите ставку НДС, которая применима к товарам в магазине.', 'woocommerce'), 473 'default' => '10', 474 'desc_tip' => true, 475 'options' => array( 476 'null' => esc_html__('НДС не облагается', 'woocommerce'), 477 '0' => esc_html__('НДС 0%', 'woocommerce'), 478 '12' => esc_html__('НДС 12%', 'woocommerce'), 479 ), 480 ), 481 'delivery_taxtype' => array( 482 'title' => esc_html__('Ставка НДС для доставки', 'woocommerce'), 483 'type' => 'select', 484 'class' => 'wc-enhanced-select', 485 'description' => esc_html__('Выберите ставку НДС, которая применима к доставке в магазине.', 'woocommerce'), 486 'default' => '10', 487 'desc_tip' => true, 488 'options' => array( 489 'null' => esc_html__('НДС не облагается', 'woocommerce'), 490 '0' => esc_html__('НДС 0%', 'woocommerce'), 491 '12' => esc_html__('НДС 12%', 'woocommerce'), 492 ), 493 ), 494 'kassa_taxsystem' => array( 495 'title' => esc_html__('Cистема налогообложения организации', 'woocommerce'), 496 'type' => 'select', 497 'class' => 'wc-enhanced-select', 498 'description' => esc_html__('Указанная система налогообложения должна совпадать с одним из вариантов, зарегистрированных в ККТ.', 'woocommerce'), 499 'default' => '1', 500 'desc_tip' => true, 501 'options' => array( 502 '0' => esc_html__('Общеустановленный режим налогообложения', 'woocommerce'), 503 '1' => esc_html__('СНР на основе упрощенной декларации', 'woocommerce'), 504 '4' => esc_html__('СНР на основе патента', 'woocommerce'), 505 ), 506 ), 507 'kassa_method' => array( 508 'title' => esc_html__('Способ расчета', 'woocommerce'), 509 'type' => 'select', 510 'class' => 'wc-enhanced-select', 511 'description' => esc_html__('Выберите способ расчета', 'woocommerce'), 512 'default' => '1', 513 'desc_tip' => true, 514 'options' => array( 515 '0' => esc_html__('Способ расчета не передается', 'woocommerce'), 516 '1' => esc_html__('Предоплата 100%', 'woocommerce'), 517 '2' => esc_html__('Предоплата', 'woocommerce'), 518 '3' => esc_html__('Аванс', 'woocommerce'), 519 '4' => esc_html__('Полный расчёт', 'woocommerce'), 520 '5' => esc_html__('Частичный расчёт и кредит', 'woocommerce'), 521 '6' => esc_html__('Передача в кредит', 'woocommerce'), 522 '7' => esc_html__('Оплата кредита', 'woocommerce'), 523 ), 524 ), 525 'kassa_object' => array( 526 'title' => esc_html__('Предмет расчета', 'woocommerce'), 527 'type' => 'select', 528 'class' => 'wc-enhanced-select', 529 'description' => esc_html__('Выберите предмет расчета', 'woocommerce'), 530 'default' => '1', 531 'desc_tip' => true, 532 'options' => array( 533 '0' => esc_html__('Предмет расчета не передается', 'woocommerce'), 534 '1' => esc_html__('Товар', 'woocommerce'), 535 '2' => esc_html__('Подакцизный товар', 'woocommerce'), 536 '3' => esc_html__('Работа', 'woocommerce'), 537 '4' => esc_html__('Услуга', 'woocommerce'), 538 '5' => esc_html__('Ставка азартной игры', 'woocommerce'), 539 '6' => esc_html__('Выигрыш азартной игры', 'woocommerce'), 540 '7' => esc_html__('Лотерейный билет', 'woocommerce'), 541 '8' => esc_html__('Выигрыш лотереи', 'woocommerce'), 542 '9' => esc_html__('Предоставление РИД', 'woocommerce'), 543 '10' => esc_html__('Платеж', 'woocommerce'), 544 '11' => esc_html__('Агентское вознаграждение', 'woocommerce'), 545 '12' => esc_html__('Составной предмет расчета', 'woocommerce'), 546 '13' => esc_html__('Иной предмет расчета', 'woocommerce'), 547 ), 548 ), 549 'status_delivered' => array( 550 'title' => esc_html__('Статус которым пробивать 2ой чек при отгрузке товара или выполнении услуги', 'woocommerce'), 551 'type' => 'select', 552 'class' => 'wc-enhanced-select', 553 'description' => '', 554 'default' => 'wc-pay_delivered', 555 'desc_tip' => true, 556 'options' => $array_status, 557 ), 558 'kassa_skubarcode' => array( 559 'title' => esc_html__('Действие со штрих-кодом', 'woocommerce'), 560 'type' => 'checkbox', 561 'label' => esc_html__('Отправлять артикул (SKU) товара как штрих-код', 'woocommerce'), 562 'default' => 'yes' 563 ), 292 <p>Кодировка UTF-8, HTTP-метод POST, Формат запроса TipTopPay.</p> 293 </div> 294 295 <?php 296 297 echo '<table class="form-table">'; 298 $this->generate_settings_html(); 299 echo '</table>'; 300 } 301 302 public function payment_fields() 303 { 304 if (is_account_page()) { 305 return; 306 } 307 require(TTPGWWC_PLUGIN_DIR . 'templates/payment-fields-checkout.php'); 308 } 309 310 public function get_vat_list() 311 { 312 $file = file_get_contents('https://static.tiptoppay.kz/receipt/dictionary-vat.json'); 313 $data = json_decode($file, true); 314 $vat_list = array(); 315 316 foreach ($data['Model'] as $item) { 317 if ($item['isActive']) { 318 $vat_list[$item['Value']] = $item['Name']; 319 } 320 } 321 322 return count($vat_list) ? $vat_list : array( 323 'null' => esc_html__('НДС не облагается', 'woocommerce'), 324 '0' => esc_html__('НДС 0%', 'woocommerce'), 325 '12' => esc_html__('НДС 12%', 'woocommerce'), 326 ); 327 } 328 329 public function init_form_fields() 330 { 331 $array_status = wc_get_order_statuses(); 332 $vat_list = $this->get_vat_list(); 333 $payment_methods = array( 334 'Card' => __('Оплата картой', 'woocommerce'), 335 'ApplePay' => __('Apple Pay', 'woocommerce'), 336 'GooglePay' => __('Google Pay', 'woocommerce'), 337 'InstallmentKz' => __('Рассрочка', 'woocommerce'), 338 ); 339 $this->form_fields = array( 340 'enabled' => array( 341 'title' => esc_html__('Enable/Disable', 'woocommerce'), 342 'type' => 'checkbox', 343 'label' => esc_html__('Включить TipTopPay', 'woocommerce'), 344 'default' => 'yes' 345 ), 346 'enabledDMS' => array( 347 'title' => esc_html__('Включить DMS', 'woocommerce'), 348 'type' => 'checkbox', 349 'label' => esc_html__('Включить DMS', 'woocommerce'), 350 'default' => 'no' 351 ), 352 'order_text' => array( 353 'title' => esc_html__('Текст оплаты заказа', 'woocommerce'), 354 'type' => 'text', 355 'default' => esc_html__('Оплата заказа:', 'woocommerce'), 356 'desc_tip' => true, 357 ), 358 'status_pay' => array( 359 'title' => esc_html__('Статус для оплаченного заказа', 'woocommerce'), 360 'type' => 'select', 361 'class' => 'wc-enhanced-select', 362 'description' => esc_html__('', 'woocommerce'), 363 'default' => 'wc-completed', 364 'desc_tip' => true, 365 'options' => $array_status, 366 ), 367 'status_chancel' => array( 368 'title' => esc_html__('Статус для отмененного заказа', 'woocommerce'), 369 'type' => 'select', 370 'class' => 'wc-enhanced-select', 371 'description' => esc_html__('', 'woocommerce'), 372 'default' => 'wc-cancelled', 373 'desc_tip' => true, 374 'options' => $array_status, 375 ), 376 'DMS_AU_status' => array( 377 'title' => esc_html__('Статус авторизованного платежа (DMS)', 'woocommerce'), 378 'type' => 'select', 379 'class' => 'wc-enhanced-select', 380 'description' => esc_html__('', 'woocommerce'), 381 'default' => 'wc-pay_au', 382 'desc_tip' => true, 383 'options' => $array_status, 384 ), 385 'title' => array( 386 'title' => esc_html__('Title', 'woocommerce'), 387 'type' => 'text', 388 'description' => esc_html__('This controls the title which the user sees during checkout.', 'woocommerce'), 389 'default' => esc_html__('Банковская карта', 'woocommerce'), 390 'desc_tip' => true, 391 ), 392 'description' => array( 393 'title' => esc_html__('Description', 'woocommerce'), 394 'type' => 'textarea', 395 'description' => esc_html__('Payment method description that the customer will see on your checkout.', 'woocommerce'), 396 'default' => esc_html__('TipTopPay – самый простой и удобный способ оплаты. Комиссий нет.', 'woocommerce'), 397 'desc_tip' => true, 398 ), 399 'public_id' => array( 400 'title' => esc_html__('Public ID', 'woocommerce'), 401 'type' => 'text', 402 'description' => 'Возьмите из личного кабинета TipTopPay', 403 'default' => '', 404 'desc_tip' => false, 405 ), 406 'api_pass' => array( 407 'title' => esc_html__('Пароль для API', 'woocommerce'), 408 'type' => 'text', 409 'description' => 'Возьмите из личного кабинета TipTopPay', 410 'default' => '', 411 'desc_tip' => false, 412 ), 413 'currency' => array( 414 'title' => esc_html__('Валюта магазина', 'woocommerce'), 415 'type' => 'select', 416 'class' => 'wc-enhanced-select', 417 'default' => 'KZT', 418 'options' => array( 419 'siteCurrency' => esc_html__('Валюта магазина', 'woocomerce'), 420 'RUB' => esc_html__('Российский рубль', 'woocommerce'), 421 'EUR' => esc_html__('Евро', 'woocommerce'), 422 'USD' => esc_html__('Доллар США', 'woocommerce'), 423 'KZT' => esc_html__('Казахский тенге', 'woocommerce'), 424 ), 425 ), 426 'skin' => array( 427 'title' => esc_html__('Дизайн виджета', 'woocommerce'), 428 'type' => 'select', 429 'class' => 'wc-enhanced-select', 430 'default' => 'classic', 431 'options' => array( 432 'classic' => esc_html__('Классический', 'woocommerce'), 433 'modern' => esc_html__('Модерн', 'woocommerce'), 434 'mini' => esc_html__('Мини', 'woocommerce'), 435 ), 436 ), 437 'paymentMethodSequenceOptions' => array( 438 'title' => __('Выберите методы оплаты для очередности отображения', 'woocommerce'), 439 'type' => 'select', 440 'class' => 'wc-enhanced-select', 441 'options' => $payment_methods 442 ), 443 'paymentMethodSequence' => array( 444 'title' => __('Очередность отображения методов оплаты', 'woocommerce'), 445 'type' => 'text', 446 'description' => __('Пожалуйста не редактируйте данное поле вручную.'), 447 ), 448 'restrictedPaymentMethods' => array( 449 'title' => __('Cписок отключенных методов оплаты', 'woocommerce'), 450 'type' => 'multiselect', 451 'class' => 'wc-enhanced-select', 452 'default' => 'ru-RU', 453 'options' => $payment_methods 454 ), 455 'language' => array( 456 'title' => esc_html__('Язык виджета', 'woocommerce'), 457 'type' => 'select', 458 'class' => 'wc-enhanced-select', 459 'default' => 'ru-RU', 460 'options' => array( 461 'ru-RU' => esc_html__('Русский', 'woocommerce'), 462 'en-US' => esc_html__('Английский', 'woocommerce'), 463 'kk-KZ' => esc_html__('Казахский', 'woocommerce'), 464 ), 465 ), 466 'emailBehavior' => array( 467 'title' => __('Email на форме оплаты', 'woocommerce'), 468 'type' => 'select', 469 'class' => 'wc-enhanced-select', 470 'default' => 'Optional', 471 'options' => array( 472 'Required' => __('Обязательно', 'woocommerce'), 473 'Optional' => __('Опционально', 'woocommerce'), 474 'Hidden' => __('Скрыто', 'woocommerce'), 475 ), 476 ), 477 'paymentMethods' => array( 478 'title' => __('Количество платёжных методов вне кнопки “Другие способы”', 'woocommerce'), 479 'type' => 'text', 480 'description' => '', 481 ), 482 'enable_for_methods' => array( 483 'title' => esc_html__('Enable for shipping methods', 'woocommerce'), 484 'type' => 'multiselect', 485 'class' => 'wc-enhanced-select', 486 'css' => 'width: 400px;', 487 'default' => '', 488 'description' => esc_html__('Если TipTopPay доступен только для определенных методов доставки, выберите их здесь. Оставьте поле пустым, чтобы включить TipTopPay для всех методов доставки.', 'tiptoppay'), 489 'options' => $this->load_shipping_method_options(), 490 'desc_tip' => true, 491 'custom_attributes' => array( 492 'data-placeholder' => esc_html__('Select shipping methods', 'woocommerce'), 493 ), 494 ), 495 'kassa_section' => array( 496 'title' => esc_html__('Онлайн-касса', 'woocommerce'), 497 'type' => 'title', 498 'description' => '', 499 ), 500 'kassa_enabled' => array( 501 'title' => esc_html__('Enable/Disable', 'woocommerce'), 502 'type' => 'checkbox', 503 'label' => esc_html__('Включить отправку данных для онлайн-кассы', 'woocommerce'), 504 'default' => 'no' 505 ), 506 'inn' => array( 507 'title' => esc_html__('ИИН/БИН', 'woocommerce'), 508 'type' => 'text', 509 'description' => '', 510 'default' => '', 511 'desc_tip' => true, 512 ), 513 'kassa_taxtype' => array( 514 'title' => esc_html__('Ставка НДС', 'woocommerce'), 515 'type' => 'select', 516 'class' => 'wc-enhanced-select', 517 'description' => esc_html__('Выберите ставку НДС, которая применима к товарам в магазине.', 'woocommerce'), 518 'default' => '10', 519 'desc_tip' => true, 520 'options' => $vat_list, 521 ), 522 'delivery_taxtype' => array( 523 'title' => esc_html__('Ставка НДС для доставки', 'woocommerce'), 524 'type' => 'select', 525 'class' => 'wc-enhanced-select', 526 'description' => esc_html__('Выберите ставку НДС, которая применима к доставке в магазине.', 'woocommerce'), 527 'default' => '10', 528 'desc_tip' => true, 529 'options' => $vat_list, 530 ), 531 'kassa_taxsystem' => array( 532 'title' => esc_html__('Cистема налогообложения организации', 'woocommerce'), 533 'type' => 'select', 534 'class' => 'wc-enhanced-select', 535 'description' => esc_html__('Указанная система налогообложения должна совпадать с одним из вариантов, зарегистрированных в ККТ.', 'woocommerce'), 536 'default' => '1', 537 'desc_tip' => true, 538 'options' => array( 539 '0' => esc_html__('Общеустановленный режим налогообложения', 'woocommerce'), 540 '1' => esc_html__('СНР на основе упрощенной декларации', 'woocommerce'), 541 '4' => esc_html__('СНР на основе патента', 'woocommerce'), 542 ), 543 ), 544 'kassa_method' => array( 545 'title' => esc_html__('Способ расчета', 'woocommerce'), 546 'type' => 'select', 547 'class' => 'wc-enhanced-select', 548 'description' => esc_html__('Выберите способ расчета', 'woocommerce'), 549 'default' => '1', 550 'desc_tip' => true, 551 'options' => array( 552 '0' => esc_html__('Способ расчета не передается', 'woocommerce'), 553 '1' => esc_html__('Предоплата 100%', 'woocommerce'), 554 '2' => esc_html__('Предоплата', 'woocommerce'), 555 '3' => esc_html__('Аванс', 'woocommerce'), 556 '4' => esc_html__('Полный расчёт', 'woocommerce'), 557 '5' => esc_html__('Частичный расчёт и кредит', 'woocommerce'), 558 '6' => esc_html__('Передача в кредит', 'woocommerce'), 559 '7' => esc_html__('Оплата кредита', 'woocommerce'), 560 ), 561 ), 562 'kassa_object' => array( 563 'title' => esc_html__('Предмет расчета', 'woocommerce'), 564 'type' => 'select', 565 'class' => 'wc-enhanced-select', 566 'description' => esc_html__('Выберите предмет расчета', 'woocommerce'), 567 'default' => '1', 568 'desc_tip' => true, 569 'options' => array( 570 '0' => esc_html__('Предмет расчета не передается', 'woocommerce'), 571 '1' => esc_html__('Товар', 'woocommerce'), 572 '2' => esc_html__('Подакцизный товар', 'woocommerce'), 573 '3' => esc_html__('Работа', 'woocommerce'), 574 '4' => esc_html__('Услуга', 'woocommerce'), 575 '5' => esc_html__('Ставка азартной игры', 'woocommerce'), 576 '6' => esc_html__('Выигрыш азартной игры', 'woocommerce'), 577 '7' => esc_html__('Лотерейный билет', 'woocommerce'), 578 '8' => esc_html__('Выигрыш лотереи', 'woocommerce'), 579 '9' => esc_html__('Предоставление РИД', 'woocommerce'), 580 '10' => esc_html__('Платеж', 'woocommerce'), 581 '11' => esc_html__('Агентское вознаграждение', 'woocommerce'), 582 '12' => esc_html__('Составной предмет расчета', 'woocommerce'), 583 '13' => esc_html__('Иной предмет расчета', 'woocommerce'), 584 ), 585 ), 586 'status_delivered' => array( 587 'title' => esc_html__('Статус которым пробивать 2ой чек при отгрузке товара или выполнении услуги', 'woocommerce'), 588 'type' => 'select', 589 'class' => 'wc-enhanced-select', 590 'description' => '', 591 'default' => 'wc-pay_delivered', 592 'desc_tip' => true, 593 'options' => $array_status, 594 ), 595 'kassa_skubarcode' => array( 596 'title' => esc_html__('Действие со штрих-кодом', 'woocommerce'), 597 'type' => 'checkbox', 598 'label' => esc_html__('Отправлять артикул (SKU) товара как штрих-код', 'woocommerce'), 599 'default' => 'yes' 600 ), 564 601 // 'shipping_spic' => array( 565 602 // 'title' => esc_html__('Код ИКПУ доставки', 'woocommerce'), … … 574 611 // 'default' => '', 575 612 // ) 576 ); 613 ); 614 } 615 616 public function ssl_check() 617 { 618 if (get_option('woocommerce_force_ssl_checkout') == 'no' && $this->enabled == 'yes') { 619 $this->msg = sprintf(esc_html__('Включена поддержка оплаты через TipTopPay и не активирована опция <a href="%s">"Принудительная защита оформления заказа"</a>; безопасность заказов находится под угрозой! Пожалуйста, включите SSL и проверьте корректность установленных сертификатов.', 'woocommerce'), admin_url('admin.php?page=wc-settings&tab=checkout')); 620 $this->enabled = false; 621 622 return false; 623 } 624 625 return true; 626 } 627 628 public function update_order_status($order_id, $old_status, $new_status) 629 { 630 if ($this->kassa_enabled == 'yes') { 631 global $woocommerce; 632 $order = new WC_Order($order_id); 633 if ("wc-" . $new_status == $this->status_delivered && ((int)$this->kassa_method == 1 || (int)$this->kassa_method == 2 || (int)$this->kassa_method == 3)) { 634 $this->send_receipt($order, 'Income', $old_status, $new_status); 635 } 636 } 637 } 638 639 public function send_receipt($order, $type, $old_status, $new_status) 640 { 641 $cart = $order->get_items(); 642 $total_amount = 0; 643 644 foreach ($cart as $item_data) { 645 $product = $item_data->get_product(); 646 if ("wc-" . $new_status == $this->status_delivered) { 647 $method = 4; 648 } else { 649 $method = (int)$this->kassa_method; 650 } 651 $items[] = apply_filters( 652 'tiptoppay_send_receipt_item', 653 array( 654 'label' => $product->get_name(), 655 'price' => number_format($product->get_price(), 2, '.', ''), 656 'quantity' => $item_data->get_quantity(), 657 'amount' => number_format(floatval($item_data->get_total()), 2, '.', ''), 658 'vat' => $this->kassa_taxtype, 659 'method' => $method, 660 'object' => (int)$this->kassa_object, 661 ), 662 $product, 663 $item_id, 664 $item_data, 665 $method, 666 $this 667 ); 668 669 $total_amount = $total_amount + number_format(floatval($item_data->get_total()), 2, ".", ''); 670 } 671 672 if ($order->get_total_shipping()) { 673 $items[] = apply_filters( 674 'tiptoppay_send_receipt_shipping_data', 675 array( 676 'label' => 'Доставка', 677 'price' => $order->get_total_shipping(), 678 'quantity' => 1, 679 'amount' => $order->get_total_shipping(), 680 'vat' => $this->delivery_taxtype, 681 'method' => $method, 682 'object' => 4, 683 ), 684 $order, 685 $this 686 ); 687 688 $total_amount = $total_amount + number_format(floatval($order->get_total_shipping()), 2, ".", ''); 689 } 690 691 $data['Items'] = $items; 692 $data['taxationSystem'] = $this->kassa_taxsystem; 693 $data['calculationPlace'] = 'www.' . sanitize_text_field($_SERVER['SERVER_NAME']); 694 $data['email'] = $order->get_billing_email(); 695 $data['phone'] = $order->get_billing_phone(); 696 $data['amounts']['electronic'] = $total_amount; 697 698 if ("wc-" . $new_status == $this->status_delivered) { 699 $data['amounts']['electronic'] = 0; 700 $data['amounts']['advancePayment'] = $total_amount; 701 } 702 703 $aData = apply_filters( 704 'tiptoppay_send_receipt_data', 705 array( 706 'Inn' => $this->inn, 707 'InvoiceId' => $order->get_id(), // номер заказа, необязательный. 708 'AccountId' => $order->get_user_id(), 709 'Type' => $type, 710 'CustomerReceipt' => $data, 711 ), 712 $order, 713 $this 714 ); 715 716 $API_URL = 'https://api.tiptoppay.kz/kkt/receipt'; 717 $request2 = json_encode($aData); 718 719 $str = date("d-m-Y H:i:s") . $aData['Type'] . $aData['InvoiceId'] . $aData['AccountId'] . $aData['CustomerReceipt']['email']; 720 $reque = md5($str); 721 $auth = base64_encode($this->public_id . ":" . $this->api_pass); 722 723 wp_remote_post($API_URL, array( 724 'timeout' => 30, 725 'redirection' => 5, 726 'httpversion' => '1.0', 727 'blocking' => true, 728 'headers' => array('Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json', 'X-Request-ID' => $reque), 729 'body' => $request2, 730 'cookies' => array() 731 )); 732 } 733 734 public function scheduled_subscription_payment($amount_to_charge, $order) 735 { 736 global $woocommerce; 737 $order_id = $order->get_id(); 738 $title = array(); 739 $items_array = array(); 740 $items = $order->get_items(); 741 $shipping_data = apply_filters( 742 'tiptoppay_scheduled_subscription_payment_shipping_data', 743 array( 744 'label' => 'Доставка', 745 'price' => number_format((float)$order->get_total_shipping() + abs((float)$order->get_shipping_tax()), 2, '.', ''), 746 'quantity' => '1.00', 747 'amount' => number_format((float)$order->get_total_shipping() + abs((float)$order->get_shipping_tax()), 2, '.', ''), 748 'vat' => ('null' == $this->delivery_taxtype) ? null : $this->delivery_taxtype, 749 'method' => (int)$this->kassa_method, 750 'object' => 4, 751 'ean' => null, 752 ), 753 $order, 754 $this 755 ); 756 757 foreach ($items as $item) { 758 if ($this->kassa_enabled == 'yes') { 759 $product = $order->get_product_from_item($item); 760 $items_array[] = apply_filters( 761 'tiptoppay_scheduled_subscription_payment_order_item', 762 array( 763 'label' => $item['name'], 764 'price' => number_format((float)$product->get_price(), 2, '.', ''), 765 'quantity' => number_format((float)$item['quantity'], 2, '.', ''), 766 'amount' => number_format((float)$item['total'] + abs((float)$item['total_tax']), 2, '.', ''), 767 'vat' => ('null' == $this->kassa_taxtype) ? null : $this->kassa_taxtype, 768 'method' => (int)$this->kassa_method, 769 'object' => (int)$this->kassa_object, 770 'ean' => ('yes' == $this->kassa_skubarcode) ? ((strlen($product->get_sku()) < 1) ? null : $product->get_sku()) : null, 771 ), 772 $product, 773 $item_id, 774 $item, 775 $this 776 ); 777 } 778 $title[] = $item['name'] . (isset($item['pa_ver']) ? ' ' . $item['pa_ver'] : ''); 779 } 780 if ($this->kassa_enabled == 'yes' && $order->get_total_shipping() > 0) { 781 $items_array[] = $shipping_data; 782 } 783 $kassa_array = array( 784 "PaymentData" => (array( 785 "customerReceipt" => array( 786 "Items" => $items_array, 787 "taxationSystem" => $this->kassa_taxsystem, 788 'calculationPlace' => 'www.' . sanitize_text_field($_SERVER['SERVER_NAME']), 789 "email" => $order->get_billing_email(), 790 "phone" => $order->get_billing_phone() 791 ) 792 )) 793 ); 794 $title = implode(', ', $title); 795 796 $widget_f = 'charge'; 797 if ($this->enabledDMS != 'no') { 798 $widget_f = 'auth'; 799 } 800 801 $user_id = $order->get_user_id(); 802 $tokens = WC_Payment_Tokens::get_customer_tokens($user_id, 'wc_tiptoppay_gateway'); 803 804 if (!empty($tokens)): 805 $default = array_filter($tokens, function ($t) { 806 $t->is_default(); 807 }); 808 $token = count($default) 809 ? array_shift($default) 810 : array_pop($tokens); 811 endif; 812 813 if (isset($token)) { 814 $request = array( 815 'Token' => $token->get_token(), 816 'Amount' => $order->get_total(), 817 'Currency' => $this->currency, 818 'InvoiceId' => $order->get_id(), 819 'AccountId' => $user_id, 820 'TrInitiatorCode' => 0, 821 'Email' => $order->get_billing_email(), 822 'Description' => 'Оплата заказа № ' . $order_id, 823 'IpAddress' => sanitize_text_field($_SERVER['REMOTE_ADDR']), 824 ); 825 826 if ($this->kassa_enabled == 'yes') { 827 $request['JsonData'] = $kassa_array; 828 } 829 830 $auth = base64_encode($this->public_id . ":" . $this->api_pass); 831 $response = wp_remote_post('https://api.tiptoppay.kz/payments/tokens/' . $widget_f, 832 array( 833 'timeout' => 30, 834 'redirection' => 5, 835 'httpversion' => '1.0', 836 'blocking' => true, 837 'headers' => array('Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json'), 838 'body' => json_encode($request, JSON_UNESCAPED_UNICODE) 839 ) 840 ); 841 842 $response['body'] = json_decode($response['body'], true); 843 844 if ($response['body']['Success'] == true) { 845 $order->payment_complete(); 846 $order->add_order_note(sprintf('Payment approved (TransactionID: %s)', $response['body']['Model']['TransactionId'])); 847 return; 848 } else { 849 $pattern = '(ReasonCode: %d), %s '; 850 $order->add_order_note(wp_sprintf($pattern, $response['body']['Model']['ReasonCode'], $response['body']['Model']['Reason'])); 851 } 852 853 if ($response['body']['Message'] != null || $response['body']['Model']['CardHolderMessage'] != null) { 854 WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order->get_id()); 855 $order->update_status('failed', sprintf(esc_html__('Error: %s', 'woocommerce'), $response['body']['Message'])); 856 } 857 858 } 859 860 } 861 862 /** 863 * Check If The Gateway Is Available For Use. 864 * 865 * @return bool 866 */ 867 public function is_available() 868 { 869 $order = null; 870 $needs_shipping = false; 871 872 // Test if shipping is needed first. 873 if (WC()->cart && WC()->cart->needs_shipping()) { 874 $needs_shipping = true; 875 } elseif (is_page(wc_get_page_id('checkout')) && 0 < get_query_var('order-pay')) { 876 $order_id = absint(get_query_var('order-pay')); 877 $order = wc_get_order($order_id); 878 879 // Test if order needs shipping. 880 if ($order && 0 < count($order->get_items())) { 881 foreach ($order->get_items() as $item) { 882 $_product = $item->get_product(); 883 if ($_product && $_product->needs_shipping()) { 884 $needs_shipping = true; 885 break; 886 } 887 } 888 } 889 } 890 891 $needs_shipping = apply_filters('woocommerce_cart_needs_shipping', $needs_shipping); 892 893 // Only apply if all packages are being shipped via chosen method. 894 if (!empty($this->enable_for_methods) && $needs_shipping) { 895 $order_shipping_items = is_object($order) ? $order->get_shipping_methods() : false; 896 $chosen_shipping_methods_session = WC()->session->get('chosen_shipping_methods'); 897 898 if ($order_shipping_items) { 899 $canonical_rate_ids = $this->get_canonical_order_shipping_item_rate_ids($order_shipping_items); 900 } else { 901 $canonical_rate_ids = $this->get_canonical_package_rate_ids($chosen_shipping_methods_session); 902 } 903 904 if (!count($this->get_matching_rates($canonical_rate_ids))) { 905 return false; 906 } 907 } 908 909 return parent::is_available(); 910 } 911 912 /** 913 * Checks to see whether or not the admin settings are being accessed by the current request. 914 * 915 * @return bool 916 */ 917 private function is_accessing_settings() 918 { 919 if (is_admin()) { 920 // phpcs:disable WordPress.Security.NonceVerification 921 if (!isset($_REQUEST['page']) || 'wc-settings' !== $_REQUEST['page']) { 922 return false; 923 } 924 if (!isset($_REQUEST['tab']) || 'checkout' !== $_REQUEST['tab']) { 925 return false; 926 } 927 if (!isset($_REQUEST['section']) || 'wc_tiptoppay_gateway' !== $_REQUEST['section']) { 928 return false; 929 } 930 // phpcs:enable WordPress.Security.NonceVerification 931 932 return true; 933 } 934 935 if (Constants::is_true('REST_REQUEST')) { 936 global $wp; 937 if (isset($wp->query_vars['rest_route']) && false !== strpos($wp->query_vars['rest_route'], '/payment_gateways')) { 938 return true; 939 } 940 } 941 942 return false; 943 } 944 945 /** 946 * Loads all of the shipping method options for the enable_for_methods field. 947 * 948 * @return array 949 */ 950 private function load_shipping_method_options() 951 { 952 // Since this is expensive, we only want to do it if we're actually on the settings page. 953 if (!$this->is_accessing_settings()) { 954 return array(); 955 } 956 957 $data_store = WC_Data_Store::load('shipping-zone'); 958 $raw_zones = $data_store->get_zones(); 959 960 foreach ($raw_zones as $raw_zone) { 961 $zones[] = new WC_Shipping_Zone($raw_zone); 962 } 963 964 $zones[] = new WC_Shipping_Zone(0); 965 966 $options = array(); 967 foreach (WC()->shipping()->load_shipping_methods() as $method) { 968 969 $options[$method->get_method_title()] = array(); 970 971 // Translators: %1$s shipping method name. 972 $options[$method->get_method_title()][$method->id] = sprintf(esc_html__('Any "%1$s" method', 'woocommerce'), $method->get_method_title()); 973 974 foreach ($zones as $zone) { 975 976 $shipping_method_instances = $zone->get_shipping_methods(); 977 978 foreach ($shipping_method_instances as $shipping_method_instance_id => $shipping_method_instance) { 979 980 if ($shipping_method_instance->id !== $method->id) { 981 continue; 982 } 983 984 $option_id = $shipping_method_instance->get_rate_id(); 985 986 // Translators: %1$s shipping method title, %2$s shipping method id. 987 $option_instance_title = sprintf(esc_html__('%1$s (#%2$s)', 'woocommerce'), $shipping_method_instance->get_title(), $shipping_method_instance_id); 988 989 // Translators: %1$s zone name, %2$s shipping method instance name. 990 $option_title = sprintf(esc_html__('%1$s – %2$s', 'woocommerce'), $zone->get_id() ? $zone->get_zone_name() : esc_html__('Other locations', 'woocommerce'), $option_instance_title); 991 992 $options[$method->get_method_title()][$option_id] = $option_title; 993 } 994 } 995 } 996 997 return $options; 998 } 999 1000 /** 1001 * Converts the chosen rate IDs generated by Shipping Methods to a canonical 'method_id:instance_id' format. 1002 * 1003 * @param array $order_shipping_items Array of WC_Order_Item_Shipping objects. 1004 * @return array $canonical_rate_ids Rate IDs in a canonical format. 1005 * @since 3.4.0 1006 * 1007 */ 1008 private function get_canonical_order_shipping_item_rate_ids($order_shipping_items) 1009 { 1010 1011 $canonical_rate_ids = array(); 1012 1013 foreach ($order_shipping_items as $order_shipping_item) { 1014 $canonical_rate_ids[] = $order_shipping_item->get_method_id() . ':' . $order_shipping_item->get_instance_id(); 1015 } 1016 1017 return $canonical_rate_ids; 1018 } 1019 1020 /** 1021 * Converts the chosen rate IDs generated by Shipping Methods to a canonical 'method_id:instance_id' format. 1022 * 1023 * @param array $chosen_package_rate_ids Rate IDs as generated by shipping methods. Can be anything if a shipping method doesn't honor WC conventions. 1024 * @return array $canonical_rate_ids Rate IDs in a canonical format. 1025 * @since 3.4.0 1026 * 1027 */ 1028 private function get_canonical_package_rate_ids($chosen_package_rate_ids) 1029 { 1030 1031 $shipping_packages = WC()->shipping()->get_packages(); 1032 $canonical_rate_ids = array(); 1033 1034 if (!empty($chosen_package_rate_ids) && is_array($chosen_package_rate_ids)) { 1035 foreach ($chosen_package_rate_ids as $package_key => $chosen_package_rate_id) { 1036 if (!empty($shipping_packages[$package_key]['rates'][$chosen_package_rate_id])) { 1037 $chosen_rate = $shipping_packages[$package_key]['rates'][$chosen_package_rate_id]; 1038 $canonical_rate_ids[] = $chosen_rate->get_method_id() . ':' . $chosen_rate->get_instance_id(); 1039 } 1040 } 1041 } 1042 1043 return $canonical_rate_ids; 1044 } 1045 1046 /** 1047 * Indicates whether a rate exists in an array of canonically-formatted rate IDs that activates this gateway. 1048 * 1049 * @param array $rate_ids Rate ids to check. 1050 * @return boolean 1051 * @since 3.4.0 1052 * 1053 */ 1054 private function get_matching_rates($rate_ids) 1055 { 1056 // First, match entries in 'method_id:instance_id' format. Then, match entries in 'method_id' format by stripping off the instance ID from the candidates. 1057 return array_unique(array_merge(array_intersect($this->enable_for_methods, $rate_ids), array_intersect($this->enable_for_methods, array_unique(array_map('wc_get_string_before_colon', $rate_ids))))); 1058 } 1059 577 1060 } 578 579 public function ssl_check()580 {581 if (get_option('woocommerce_force_ssl_checkout') == 'no' && $this->enabled == 'yes') {582 $this->msg = sprintf(esc_html__('Включена поддержка оплаты через TipTopPay и не активирована опция <a href="%s">"Принудительная защита оформления заказа"</a>; безопасность заказов находится под угрозой! Пожалуйста, включите SSL и проверьте корректность установленных сертификатов.', 'woocommerce'), admin_url('admin.php?page=wc-settings&tab=checkout'));583 $this->enabled = false;584 585 return false;586 }587 588 return true;589 }590 591 public function update_order_status($order_id, $old_status, $new_status)592 {593 if ($this->kassa_enabled == 'yes') {594 global $woocommerce;595 $order = new WC_Order($order_id);596 if ("wc-" . $new_status == $this->status_delivered && ((int)$this->kassa_method == 1 || (int)$this->kassa_method == 2 || (int)$this->kassa_method == 3)) {597 $this->send_receipt($order, 'Income', $old_status, $new_status);598 }599 }600 }601 602 public function send_receipt($order, $type, $old_status, $new_status)603 {604 $cart = $order->get_items();605 $total_amount = 0;606 607 foreach ($cart as $item_data) {608 $product = $item_data->get_product();609 if ("wc-" . $new_status == $this->status_delivered) {610 $method = 4;611 } else {612 $method = (int)$this->kassa_method;613 }614 $items[] = apply_filters(615 'tiptoppay_send_receipt_item',616 array(617 'label' => $product->get_name(),618 'price' => number_format($product->get_price(), 2, '.', ''),619 'quantity' => $item_data->get_quantity(),620 'amount' => number_format(floatval($item_data->get_total()), 2, '.', ''),621 'vat' => $this->kassa_taxtype,622 'method' => $method,623 'object' => (int)$this->kassa_object,624 ),625 $product,626 $item_id,627 $item_data,628 $method,629 $this630 );631 632 $total_amount = $total_amount + number_format(floatval($item_data->get_total()), 2, ".", '');633 }634 635 if ($order->get_total_shipping()) {636 $items[] = apply_filters(637 'tiptoppay_send_receipt_shipping_data',638 array(639 'label' => 'Доставка',640 'price' => $order->get_total_shipping(),641 'quantity' => 1,642 'amount' => $order->get_total_shipping(),643 'vat' => $this->delivery_taxtype,644 'method' => $method,645 'object' => 4,646 ),647 $order,648 $this649 );650 651 $total_amount = $total_amount + number_format(floatval($order->get_total_shipping()), 2, ".", '');652 }653 654 $data['Items'] = $items;655 $data['taxationSystem'] = $this->kassa_taxsystem;656 $data['calculationPlace'] = 'www.' . sanitize_text_field($_SERVER['SERVER_NAME']);657 $data['email'] = $order->get_billing_email();658 $data['phone'] = $order->get_billing_phone();659 $data['amounts']['electronic'] = $total_amount;660 661 if ("wc-" . $new_status == $this->status_delivered) {662 $data['amounts']['electronic'] = 0;663 $data['amounts']['advancePayment'] = $total_amount;664 }665 666 $aData = apply_filters(667 'tiptoppay_send_receipt_data',668 array(669 'Inn' => $this->inn,670 'InvoiceId' => $order->get_id(), // номер заказа, необязательный.671 'AccountId' => $order->get_user_id(),672 'Type' => $type,673 'CustomerReceipt' => $data,674 ),675 $order,676 $this677 );678 679 $API_URL = 'https://api.tiptoppay.kz/kkt/receipt';680 $request2 = json_encode($aData);681 682 $str = date("d-m-Y H:i:s") . $aData['Type'] . $aData['InvoiceId'] . $aData['AccountId'] . $aData['CustomerReceipt']['email'];683 $reque = md5($str);684 $auth = base64_encode($this->public_id . ":" . $this->api_pass);685 686 wp_remote_post($API_URL, array(687 'timeout' => 30,688 'redirection' => 5,689 'httpversion' => '1.0',690 'blocking' => true,691 'headers' => array('Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json', 'X-Request-ID' => $reque),692 'body' => $request2,693 'cookies' => array()694 ));695 }696 697 public function scheduled_subscription_payment($amount_to_charge, $order)698 {699 global $woocommerce;700 $order_id = $order->get_id();701 $title = array();702 $items_array = array();703 $items = $order->get_items();704 $shipping_data = apply_filters(705 'tiptoppay_scheduled_subscription_payment_shipping_data',706 array(707 'label' => 'Доставка',708 'price' => number_format((float)$order->get_total_shipping() + abs((float)$order->get_shipping_tax()), 2, '.', ''),709 'quantity' => '1.00',710 'amount' => number_format((float)$order->get_total_shipping() + abs((float)$order->get_shipping_tax()), 2, '.', ''),711 'vat' => ('null' == $this->delivery_taxtype) ? null : $this->delivery_taxtype,712 'method' => (int)$this->kassa_method,713 'object' => 4,714 'ean' => null,715 ),716 $order,717 $this718 );719 720 foreach ($items as $item) {721 if ($this->kassa_enabled == 'yes') {722 $product = $order->get_product_from_item($item);723 $items_array[] = apply_filters(724 'tiptoppay_scheduled_subscription_payment_order_item',725 array(726 'label' => $item['name'],727 'price' => number_format((float)$product->get_price(), 2, '.', ''),728 'quantity' => number_format((float)$item['quantity'], 2, '.', ''),729 'amount' => number_format((float)$item['total'] + abs((float)$item['total_tax']), 2, '.', ''),730 'vat' => ('null' == $this->kassa_taxtype) ? null : $this->kassa_taxtype,731 'method' => (int)$this->kassa_method,732 'object' => (int)$this->kassa_object,733 'ean' => ('yes' == $this->kassa_skubarcode) ? ((strlen($product->get_sku()) < 1) ? null : $product->get_sku()) : null,734 ),735 $product,736 $item_id,737 $item,738 $this739 );740 }741 $title[] = $item['name'] . (isset($item['pa_ver']) ? ' ' . $item['pa_ver'] : '');742 }743 if ($this->kassa_enabled == 'yes' && $order->get_total_shipping() > 0) {744 $items_array[] = $shipping_data;745 }746 $kassa_array = array(747 "PaymentData" => (array(748 "customerReceipt" => array(749 "Items" => $items_array,750 "taxationSystem" => $this->kassa_taxsystem,751 'calculationPlace' => 'www.' . sanitize_text_field($_SERVER['SERVER_NAME']),752 "email" => $order->get_billing_email(),753 "phone" => $order->get_billing_phone()754 )755 ))756 );757 $title = implode(', ', $title);758 759 $widget_f = 'charge';760 if ($this->enabledDMS != 'no') {761 $widget_f = 'auth';762 }763 764 $user_id = $order->get_user_id();765 $tokens = WC_Payment_Tokens::get_customer_tokens($user_id, 'wc_tiptoppay_gateway');766 767 if (!empty($tokens)):768 $default = array_filter($tokens, function ($t) {769 $t->is_default();770 });771 $token = count($default)772 ? array_shift($default)773 : array_pop($tokens);774 endif;775 776 if (isset($token)) {777 $request = array(778 'Token' => $token->get_token(),779 'Amount' => $order->get_total(),780 'Currency' => $this->currency,781 'InvoiceId' => $order->get_id(),782 'AccountId' => $user_id,783 'TrInitiatorCode' => 0,784 'Email' => $order->get_billing_email(),785 'Description' => 'Оплата заказа № ' . $order_id,786 'IpAddress' => sanitize_text_field($_SERVER['REMOTE_ADDR']),787 );788 789 if ($this->kassa_enabled == 'yes') {790 $request['JsonData'] = $kassa_array;791 }792 793 $auth = base64_encode($this->public_id . ":" . $this->api_pass);794 $response = wp_remote_post('https://api.tiptoppay.kz/payments/tokens/' . $widget_f,795 array(796 'timeout' => 30,797 'redirection' => 5,798 'httpversion' => '1.0',799 'blocking' => true,800 'headers' => array('Authorization' => 'Basic ' . $auth, 'Content-Type' => 'application/json'),801 'body' => json_encode($request, JSON_UNESCAPED_UNICODE)802 )803 );804 805 $response['body'] = json_decode($response['body'], true);806 807 if ($response['body']['Success'] == true) {808 $order->payment_complete();809 $order->add_order_note(sprintf('Payment approved (TransactionID: %s)', $response['body']['Model']['TransactionId']));810 return;811 } else {812 $pattern = '(ReasonCode: %d), %s ';813 $order->add_order_note(wp_sprintf($pattern, $response['body']['Model']['ReasonCode'], $response['body']['Model']['Reason']));814 }815 816 if ($response['body']['Message'] != null || $response['body']['Model']['CardHolderMessage'] != null) {817 WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order->get_id());818 $order->update_status('failed', sprintf(esc_html__('Error: %s', 'woocommerce'), $response['body']['Message']));819 }820 821 }822 823 }824 825 /**826 * Check If The Gateway Is Available For Use.827 *828 * @return bool829 */830 public function is_available()831 {832 $order = null;833 $needs_shipping = false;834 835 // Test if shipping is needed first.836 if (WC()->cart && WC()->cart->needs_shipping()) {837 $needs_shipping = true;838 } elseif (is_page(wc_get_page_id('checkout')) && 0 < get_query_var('order-pay')) {839 $order_id = absint(get_query_var('order-pay'));840 $order = wc_get_order($order_id);841 842 // Test if order needs shipping.843 if ($order && 0 < count($order->get_items())) {844 foreach ($order->get_items() as $item) {845 $_product = $item->get_product();846 if ($_product && $_product->needs_shipping()) {847 $needs_shipping = true;848 break;849 }850 }851 }852 }853 854 $needs_shipping = apply_filters('woocommerce_cart_needs_shipping', $needs_shipping);855 856 // Only apply if all packages are being shipped via chosen method.857 if (!empty($this->enable_for_methods) && $needs_shipping) {858 $order_shipping_items = is_object($order) ? $order->get_shipping_methods() : false;859 $chosen_shipping_methods_session = WC()->session->get('chosen_shipping_methods');860 861 if ($order_shipping_items) {862 $canonical_rate_ids = $this->get_canonical_order_shipping_item_rate_ids($order_shipping_items);863 } else {864 $canonical_rate_ids = $this->get_canonical_package_rate_ids($chosen_shipping_methods_session);865 }866 867 if (!count($this->get_matching_rates($canonical_rate_ids))) {868 return false;869 }870 }871 872 return parent::is_available();873 }874 875 /**876 * Checks to see whether or not the admin settings are being accessed by the current request.877 *878 * @return bool879 */880 private function is_accessing_settings()881 {882 if (is_admin()) {883 // phpcs:disable WordPress.Security.NonceVerification884 if (!isset($_REQUEST['page']) || 'wc-settings' !== $_REQUEST['page']) {885 return false;886 }887 if (!isset($_REQUEST['tab']) || 'checkout' !== $_REQUEST['tab']) {888 return false;889 }890 if (!isset($_REQUEST['section']) || 'wc_tiptoppay_gateway' !== $_REQUEST['section']) {891 return false;892 }893 // phpcs:enable WordPress.Security.NonceVerification894 895 return true;896 }897 898 if (Constants::is_true('REST_REQUEST')) {899 global $wp;900 if (isset($wp->query_vars['rest_route']) && false !== strpos($wp->query_vars['rest_route'], '/payment_gateways')) {901 return true;902 }903 }904 905 return false;906 }907 908 /**909 * Loads all of the shipping method options for the enable_for_methods field.910 *911 * @return array912 */913 private function load_shipping_method_options()914 {915 // Since this is expensive, we only want to do it if we're actually on the settings page.916 if (!$this->is_accessing_settings()) {917 return array();918 }919 920 $data_store = WC_Data_Store::load('shipping-zone');921 $raw_zones = $data_store->get_zones();922 923 foreach ($raw_zones as $raw_zone) {924 $zones[] = new WC_Shipping_Zone($raw_zone);925 }926 927 $zones[] = new WC_Shipping_Zone(0);928 929 $options = array();930 foreach (WC()->shipping()->load_shipping_methods() as $method) {931 932 $options[$method->get_method_title()] = array();933 934 // Translators: %1$s shipping method name.935 $options[$method->get_method_title()][$method->id] = sprintf(esc_html__('Any "%1$s" method', 'woocommerce'), $method->get_method_title());936 937 foreach ($zones as $zone) {938 939 $shipping_method_instances = $zone->get_shipping_methods();940 941 foreach ($shipping_method_instances as $shipping_method_instance_id => $shipping_method_instance) {942 943 if ($shipping_method_instance->id !== $method->id) {944 continue;945 }946 947 $option_id = $shipping_method_instance->get_rate_id();948 949 // Translators: %1$s shipping method title, %2$s shipping method id.950 $option_instance_title = sprintf(esc_html__('%1$s (#%2$s)', 'woocommerce'), $shipping_method_instance->get_title(), $shipping_method_instance_id);951 952 // Translators: %1$s zone name, %2$s shipping method instance name.953 $option_title = sprintf(esc_html__('%1$s – %2$s', 'woocommerce'), $zone->get_id() ? $zone->get_zone_name() : esc_html__('Other locations', 'woocommerce'), $option_instance_title);954 955 $options[$method->get_method_title()][$option_id] = $option_title;956 }957 }958 }959 960 return $options;961 }962 963 /**964 * Converts the chosen rate IDs generated by Shipping Methods to a canonical 'method_id:instance_id' format.965 *966 * @param array $order_shipping_items Array of WC_Order_Item_Shipping objects.967 * @return array $canonical_rate_ids Rate IDs in a canonical format.968 * @since 3.4.0969 *970 */971 private function get_canonical_order_shipping_item_rate_ids($order_shipping_items)972 {973 974 $canonical_rate_ids = array();975 976 foreach ($order_shipping_items as $order_shipping_item) {977 $canonical_rate_ids[] = $order_shipping_item->get_method_id() . ':' . $order_shipping_item->get_instance_id();978 }979 980 return $canonical_rate_ids;981 }982 983 /**984 * Converts the chosen rate IDs generated by Shipping Methods to a canonical 'method_id:instance_id' format.985 *986 * @param array $chosen_package_rate_ids Rate IDs as generated by shipping methods. Can be anything if a shipping method doesn't honor WC conventions.987 * @return array $canonical_rate_ids Rate IDs in a canonical format.988 * @since 3.4.0989 *990 */991 private function get_canonical_package_rate_ids($chosen_package_rate_ids)992 {993 994 $shipping_packages = WC()->shipping()->get_packages();995 $canonical_rate_ids = array();996 997 if (!empty($chosen_package_rate_ids) && is_array($chosen_package_rate_ids)) {998 foreach ($chosen_package_rate_ids as $package_key => $chosen_package_rate_id) {999 if (!empty($shipping_packages[$package_key]['rates'][$chosen_package_rate_id])) {1000 $chosen_rate = $shipping_packages[$package_key]['rates'][$chosen_package_rate_id];1001 $canonical_rate_ids[] = $chosen_rate->get_method_id() . ':' . $chosen_rate->get_instance_id();1002 }1003 }1004 }1005 1006 return $canonical_rate_ids;1007 }1008 1009 /**1010 * Indicates whether a rate exists in an array of canonically-formatted rate IDs that activates this gateway.1011 *1012 * @param array $rate_ids Rate ids to check.1013 * @return boolean1014 * @since 3.4.01015 *1016 */1017 private function get_matching_rates($rate_ids)1018 {1019 // First, match entries in 'method_id:instance_id' format. Then, match entries in 'method_id' format by stripping off the instance ID from the candidates.1020 return array_unique(array_merge(array_intersect($this->enable_for_methods, $rate_ids), array_intersect($this->enable_for_methods, array_unique(array_map('wc_get_string_before_colon', $rate_ids)))));1021 }1022 1023 } -
tiptoppay-gateway-for-woocommerce/trunk/readme.txt
r3246331 r3464118 5 5 Requires at least: 4.9.7 6 6 Tested up to: 6.7.1 7 Stable tag: 1.0. 17 Stable tag: 1.0.5 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 28 28 * Отправка чеков по email; 29 29 * Отправка чеков по SMS; 30 * Теги способа и предмета расчета; 30 * Теги способа и предмета расчета; 31 31 * Отдельный параметр НДС для доставки. 32 32 … … 46 46 3. В управлении сайтом зайдите в "WooCommerce" -> "Настройки" -> "Оплата" -> "TipTopPay". Отметьте галочкой "Enable TipTopPay". 47 47 48 * **Включить/Выключить** - Включение/Отключение платежной системы; 48 * **Включить/Выключить** - Включение/Отключение платежной системы; 49 49 * **Включить DMS** - Включение двухстадийной схемы оплата платежа (холдирование); 50 * **Текст оплаты заказа** - Можете настроить текст назначения платежа; 51 * **Статус для оплаченного заказа** - **Обработка** (Если не предусматривается другой функционал); 52 * **Статус для отмененного заказа** - **Отменен** (Если не предусматривается другой функционал); 50 * **Текст оплаты заказа** - Можете настроить текст назначения платежа; 51 * **Статус для оплаченного заказа** - **Обработка** (Если не предусматривается другой функционал); 52 * **Статус для отмененного заказа** - **Отменен** (Если не предусматривается другой функционал); 53 53 * **Статус авторизованного платежа DMS** - **На удержании** (Или **Платеж авторизован**, если предусматривается другой функционал); 54 * **Наименование** - Заголовок, который видит пользователь в процессе оформления заказа; 55 * **Описание** - Описание метода оплаты; 54 * **Наименование** - Заголовок, который видит пользователь в процессе оформления заказа; 55 * **Описание** - Описание метода оплаты; 56 56 * **Public_id** - Public id сайта из личного кабинета TipTopPay; 57 57 * **Password for API** - API Secret из личного кабинета TipTopPay; 58 * **Валюта магазина** - Можно выбрать либо валюту магазина, либо конкретное значение, которое будет передаваться в платеж; 58 * **Валюта магазина** - Можно выбрать либо валюту магазина, либо конкретное значение, которое будет передаваться в платеж; 59 59 * **Дизайн виджета** - Выбор дизайна виджета из 3 возможных (classic, modern, mini); 60 * **Язык виджета** - Русский МСК (Если не предусматривается использовать другие языки); 60 * **Язык виджета** - Русский МСК (Если не предусматривается использовать другие языки); 61 61 * **Включено для способов доставки** - Выбор способа доставки, для которого возможен платеж**. 62 62 … … 88 88 * Получить доступ в личный кабинет. Он необходим для подписания договора и дальнейшей работы со всеми инструментариями TipTopPay. 89 89 * Выполнить техническую интеграцию сайта. 90 * Провести тестовые платежи. После успешных тестов — сообщить об этом менеджеру, который переведет сайт в боевой режим. 90 * Провести тестовые платежи. После успешных тестов — сообщить об этом менеджеру, который переведет сайт в боевой режим. 91 91 * Принимайте онлайн-платежи на сайте с помощью банковских карт, а также в один клик 92 92 93 93 = Как получить URL адрес с копией отправленного онлайн-чека в админ панели магазина? = 94 94 … … 102 102 Для некоторых товаров есть требование поставлять названия товаров в чеках на русском языке. Для этого добавлены несколько фильтров: 103 103 104 * Формирование данных заказа во время оплаты 104 * Формирование данных заказа во время оплаты 105 105 * tiptoppay_process_payment_shipping_data 106 106 * tiptoppay_process_payment_order_item 107 * Формирование данных заказа на при смене статуса заказа 107 * Формирование данных заказа на при смене статуса заказа 108 108 * tiptoppay_send_receipt_item 109 109 * tiptoppay_send_receipt_shipping_data 110 110 * tiptoppay_send_receipt_data 111 * Формирование данных заказа при запланированном платеже 111 * Формирование данных заказа при запланированном платеже 112 112 * tiptoppay_scheduled_subscription_payment_shipping_data 113 113 * tiptoppay_scheduled_subscription_payment_order_item -
tiptoppay-gateway-for-woocommerce/trunk/tiptoppay_gateway_for_wc.php
r3303671 r3464118 4 4 * Plugin URI: https://tiptoppay.kz/ 5 5 * Description: Extends WooCommerce with TipTopPay Gateway. 6 * Version: 1.0. 26 * Version: 1.0.4 7 7 * Author: TipTop Pay 8 8 * Author URI: https://tiptoppay.kz/
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)