Changeset 3033150
- Timestamp:
- 02/08/2024 12:10:12 PM (23 months ago)
- Location:
- bonus-plus-wp
- Files:
-
- 4 added
- 8 deleted
- 33 edited
- 1 copied
-
assets/banner-1544x500.png (modified) (1 prop) (previous)
-
assets/banner-772x250.png (modified) (1 prop) (previous)
-
assets/icon-128x128.png (modified) (1 prop) (previous)
-
assets/icon-256x256.png (modified) (1 prop) (previous)
-
assets/icon.svg (modified) (1 prop)
-
assets/screenshot-1.jpg (modified) (1 prop) (previous)
-
assets/screenshot-2.jpg (modified) (1 prop) (previous)
-
assets/screenshot-3.jpg (modified) (1 prop) (previous)
-
assets/screenshot-4.jpg (modified) (1 prop) (previous)
-
assets/screenshot-5.png (modified) (1 prop) (previous)
-
assets/scrrnshots-6.png (modified) (1 prop) (previous)
-
tags/2.8 (copied) (copied from bonus-plus-wp/trunk)
-
tags/2.8/README.md (deleted)
-
tags/2.8/assets/account.js (deleted)
-
tags/2.8/assets/api (deleted)
-
tags/2.8/assets/customer.js (added)
-
tags/2.8/assets/qrcodejs/script.js (deleted)
-
tags/2.8/bonus-plus-wp.php (modified) (5 diffs)
-
tags/2.8/functions.php (modified) (2 diffs)
-
tags/2.8/inc/ApiHelper.php (modified) (10 diffs)
-
tags/2.8/inc/ClientProfile.php (modified) (3 diffs)
-
tags/2.8/inc/CustomerBalance.php (modified) (7 diffs)
-
tags/2.8/inc/Logger.php (modified) (2 diffs)
-
tags/2.8/inc/MenuSettings.php (modified) (1 diff)
-
tags/2.8/inc/RestApiEndpoints.php (added)
-
tags/2.8/inc/WooAccount.php (modified) (11 diffs)
-
tags/2.8/inc/WooProductCatExport.php (modified) (3 diffs)
-
tags/2.8/readme.txt (modified) (3 diffs)
-
tags/2.8/templates/client-account.php (modified) (1 diff)
-
trunk/README.md (deleted)
-
trunk/assets/account.js (deleted)
-
trunk/assets/api (deleted)
-
trunk/assets/customer.js (added)
-
trunk/assets/qrcodejs/script.js (deleted)
-
trunk/bonus-plus-wp.php (modified) (5 diffs)
-
trunk/functions.php (modified) (2 diffs)
-
trunk/inc/ApiHelper.php (modified) (10 diffs)
-
trunk/inc/ClientProfile.php (modified) (3 diffs)
-
trunk/inc/CustomerBalance.php (modified) (7 diffs)
-
trunk/inc/Logger.php (modified) (2 diffs)
-
trunk/inc/MenuSettings.php (modified) (1 diff)
-
trunk/inc/RestApiEndpoints.php (added)
-
trunk/inc/WooAccount.php (modified) (11 diffs)
-
trunk/inc/WooProductCatExport.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/templates/client-account.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
bonus-plus-wp/assets/banner-1544x500.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/banner-772x250.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/icon-128x128.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/icon-256x256.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/icon.svg
-
Property
svn:mime-type
set to
image/svg+xml
-
Property
svn:mime-type
set to
-
bonus-plus-wp/assets/screenshot-1.jpg
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/jpeg
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/screenshot-2.jpg
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/jpeg
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/screenshot-3.jpg
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/jpeg
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/screenshot-4.jpg
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/jpeg
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/screenshot-5.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/assets/scrrnshots-6.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
bonus-plus-wp/tags/2.8/bonus-plus-wp.php
r3011611 r3033150 8 8 * Developer: redmonkey73 9 9 * Developer URI: https://github.com/evgrezanov/ 10 * Text Domain: wp-bonus-plus10 * Text Domain: bonus-plus-wp 11 11 * Domain Path: /languages 12 12 * License: GPLv2 or later … … 15 15 * WP requires at least: 6.0 16 16 * Tested up to: 6.4.2 17 * Version: 2. 717 * Version: 2.8 18 18 */ 19 19 namespace BPWP; … … 28 28 public static function init() 29 29 { 30 define('BPWP_PLUGIN_VERSION', '2. 7');30 define('BPWP_PLUGIN_VERSION', '2.8'); 31 31 32 32 require_once __DIR__ . '/functions.php'; … … 71 71 if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { 72 72 require_once __DIR__ . '/inc/WooAccount.php'; 73 require_once __DIR__ . '/inc/ApiHelper.php'; 73 74 } 74 75 require_once __DIR__ . '/inc/MenuSettings.php'; … … 76 77 require_once __DIR__ . '/inc/ClientProfile.php'; 77 78 require_once __DIR__ . '/inc/WooProductCatExport.php'; 78 require_once __DIR__ . '/inc/ApiHelper.php';79 79 require_once __DIR__ . '/inc/CustomerBalance.php'; 80 require_once __DIR__ . '/inc/RestApiEndpoints.php'; 80 81 } 81 82 -
bonus-plus-wp/tags/2.8/functions.php
r2975143 r3033150 54 54 'body' => $params, 55 55 ); 56 $args['headers']['Content-Length'] = strlen( $args['body'] ?: '' ); // Добавим Content-Length. Важно, если body пустой 56 57 } 57 58 … … 139 140 } 140 141 142 /** 143 * Get the error message for a given code. 144 * 145 * @param int $code The error code. 146 * @return string|false The error message, or false if not found. 147 */ 141 148 function bpwp_api_get_error_msg($code) 142 149 { -
bonus-plus-wp/tags/2.8/inc/ApiHelper.php
r3004945 r3033150 18 18 add_action('woocommerce_before_cart_totals', [__CLASS__, 'bpwp_cart_checkout_bonusplus_price']); 19 19 add_action('woocommerce_checkout_before_order_review', [__CLASS__, 'bpwp_cart_checkout_bonusplus_price']); 20 add_action('woocommerce_ short_description', [__CLASS__, 'bpwp_single_product_bonusplus_price'], 10, 1);20 add_action('woocommerce_product_meta_end', [__CLASS__, 'bpwp_single_product_bonusplus_price'], 10); 21 21 add_action('woocommerce_cart_calculate_fees', [__CLASS__, 'add_custom_fee_on_checkout']); 22 22 23 23 } 24 24 … … 37 37 38 38 WC()->cart->add_fee($fee_name, $fee_amount, $taxable, $tax_class); 39 40 39 } 41 40 } … … 119 118 'quantity' => $quantity 120 119 ); 120 do_action('logger', $items); 121 121 122 } 122 123 … … 150 151 $retailcalc = bpwp_api_request( 151 152 'retail/calc', 152 json_encode($params),153 wp_json_encode($params), 153 154 'PUT', 154 155 ); 155 156 156 $response_code = wp_remote_retrieve_response_code($retailcalc);157 //$response_code = wp_remote_retrieve_response_code($retailcalc); 157 158 158 159 return $retailcalc; … … 171 172 172 173 $output = ''; 173 174 // TODO добавить проверку на nonce if (isset($_GET['testrequest']) && isset($_GET['nonce']) && wp_verify_nonce($_GET['nonce'], 'nonce_action_name')) {} 174 175 if (isset($_GET['testrequest'])) { 175 176 … … 235 236 236 237 $output .= '<div class="bonus-plus-price">'; 237 $output .= '<p>Ваш бонусный баланс '. $available_bonuses .'.</p><p>Сумма бонусов, которые будут начислены '. $bonuses .'.</p><p> На эту покупку будет списано '. $maxDebitBonuses .' бон .</p>';238 $output .= '<p>Ваш бонусный баланс '. $available_bonuses .'.</p><p>Сумма бонусов, которые будут начислены '. $bonuses .'.</p><p> На эту покупку будет списано '. $maxDebitBonuses .' бонусов</p>'; 238 239 $output .= '</div>'; 239 240 … … 243 244 } 244 245 246 /** 247 * Renders retail items calculation based on the provided data. 248 * 249 * @param array $data The data for the retail items calculation. 250 */ 245 251 public static function bpwp_render_retailitems_calc($data) 246 252 { … … 274 280 275 281 /** 276 * 277 */ 278 public static function bpwp_single_product_bonusplus_price($post_excerpt){ 282 * Выводит доступные бонусы на странице товара 283 */ 284 public static function bpwp_single_product_bonusplus_price(){ 285 286 if (!is_product()) { 287 return; 288 } 289 279 290 $content = ''; 280 281 if (is_product()) { 282 $price_data = self::bpwp_get_calc_bonusplus_price(); 283 $content = $post_excerpt . self::bpwp_render_retailitems_calc($price_data); 284 } 285 291 $price_data = self::bpwp_get_calc_bonusplus_price(); 292 $content = self::bpwp_render_retailitems_calc($price_data); 293 286 294 return $content; 287 295 } … … 301 309 } 302 310 311 /** 312 * Get the maximum debit bonuses from the provided data array. 313 * 314 * @param array $data The input data array 315 */ 303 316 public function bpwp_get_max_debit_bonuses($data) { 304 317 if (is_array($data) && isset($data['request']) && isset($data['request']['discount'])) { … … 309 322 } 310 323 324 325 311 326 BPWPApiHelper::init(); -
bonus-plus-wp/tags/2.8/inc/ClientProfile.php
r3004945 r3033150 16 16 add_action('wp_login', [__CLASS__, 'bpwp_customer_login'], 10, 2); 17 17 add_filter('bpwp_replace_customer_card_desc', [__CLASS__, 'bpwp_replace_customer_card_desc'], 10, 2); 18 //add_action('woocommerce_customer_save_address', [__CLASS__, 'bpwp_remove_user_meta_on_address_change'], 10, 2); 18 19 } 19 20 … … 138 139 // Проверим заполнены ли у порльзователя дата рождения и телефон 139 140 $user_id = get_current_user_id(); 140 $billing_birth_date = get_user_meta( $user_id, 'billing_birth_date', true );141 141 $billing_phone = get_user_meta(get_current_user_id(), 'billing_phone', true); 142 142 $bonus_plus = get_user_meta(get_current_user_id(), 'bonus-plus', true); 143 143 144 if ( empty( $billing_birth_date ) ||empty($billing_phone) ) {144 if (empty($billing_phone) ) { 145 145 $data['title'] = __('ОШИБКА!', 'bonus-plus-wp'); 146 146 $data['url'] = get_option('bpwp_uri_customers_lk_billing_address'); 147 $data['desc'] = 'Добавьте дату рождения и/илиномер телефона в личном кабинете';147 $data['desc'] = 'Добавьте номер телефона в личном кабинете'; 148 148 $data['class'] = 'card3'; 149 149 // или данные из Бонус+ пустые … … 239 239 } 240 240 } 241 242 /** 243 * Обновление метаданных Бонус+ при сохранении адреса из личного кабинета пользователя 244 * 245 * @param int $user_id User ID being saved. 246 * @param string $address_type Type of address; 'billing' or 'shipping'. 247 * 248 * @return void 249 * 250 */ 251 public static function bpwp_remove_user_meta_on_address_change( $user_id, $load_address ){ 252 if ( ! is_user_logged_in() ) return; 253 254 if ( $load_address !== 'billing') return; 255 // TODO: Если есть мета и тел bonus-plus['phone] и billing_phone не совпадают, то чистим мета 256 $user = get_user_by_id($user_id); 257 258 //self::bpwp_customer_login($user->user_login, $user); 259 } 241 260 } 242 261 BPWPProfile::init(); -
bonus-plus-wp/tags/2.8/inc/CustomerBalance.php
r3004945 r3033150 17 17 // Заказ выполнен, запрос с начислением бонусов. Комментарий в заказ - "бонусы начисены" 18 18 add_action('woocommerce_order_status_completed', [__CLASS__, 'bpwp_customer_balance_bonusplus']); 19 20 19 } 21 20 … … 27 26 $user_id = $order->get_user_id(); 28 27 29 // TODOПолучить бонусы для списания и добавить в мета заказа28 // Получить бонусы для списания и добавить в мета заказа 30 29 $data = BPWPApiHelper::bpwp_get_calc_bonusplus_price(); 31 30 … … 34 33 } 35 34 36 // Запрос Резервируем бонусы 37 /* 38 https://bonusplus.pro/api/Help/Api/PATCH-customer-phoneNumber-balance-reserve 39 */ 40 41 // Резервируем бонусы, передаем положительное число 42 35 43 36 $order_data = array( 44 37 'billing_phone' => bpwp_api_get_customer_phone($user_id), … … 47 40 ); 48 41 42 /* Запрос Резервируем бонусы, передаем положительное число 43 https://bonusplus.pro/api/Help/Api/PATCH-customer-phoneNumber-balance-reserve 44 */ 49 45 $balance_reserve = self::bpwp_balance_reserve($order_data); 50 46 51 52 $info = bpwp_api_get_customer_data(); 53 54 if ($info && is_array($info)) { 55 $info['availableBonuses'] = $info['availableBonuses'] - $bonus_debit; 56 57 update_user_meta($user_id, 'bonus-plus', $info); 58 } 59 60 61 //TODO В инфо заказа фильтр, начислено бонусов 62 63 /* 64 bonus-plus [ 65 'availableBonuses' => 404.0 66 ] 67 */ 68 // Обновление данных заказа 69 // if ($balance_reserve['code'] == 200){ 70 // update_order_meta($order_id, 'bonus_debit', $bonus_debit); 71 72 // //update_user_meta($order_id, 'bonus_debit', $balance_reserve['request']['customer']); 73 // } 74 75 add_post_meta( $order_id, '_bonus_debit', $bonus_debit ); 76 77 //if ($deduction == 'true') { // TODO Если пользователь подтвердил списание бонусов 78 79 // Добавим Скидку 80 $item_id = wc_add_order_item( $order_id, array( 81 'order_item_name' => 'Списание бонусов', 82 'order_item_type' => 'fee' 83 ) ); 84 85 wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( -$bonus_debit) ); 86 87 $order->calculate_totals(); 88 $order_id = $order->save(); 89 90 //} End if 91 47 if ($balance_reserve['code'] == 204) { 48 49 $info = bpwp_api_get_customer_data(); 50 51 if ($info && is_array($info)) { 52 $info['availableBonuses'] = $info['availableBonuses'] - $bonus_debit; 53 54 update_user_meta($user_id, 'bonus-plus', $info); 55 } 56 57 add_post_meta( $order_id, '_bonus_debit', $bonus_debit, true); 58 59 } else { 60 do_action( 61 'bpwp_logger', 62 $type = __CLASS__, 63 $title = __('Ошибка при резервировании бонусов', 'bonus-plus-wp'), 64 $desc = sprintf(__('У заказа ИД %s, бонусы не зарезервированы!', 'bonus-plus-wp'), $order_id), 65 ); 66 } 92 67 } 93 68 … … 106 81 $balance_reserve = bpwp_api_request( 107 82 '/customer/'. $order_data['billing_phone'] .'/balance/reserve', 108 json_encode($params),83 wp_json_encode($params), 109 84 'PATCH', 110 85 ); 111 86 112 87 return $balance_reserve; 113 } 114 115 } 116 88 89 } 90 } 117 91 118 92 /** … … 135 109 // Освобождаем из резерва, передаем отрицательное число 136 110 $balance_reserve = self::bpwp_balance_reserve($order_data); 137 } 138 139 //Проведение продажи в БонусПлюс 140 $retail = self::bpwp_get_order_bonuses($order_id); 141 142 // Обновление данных пользователя 143 if ($retail['code'] == 200){ 144 145 update_user_meta($user_id, 'bonus-plus', $retail['request']['customer']); 111 112 if ($balance_reserve['code'] == 204) { 113 114 //Проведение продажи в БонусПлюс 115 $retail = self::bpwp_get_order_bonuses($order_id); 116 117 // Обновление данных пользователя 118 if ($retail['code'] == 200){ 119 update_user_meta($user_id, 'bonus-plus', $retail['request']['customer']); 120 } else { 121 do_action( 122 'bpwp_logger', 123 $type = __CLASS__, 124 $title = __('Проведение продажи в БонусПлюс', 'bonus-plus-wp'), 125 $desc = sprintf(__('Заказа ИД %s, код ошибки %s', 'bonus-plus-wp'), $order_id,), 126 ); 127 } 128 129 } else { 130 do_action( 131 'bpwp_logger', 132 $type = __CLASS__, 133 $title = __('Ошибка при списании бонусов', 'bonus-plus-wp'), 134 $desc = sprintf(__('У заказа ИД %s, бонусы не зарезервированы!', 'bonus-plus-wp'), $order_id), 135 ); 136 } 146 137 } 147 138 } … … 181 172 // Отправим запрос "Проведение продажи в БонусПлюс" 182 173 if (!empty($billingPhone) && !empty($store) && count($items) >= 1){ 183 $retail = bpwp_api_request( 184 'retail', 185 json_encode($params), 186 'POST', 187 ); 188 174 $retail = bpwp_api_request( 175 'retail', 176 wp_json_encode($params), 177 'POST', 178 ); 189 179 return $retail; 190 180 } 191 192 181 } 193 182 -
bonus-plus-wp/tags/2.8/inc/Logger.php
r2577633 r3033150 60 60 61 61 if (is_array($description)) { 62 $description = json_encode($description, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);62 $description = wp_json_encode($description, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); 63 63 } else { 64 64 $description = wc_print_r($description, true); … … 92 92 if (!empty($description)) { 93 93 if (is_array($description)) { 94 $description = json_encode($description, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);94 $description = wp_json_encode($description, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); 95 95 } else { 96 96 $description = wc_print_r($description, true); -
bonus-plus-wp/tags/2.8/inc/MenuSettings.php
r3004945 r3033150 483 483 484 484 printf('<a href="%s">Вернуться...</a>', remove_query_arg('a', self::$url)); 485 485 // TODO Processing form data without nonce verification. 486 // if ( isset( $_GET['a'] ) && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'your_action_nonce' ) ) { 487 //do_action( 'bpwp_tool_actions_' . $_GET['a'] ); 488 //} 486 489 do_action('bpwp_tool_actions_' . $_GET['a']); 487 490 -
bonus-plus-wp/tags/2.8/inc/WooAccount.php
r3004945 r3033150 34 34 add_action('wp_enqueue_scripts', [__CLASS__, 'bpwp_qrcode_scripts']); 35 35 add_filter('bpwp_debug_phone_verify', '__return_true'); 36 add_filter('woocommerce_billing_fields', [__CLASS__, 'bpwp_add_birth_date_billing_field'], 20, 1); 37 if (wp_doing_ajax()) { 38 add_action('wp_ajax_nopriv_bpwp_cv', [__CLASS__, 'bpwp_client_verify_phone_callback']); 39 add_action('wp_ajax_bpwp_cv', [__CLASS__, 'bpwp_client_verify_phone_callback']); 40 } 36 41 37 } 42 38 … … 110 106 if (empty($is_debug)) { 111 107 printf('<h2>%s</h2>', 'Информация по карте лояльности'); 108 109 echo '<div id="loader" class="center-body"><div class="loader-ball-8"></div></div>'; 112 110 113 111 //do_action('bpwp_after_bonus_card_info_title'); … … 185 183 $customerData = bpwp_api_get_customer_data(); 186 184 $cardNumber = !empty($customerData['discountCardNumber']) ? $customerData['discountCardNumber'] : ''; 187 //$clientInfo = []; 188 $apiKey = ''; 189 $sendSmsUri = ''; 190 $sendOtpUri = ''; 191 $registrationUri = ''; 192 193 if (!empty($phone = get_user_meta(get_current_user_id(), 'billing_phone', true))) { 194 $apiKey = base64_encode(esc_attr(get_option('bpwp_api_key'))); 195 $sendSmsUri = sprintf('https://bonusplus.pro/api/customer/%s/sendCode/', $phone); 196 $sendOtpUri = sprintf('https://bonusplus.pro/api/customer/%s/checkCode/', $phone); 197 $registrationUri = 'https://bonusplus.pro/api/customer/'; 198 //$clientInfo = self::bpwp_get_client_registration_data(get_current_user_id()); 199 } 185 $phone = get_user_meta(get_current_user_id(), 'billing_phone', true); 200 186 201 187 wp_enqueue_script( … … 208 194 209 195 wp_enqueue_script( 210 ' accountjs',211 plugins_url('/assets/ account.js', __DIR__),196 'customerjs', 197 plugins_url('/assets/customer.js', __DIR__), 212 198 ['qrcodejs', 'jquery'], 213 199 BPWP_PLUGIN_VERSION, … … 215 201 ); 216 202 203 wp_enqueue_script( 'wp-api' ); 204 217 205 wp_localize_script( 218 ' accountjs',206 'customerjs', 219 207 'accountBonusPlusData', 220 208 array( 221 'auth' => esc_attr($apiKey), 222 'sendSmsUri' => $sendSmsUri, 223 'sendOtpUri' => $sendOtpUri, 224 'registrationUri' => esc_attr($registrationUri), 225 'redirect' => site_url() . '/my-account/', 226 'ajax_url' => admin_url('admin-ajax.php'), 227 'cardNumber' => esc_attr($cardNumber), 228 'debug' => apply_filters('bpwp_debug_phone_verify', false), 229 'clientInfo' => json_encode(self::bpwp_get_client_registration_data(get_current_user_id())), 209 'phone' => esc_attr($phone), 210 'cardNumber' => esc_attr($cardNumber), 211 'redirect' => site_url() . '/my-account/bonus-plus/', 212 'debug' => apply_filters('bpwp_debug_phone_verify', false), 230 213 ) 231 214 ); … … 240 223 $phone = !empty(get_user_meta(get_current_user_id(), 'billing_phone', true)) ? get_user_meta(get_current_user_id(), 'billing_phone', true) : ''; 241 224 242 $birthDate = !empty(get_user_meta(get_current_user_id(), 'billing_birth_date', true)) ? get_user_meta(get_current_user_id(), 'billing_birth_date', true) : '';243 244 225 $verifiedUser = !empty(get_user_meta(get_current_user_id(), 'bpwp_verified_user', true)) ? get_user_meta(get_current_user_id(), 'bpwp_verified_user', true) : ''; 245 226 … … 248 229 if (empty($phone)) { 249 230 250 $msg .= sprintf('<h3>%s</h3>', __('Пожалуйста заполнить платежный адрес и телефон', 'bonus-plus-wp')); 251 } else if (empty($birthDate)) { 252 253 $msg .= sprintf('<h3>%s</h3>', __('Пожалуйста заполните дату рождения в платежном адресе', 'bonus-plus-wp')); 231 $msg .= sprintf('<h3>%s</h3>', __('Пожалуйста, заполните платежный адрес и телефон', 'bonus-plus-wp')); 232 $msg .= sprintf('<a href="%s">%s</a>', '/my-account/edit-address/billing/', __('Перейти к заполнению данных', 'bonus-plus-wp')); 254 233 } else if (empty($verifiedUser)) { 255 234 … … 277 256 <div hidden id="bpmsg" class="msg" style="display:none;"></div> 278 257 279 <div id="qrcode" style="display:none;"></div> 280 281 <div id='bpwp-registration' style="display:none;"> 282 <p><?= __('Вы еще не зарегистрированы в программе лояльности', 'bonus-plus-wp') ?> 258 <!-- <div id="qrcode" style="display:none;"></div> --> 259 260 <div id='bpwp-registration'> 261 <p><?php echo __('Вы еще не зарегистрированы в программе лояльности', 'bonus-plus-wp') ?></p> 262 </div> 263 264 <div id='bpwp-verify-start' style="display:none;"> 265 <p><?php echo __('Подтвердите номер телефона', 'bonus-plus-wp') ?> 266 <strong><?php echo $phone ?></strong> 283 267 </p> 284 <button id="bpwp Registration"><?= __('Создать учетную запись', 'bonus-plus-wp') ?></button>268 <button id="bpwpSendSms"><?php echo __('Отправить SMS c кодом подтверждения', 'bonus-plus-wp') ?></button> 285 269 </div> 286 270 287 <div id='bpwp-verify-start' style="display:none;">288 <p><?= __('Подтвердите номер телефона', 'bonus-plus-wp') ?>289 <strong><?= $phone ?></strong>290 </p>291 <button id="bpwpSendSms"><?= __('Отправить SMS c кодом подтверждения', 'bonus-plus-wp') ?></button>292 </div>293 294 271 <div id='bpwp-verify-end' style="display:none;"> 295 <p><? =__('Введите код высланый в SMS, на номер телефона:', 'bonus-plus-wp') ?>296 <strong><? =$phone ?></strong>272 <p><?php echo __('Введите код высланый в SMS, на номер телефона:', 'bonus-plus-wp') ?> 273 <strong><?php echo $phone ?></strong> 297 274 </p> 298 275 <input id="bpwpOtpInput" type="number" maxLength="1" size="6" min="0" max="999999" pattern="[0-9]{6}" /> 299 <button id="bpwpSendOtp"><? =__('Подтвердить номер телефона', 'bonus-plus-wp') ?></button>276 <button id="bpwpSendOtp"><?php echo __('Подтвердить номер телефона', 'bonus-plus-wp') ?></button> 300 277 </div> 301 278 </div> 302 279 <?php 303 }304 305 /**306 * Добавим обязательное поле "Дата рождения" в платежный адрес307 */308 public static function bpwp_add_birth_date_billing_field($billing_fields)309 {310 $billing_fields['billing_birth_date'] = array(311 'type' => 'date',312 'label' => __('Дата рождения', 'bonus-plus-wp'),313 'class' => array('form-row-wide'),314 'priority' => 25,315 'required' => true,316 'clear' => true,317 );318 319 return $billing_fields;320 }321 322 /**323 * AJAX Callback324 * Always Echos and Exits325 */326 public static function bpwp_client_verify_phone_callback()327 {328 // Ensure we have the data we need to continue329 if (!is_user_logged_in()) {330 // If we don't - return custom error message and exit331 header('HTTP/1.1 400 Empty POST Values');332 wp_send_json('Could Not Verify POST Values.');333 wp_die();334 }335 $user_id = get_current_user_id();336 337 // if user already register, make verify phone request338 $phone = bpwp_api_get_customer_phone($user_id);339 340 if (!empty($phone)) {341 $res = bpwp_api_request(342 'customer',343 array(344 'phone' => $phone345 ),346 'GET'347 );348 if (!empty($res['request'])) {349 $response = $res['request']['response'];350 update_user_meta($user_id, 'bonus-plus', $res['request']);351 $result = $res['request'];352 // todo353 // ... parse response data and return cardnumber354 wp_send_json($res);355 wp_die();356 }357 }358 280 } 359 281 … … 379 301 $billingEmail = !empty($customer['billing_email']) ? $customer['billing_email'] : '-'; 380 302 $billingPhone = !empty($customer['billing_phone']) ? $customer['billing_phone'] : '-'; 381 // ДД.ММ.ГГГГ382 if (isset($customer['billing_birth_date'])) {383 $originalBDate = $customer['billing_birth_date'][0];384 $newBDate = date("d.m.Y", strtotime($originalBDate));385 } else {386 $newBDate = '';387 }388 303 389 304 $registrationData = array(); 390 305 391 if ($firstName && $lastName && $ newBDate && $billingEmail && $billingPhone) {306 if ($firstName && $lastName && $billingEmail && $billingPhone) { 392 307 /* 393 308 $registrationData['phone'] = $billingPhone; … … 405 320 'ln' => $lastName[0], 406 321 'desc' => __('Регистрация на сайте', 'bonus-plus-wp'), 407 'birthDay' => $newBDate,408 322 ); 409 323 //$registrationData['address'] = $billingPostcode . $billingCountry . $billingState . $billingCity . $address1 . $address2; … … 412 326 return $registrationData; 413 327 } 328 414 329 } 330 415 331 BPWPMyAccount::init(); -
bonus-plus-wp/tags/2.8/inc/WooProductCatExport.php
r3011611 r3033150 314 314 $export = bpwp_api_request( 315 315 'product/import', 316 json_encode($params),316 wp_json_encode($params), 317 317 'POST', 318 318 ); … … 383 383 ?> 384 384 <div class="wrap"> 385 <div id="message" class="<? =esc_attr($class) ?>">385 <div id="message" class="<?php echo esc_attr($class) ?>"> 386 386 <?php 387 387 foreach ($strings as $string) { … … 404 404 //Get all terms associated with post in woocommerce's taxonomy 'product_cat' 405 405 $terms = get_the_terms($productId, 'product_cat'); 406 407 //Get an array of their IDs 408 $term_ids = wp_list_pluck($terms, 'term_id'); 409 410 //Get array of parents - 0 is not a parent 411 $parents = array_filter(wp_list_pluck($terms, 'parent')); 412 413 //Get array of IDs of terms which are not parents. 414 $term_ids_not_parents = array_diff($term_ids, $parents); 415 416 //Get corresponding term objects. 417 $terms_not_parents = array_intersect_key($terms, $term_ids_not_parents); 418 419 return $terms_not_parents; 406 407 // Check if terms exist and is not a WP_Error 408 if (is_array($terms) && !is_wp_error($terms)) { 409 410 //Get an array of their IDs 411 $term_ids = wp_list_pluck($terms, 'term_id'); 412 413 //Get array of parents - 0 is not a parent 414 $parents = array_filter(wp_list_pluck($terms, 'parent')); 415 416 //Get array of IDs of terms which are not parents. 417 $term_ids_not_parents = array_diff($term_ids, $parents); 418 419 //Get corresponding term objects. 420 $terms_not_parents = array_intersect_key($terms, $term_ids_not_parents); 421 422 return $terms_not_parents; 423 } 424 425 // Return an empty array if there are no terms or an error occurred 426 return array(); 420 427 } 421 428 } -
bonus-plus-wp/tags/2.8/readme.txt
r3011611 r3033150 5 5 Requires at least: 4.0 6 6 Tested up to: 6.4.2 7 Stable tag: 2. 77 Stable tag: 2.8 8 8 Requires PHP: 8.1 9 9 License: GPLv2 or later … … 46 46 = Automatic installation = 47 47 48 Automatic installation is the easiest option -- WordPress will handles the file transfer, and you won’t need to leave your web browser. To do an automatic install of WP-bonus-plus, log in to your WordPress dashboard, navigate to the Plugins menu, and click “Add New.”48 Automatic installation is the easiest option -- WordPress will handles the file transfer, and you won’t need to leave your web browser. To do an automatic install of bonus-plus-wp, log in to your WordPress dashboard, navigate to the Plugins menu, and click “Add New.” 49 49 50 In the search field type “ wp-bonus-plus,” then click “Search Plugins.” Once you’ve found us, you can view details about it such as the point release, rating, and description. Most importantly of course, you can install it by! Click “Install Now,” and WordPress will take it from there.50 In the search field type “bonus-plus-wp,” then click “Search Plugins.” Once you’ve found us, you can view details about it such as the point release, rating, and description. Most importantly of course, you can install it by! Click “Install Now,” and WordPress will take it from there. 51 51 52 52 = Manual installation = 53 53 54 Manual installation method requires downloading the wp-bonus-plusplugin and uploading it to your web server via your favorite FTP application. The WordPress codex contains [instructions on how to do this here](https://wordpress.org/support/article/managing-plugins/#manual-plugin-installation).54 Manual installation method requires downloading the bonus-plus-wp plugin and uploading it to your web server via your favorite FTP application. The WordPress codex contains [instructions on how to do this here](https://wordpress.org/support/article/managing-plugins/#manual-plugin-installation). 55 55 56 56 … … 92 92 93 93 == Changelog == 94 95 = 2.8 = 96 - убрали поле "дата рождения" из личного кабинета https://github.com/evgrezanov/bonus-plus-wp/issues/58 97 - добавлена обработка ошибок при экспорте товаров и категорий https://github.com/evgrezanov/bonus-plus-wp/issues/56 98 - рефакторинг процесса авторизации и регистрации в программе лояльности https://github.com/evgrezanov/bonus-plus-wp/issues/47 99 - исправлена функция списания и резервирования бонусов https://github.com/evgrezanov/bonus-plus-wp/issues/40 100 - исправлена проблема с безопастностью при генерации QR кода в личном кабинете исправить проблему с безопастностью https://github.com/evgrezanov/bonus-plus-wp/issues/21 94 101 95 102 = 2.7 = -
bonus-plus-wp/tags/2.8/templates/client-account.php
r2627044 r3033150 10 10 11 11 <div id='bpwp-registration' style="display:none;"> 12 <p><? =__('Вы еще не зарегистрированы в программе лояльности', 'bonus-plus-wp') ?>12 <p><?php echo __('Вы еще не зарегистрированы в программе лояльности', 'bonus-plus-wp') ?> 13 13 </p> 14 <button id="bpwpRegistration"><? =__('Продолжить регистрацию', 'bonus-plus-wp') ?></button>14 <button id="bpwpRegistration"><?php echo __('Продолжить регистрацию', 'bonus-plus-wp') ?></button> 15 15 </div> 16 16 17 17 <div id='bpwp-verify-start' style="display:none;"> 18 <p><? =__('Для завершения регистрации в Бонус+, подтвердите номер телефона, после отправки СМС', 'bonus-plus-wp') ?>19 <strong><?= $phone?></strong>18 <p><?php echo __('Для завершения регистрации в Бонус+, подтвердите номер телефона, после отправки СМС', 'bonus-plus-wp') ?> 19 <strong><?php echo $phone; ?></strong> 20 20 </p> 21 <button id="bpwpSendSms"><? = __('Отправить SMS c кодом подтверждения', 'bonus-plus-wp')?></button>21 <button id="bpwpSendSms"><?php echo __('Отправить SMS c кодом подтверждения', 'bonus-plus-wp'); ?></button> 22 22 </div> 23 23 24 24 <div id='bpwp-verify-end' style="display:none;"> 25 <p><? = __('Введите код высланый в SMS, на номер телефона:', 'bonus-plus-wp') ?>26 <strong><?= $phone?></strong>25 <p><?php echo __('Введите код высланый в SMS, на номер телефона:', 'bonus-plus-wp'); ?></p> 26 <strong><?php echo $phone; ?></strong> 27 27 </p> 28 28 <input id="bpwpOtpInput" type="number" maxLength="1" size="6" min="0" max="999999" pattern="[0-9]{6}" /> 29 <button id="bpwpSendOtp"><? = __('Подтвердить', 'bonus-plus-wp')?></button>29 <button id="bpwpSendOtp"><?php echo __('Подтвердить', 'bonus-plus-wp'); ?></button> 30 30 </div> 31 31 </div> -
bonus-plus-wp/trunk/bonus-plus-wp.php
r3011611 r3033150 8 8 * Developer: redmonkey73 9 9 * Developer URI: https://github.com/evgrezanov/ 10 * Text Domain: wp-bonus-plus10 * Text Domain: bonus-plus-wp 11 11 * Domain Path: /languages 12 12 * License: GPLv2 or later … … 15 15 * WP requires at least: 6.0 16 16 * Tested up to: 6.4.2 17 * Version: 2. 717 * Version: 2.8 18 18 */ 19 19 namespace BPWP; … … 28 28 public static function init() 29 29 { 30 define('BPWP_PLUGIN_VERSION', '2. 7');30 define('BPWP_PLUGIN_VERSION', '2.8'); 31 31 32 32 require_once __DIR__ . '/functions.php'; … … 71 71 if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { 72 72 require_once __DIR__ . '/inc/WooAccount.php'; 73 require_once __DIR__ . '/inc/ApiHelper.php'; 73 74 } 74 75 require_once __DIR__ . '/inc/MenuSettings.php'; … … 76 77 require_once __DIR__ . '/inc/ClientProfile.php'; 77 78 require_once __DIR__ . '/inc/WooProductCatExport.php'; 78 require_once __DIR__ . '/inc/ApiHelper.php';79 79 require_once __DIR__ . '/inc/CustomerBalance.php'; 80 require_once __DIR__ . '/inc/RestApiEndpoints.php'; 80 81 } 81 82 -
bonus-plus-wp/trunk/functions.php
r2975143 r3033150 54 54 'body' => $params, 55 55 ); 56 $args['headers']['Content-Length'] = strlen( $args['body'] ?: '' ); // Добавим Content-Length. Важно, если body пустой 56 57 } 57 58 … … 139 140 } 140 141 142 /** 143 * Get the error message for a given code. 144 * 145 * @param int $code The error code. 146 * @return string|false The error message, or false if not found. 147 */ 141 148 function bpwp_api_get_error_msg($code) 142 149 { -
bonus-plus-wp/trunk/inc/ApiHelper.php
r3004945 r3033150 18 18 add_action('woocommerce_before_cart_totals', [__CLASS__, 'bpwp_cart_checkout_bonusplus_price']); 19 19 add_action('woocommerce_checkout_before_order_review', [__CLASS__, 'bpwp_cart_checkout_bonusplus_price']); 20 add_action('woocommerce_ short_description', [__CLASS__, 'bpwp_single_product_bonusplus_price'], 10, 1);20 add_action('woocommerce_product_meta_end', [__CLASS__, 'bpwp_single_product_bonusplus_price'], 10); 21 21 add_action('woocommerce_cart_calculate_fees', [__CLASS__, 'add_custom_fee_on_checkout']); 22 22 23 23 } 24 24 … … 37 37 38 38 WC()->cart->add_fee($fee_name, $fee_amount, $taxable, $tax_class); 39 40 39 } 41 40 } … … 119 118 'quantity' => $quantity 120 119 ); 120 do_action('logger', $items); 121 121 122 } 122 123 … … 150 151 $retailcalc = bpwp_api_request( 151 152 'retail/calc', 152 json_encode($params),153 wp_json_encode($params), 153 154 'PUT', 154 155 ); 155 156 156 $response_code = wp_remote_retrieve_response_code($retailcalc);157 //$response_code = wp_remote_retrieve_response_code($retailcalc); 157 158 158 159 return $retailcalc; … … 171 172 172 173 $output = ''; 173 174 // TODO добавить проверку на nonce if (isset($_GET['testrequest']) && isset($_GET['nonce']) && wp_verify_nonce($_GET['nonce'], 'nonce_action_name')) {} 174 175 if (isset($_GET['testrequest'])) { 175 176 … … 235 236 236 237 $output .= '<div class="bonus-plus-price">'; 237 $output .= '<p>Ваш бонусный баланс '. $available_bonuses .'.</p><p>Сумма бонусов, которые будут начислены '. $bonuses .'.</p><p> На эту покупку будет списано '. $maxDebitBonuses .' бон .</p>';238 $output .= '<p>Ваш бонусный баланс '. $available_bonuses .'.</p><p>Сумма бонусов, которые будут начислены '. $bonuses .'.</p><p> На эту покупку будет списано '. $maxDebitBonuses .' бонусов</p>'; 238 239 $output .= '</div>'; 239 240 … … 243 244 } 244 245 246 /** 247 * Renders retail items calculation based on the provided data. 248 * 249 * @param array $data The data for the retail items calculation. 250 */ 245 251 public static function bpwp_render_retailitems_calc($data) 246 252 { … … 274 280 275 281 /** 276 * 277 */ 278 public static function bpwp_single_product_bonusplus_price($post_excerpt){ 282 * Выводит доступные бонусы на странице товара 283 */ 284 public static function bpwp_single_product_bonusplus_price(){ 285 286 if (!is_product()) { 287 return; 288 } 289 279 290 $content = ''; 280 281 if (is_product()) { 282 $price_data = self::bpwp_get_calc_bonusplus_price(); 283 $content = $post_excerpt . self::bpwp_render_retailitems_calc($price_data); 284 } 285 291 $price_data = self::bpwp_get_calc_bonusplus_price(); 292 $content = self::bpwp_render_retailitems_calc($price_data); 293 286 294 return $content; 287 295 } … … 301 309 } 302 310 311 /** 312 * Get the maximum debit bonuses from the provided data array. 313 * 314 * @param array $data The input data array 315 */ 303 316 public function bpwp_get_max_debit_bonuses($data) { 304 317 if (is_array($data) && isset($data['request']) && isset($data['request']['discount'])) { … … 309 322 } 310 323 324 325 311 326 BPWPApiHelper::init(); -
bonus-plus-wp/trunk/inc/ClientProfile.php
r3004945 r3033150 16 16 add_action('wp_login', [__CLASS__, 'bpwp_customer_login'], 10, 2); 17 17 add_filter('bpwp_replace_customer_card_desc', [__CLASS__, 'bpwp_replace_customer_card_desc'], 10, 2); 18 //add_action('woocommerce_customer_save_address', [__CLASS__, 'bpwp_remove_user_meta_on_address_change'], 10, 2); 18 19 } 19 20 … … 138 139 // Проверим заполнены ли у порльзователя дата рождения и телефон 139 140 $user_id = get_current_user_id(); 140 $billing_birth_date = get_user_meta( $user_id, 'billing_birth_date', true );141 141 $billing_phone = get_user_meta(get_current_user_id(), 'billing_phone', true); 142 142 $bonus_plus = get_user_meta(get_current_user_id(), 'bonus-plus', true); 143 143 144 if ( empty( $billing_birth_date ) ||empty($billing_phone) ) {144 if (empty($billing_phone) ) { 145 145 $data['title'] = __('ОШИБКА!', 'bonus-plus-wp'); 146 146 $data['url'] = get_option('bpwp_uri_customers_lk_billing_address'); 147 $data['desc'] = 'Добавьте дату рождения и/илиномер телефона в личном кабинете';147 $data['desc'] = 'Добавьте номер телефона в личном кабинете'; 148 148 $data['class'] = 'card3'; 149 149 // или данные из Бонус+ пустые … … 239 239 } 240 240 } 241 242 /** 243 * Обновление метаданных Бонус+ при сохранении адреса из личного кабинета пользователя 244 * 245 * @param int $user_id User ID being saved. 246 * @param string $address_type Type of address; 'billing' or 'shipping'. 247 * 248 * @return void 249 * 250 */ 251 public static function bpwp_remove_user_meta_on_address_change( $user_id, $load_address ){ 252 if ( ! is_user_logged_in() ) return; 253 254 if ( $load_address !== 'billing') return; 255 // TODO: Если есть мета и тел bonus-plus['phone] и billing_phone не совпадают, то чистим мета 256 $user = get_user_by_id($user_id); 257 258 //self::bpwp_customer_login($user->user_login, $user); 259 } 241 260 } 242 261 BPWPProfile::init(); -
bonus-plus-wp/trunk/inc/CustomerBalance.php
r3004945 r3033150 17 17 // Заказ выполнен, запрос с начислением бонусов. Комментарий в заказ - "бонусы начисены" 18 18 add_action('woocommerce_order_status_completed', [__CLASS__, 'bpwp_customer_balance_bonusplus']); 19 20 19 } 21 20 … … 27 26 $user_id = $order->get_user_id(); 28 27 29 // TODOПолучить бонусы для списания и добавить в мета заказа28 // Получить бонусы для списания и добавить в мета заказа 30 29 $data = BPWPApiHelper::bpwp_get_calc_bonusplus_price(); 31 30 … … 34 33 } 35 34 36 // Запрос Резервируем бонусы 37 /* 38 https://bonusplus.pro/api/Help/Api/PATCH-customer-phoneNumber-balance-reserve 39 */ 40 41 // Резервируем бонусы, передаем положительное число 42 35 43 36 $order_data = array( 44 37 'billing_phone' => bpwp_api_get_customer_phone($user_id), … … 47 40 ); 48 41 42 /* Запрос Резервируем бонусы, передаем положительное число 43 https://bonusplus.pro/api/Help/Api/PATCH-customer-phoneNumber-balance-reserve 44 */ 49 45 $balance_reserve = self::bpwp_balance_reserve($order_data); 50 46 51 52 $info = bpwp_api_get_customer_data(); 53 54 if ($info && is_array($info)) { 55 $info['availableBonuses'] = $info['availableBonuses'] - $bonus_debit; 56 57 update_user_meta($user_id, 'bonus-plus', $info); 58 } 59 60 61 //TODO В инфо заказа фильтр, начислено бонусов 62 63 /* 64 bonus-plus [ 65 'availableBonuses' => 404.0 66 ] 67 */ 68 // Обновление данных заказа 69 // if ($balance_reserve['code'] == 200){ 70 // update_order_meta($order_id, 'bonus_debit', $bonus_debit); 71 72 // //update_user_meta($order_id, 'bonus_debit', $balance_reserve['request']['customer']); 73 // } 74 75 add_post_meta( $order_id, '_bonus_debit', $bonus_debit ); 76 77 //if ($deduction == 'true') { // TODO Если пользователь подтвердил списание бонусов 78 79 // Добавим Скидку 80 $item_id = wc_add_order_item( $order_id, array( 81 'order_item_name' => 'Списание бонусов', 82 'order_item_type' => 'fee' 83 ) ); 84 85 wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( -$bonus_debit) ); 86 87 $order->calculate_totals(); 88 $order_id = $order->save(); 89 90 //} End if 91 47 if ($balance_reserve['code'] == 204) { 48 49 $info = bpwp_api_get_customer_data(); 50 51 if ($info && is_array($info)) { 52 $info['availableBonuses'] = $info['availableBonuses'] - $bonus_debit; 53 54 update_user_meta($user_id, 'bonus-plus', $info); 55 } 56 57 add_post_meta( $order_id, '_bonus_debit', $bonus_debit, true); 58 59 } else { 60 do_action( 61 'bpwp_logger', 62 $type = __CLASS__, 63 $title = __('Ошибка при резервировании бонусов', 'bonus-plus-wp'), 64 $desc = sprintf(__('У заказа ИД %s, бонусы не зарезервированы!', 'bonus-plus-wp'), $order_id), 65 ); 66 } 92 67 } 93 68 … … 106 81 $balance_reserve = bpwp_api_request( 107 82 '/customer/'. $order_data['billing_phone'] .'/balance/reserve', 108 json_encode($params),83 wp_json_encode($params), 109 84 'PATCH', 110 85 ); 111 86 112 87 return $balance_reserve; 113 } 114 115 } 116 88 89 } 90 } 117 91 118 92 /** … … 135 109 // Освобождаем из резерва, передаем отрицательное число 136 110 $balance_reserve = self::bpwp_balance_reserve($order_data); 137 } 138 139 //Проведение продажи в БонусПлюс 140 $retail = self::bpwp_get_order_bonuses($order_id); 141 142 // Обновление данных пользователя 143 if ($retail['code'] == 200){ 144 145 update_user_meta($user_id, 'bonus-plus', $retail['request']['customer']); 111 112 if ($balance_reserve['code'] == 204) { 113 114 //Проведение продажи в БонусПлюс 115 $retail = self::bpwp_get_order_bonuses($order_id); 116 117 // Обновление данных пользователя 118 if ($retail['code'] == 200){ 119 update_user_meta($user_id, 'bonus-plus', $retail['request']['customer']); 120 } else { 121 do_action( 122 'bpwp_logger', 123 $type = __CLASS__, 124 $title = __('Проведение продажи в БонусПлюс', 'bonus-plus-wp'), 125 $desc = sprintf(__('Заказа ИД %s, код ошибки %s', 'bonus-plus-wp'), $order_id,), 126 ); 127 } 128 129 } else { 130 do_action( 131 'bpwp_logger', 132 $type = __CLASS__, 133 $title = __('Ошибка при списании бонусов', 'bonus-plus-wp'), 134 $desc = sprintf(__('У заказа ИД %s, бонусы не зарезервированы!', 'bonus-plus-wp'), $order_id), 135 ); 136 } 146 137 } 147 138 } … … 181 172 // Отправим запрос "Проведение продажи в БонусПлюс" 182 173 if (!empty($billingPhone) && !empty($store) && count($items) >= 1){ 183 $retail = bpwp_api_request( 184 'retail', 185 json_encode($params), 186 'POST', 187 ); 188 174 $retail = bpwp_api_request( 175 'retail', 176 wp_json_encode($params), 177 'POST', 178 ); 189 179 return $retail; 190 180 } 191 192 181 } 193 182 -
bonus-plus-wp/trunk/inc/Logger.php
r2577633 r3033150 60 60 61 61 if (is_array($description)) { 62 $description = json_encode($description, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);62 $description = wp_json_encode($description, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); 63 63 } else { 64 64 $description = wc_print_r($description, true); … … 92 92 if (!empty($description)) { 93 93 if (is_array($description)) { 94 $description = json_encode($description, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);94 $description = wp_json_encode($description, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); 95 95 } else { 96 96 $description = wc_print_r($description, true); -
bonus-plus-wp/trunk/inc/MenuSettings.php
r3004945 r3033150 483 483 484 484 printf('<a href="%s">Вернуться...</a>', remove_query_arg('a', self::$url)); 485 485 // TODO Processing form data without nonce verification. 486 // if ( isset( $_GET['a'] ) && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'your_action_nonce' ) ) { 487 //do_action( 'bpwp_tool_actions_' . $_GET['a'] ); 488 //} 486 489 do_action('bpwp_tool_actions_' . $_GET['a']); 487 490 -
bonus-plus-wp/trunk/inc/WooAccount.php
r3004945 r3033150 34 34 add_action('wp_enqueue_scripts', [__CLASS__, 'bpwp_qrcode_scripts']); 35 35 add_filter('bpwp_debug_phone_verify', '__return_true'); 36 add_filter('woocommerce_billing_fields', [__CLASS__, 'bpwp_add_birth_date_billing_field'], 20, 1); 37 if (wp_doing_ajax()) { 38 add_action('wp_ajax_nopriv_bpwp_cv', [__CLASS__, 'bpwp_client_verify_phone_callback']); 39 add_action('wp_ajax_bpwp_cv', [__CLASS__, 'bpwp_client_verify_phone_callback']); 40 } 36 41 37 } 42 38 … … 110 106 if (empty($is_debug)) { 111 107 printf('<h2>%s</h2>', 'Информация по карте лояльности'); 108 109 echo '<div id="loader" class="center-body"><div class="loader-ball-8"></div></div>'; 112 110 113 111 //do_action('bpwp_after_bonus_card_info_title'); … … 185 183 $customerData = bpwp_api_get_customer_data(); 186 184 $cardNumber = !empty($customerData['discountCardNumber']) ? $customerData['discountCardNumber'] : ''; 187 //$clientInfo = []; 188 $apiKey = ''; 189 $sendSmsUri = ''; 190 $sendOtpUri = ''; 191 $registrationUri = ''; 192 193 if (!empty($phone = get_user_meta(get_current_user_id(), 'billing_phone', true))) { 194 $apiKey = base64_encode(esc_attr(get_option('bpwp_api_key'))); 195 $sendSmsUri = sprintf('https://bonusplus.pro/api/customer/%s/sendCode/', $phone); 196 $sendOtpUri = sprintf('https://bonusplus.pro/api/customer/%s/checkCode/', $phone); 197 $registrationUri = 'https://bonusplus.pro/api/customer/'; 198 //$clientInfo = self::bpwp_get_client_registration_data(get_current_user_id()); 199 } 185 $phone = get_user_meta(get_current_user_id(), 'billing_phone', true); 200 186 201 187 wp_enqueue_script( … … 208 194 209 195 wp_enqueue_script( 210 ' accountjs',211 plugins_url('/assets/ account.js', __DIR__),196 'customerjs', 197 plugins_url('/assets/customer.js', __DIR__), 212 198 ['qrcodejs', 'jquery'], 213 199 BPWP_PLUGIN_VERSION, … … 215 201 ); 216 202 203 wp_enqueue_script( 'wp-api' ); 204 217 205 wp_localize_script( 218 ' accountjs',206 'customerjs', 219 207 'accountBonusPlusData', 220 208 array( 221 'auth' => esc_attr($apiKey), 222 'sendSmsUri' => $sendSmsUri, 223 'sendOtpUri' => $sendOtpUri, 224 'registrationUri' => esc_attr($registrationUri), 225 'redirect' => site_url() . '/my-account/', 226 'ajax_url' => admin_url('admin-ajax.php'), 227 'cardNumber' => esc_attr($cardNumber), 228 'debug' => apply_filters('bpwp_debug_phone_verify', false), 229 'clientInfo' => json_encode(self::bpwp_get_client_registration_data(get_current_user_id())), 209 'phone' => esc_attr($phone), 210 'cardNumber' => esc_attr($cardNumber), 211 'redirect' => site_url() . '/my-account/bonus-plus/', 212 'debug' => apply_filters('bpwp_debug_phone_verify', false), 230 213 ) 231 214 ); … … 240 223 $phone = !empty(get_user_meta(get_current_user_id(), 'billing_phone', true)) ? get_user_meta(get_current_user_id(), 'billing_phone', true) : ''; 241 224 242 $birthDate = !empty(get_user_meta(get_current_user_id(), 'billing_birth_date', true)) ? get_user_meta(get_current_user_id(), 'billing_birth_date', true) : '';243 244 225 $verifiedUser = !empty(get_user_meta(get_current_user_id(), 'bpwp_verified_user', true)) ? get_user_meta(get_current_user_id(), 'bpwp_verified_user', true) : ''; 245 226 … … 248 229 if (empty($phone)) { 249 230 250 $msg .= sprintf('<h3>%s</h3>', __('Пожалуйста заполнить платежный адрес и телефон', 'bonus-plus-wp')); 251 } else if (empty($birthDate)) { 252 253 $msg .= sprintf('<h3>%s</h3>', __('Пожалуйста заполните дату рождения в платежном адресе', 'bonus-plus-wp')); 231 $msg .= sprintf('<h3>%s</h3>', __('Пожалуйста, заполните платежный адрес и телефон', 'bonus-plus-wp')); 232 $msg .= sprintf('<a href="%s">%s</a>', '/my-account/edit-address/billing/', __('Перейти к заполнению данных', 'bonus-plus-wp')); 254 233 } else if (empty($verifiedUser)) { 255 234 … … 277 256 <div hidden id="bpmsg" class="msg" style="display:none;"></div> 278 257 279 <div id="qrcode" style="display:none;"></div> 280 281 <div id='bpwp-registration' style="display:none;"> 282 <p><?= __('Вы еще не зарегистрированы в программе лояльности', 'bonus-plus-wp') ?> 258 <!-- <div id="qrcode" style="display:none;"></div> --> 259 260 <div id='bpwp-registration'> 261 <p><?php echo __('Вы еще не зарегистрированы в программе лояльности', 'bonus-plus-wp') ?></p> 262 </div> 263 264 <div id='bpwp-verify-start' style="display:none;"> 265 <p><?php echo __('Подтвердите номер телефона', 'bonus-plus-wp') ?> 266 <strong><?php echo $phone ?></strong> 283 267 </p> 284 <button id="bpwp Registration"><?= __('Создать учетную запись', 'bonus-plus-wp') ?></button>268 <button id="bpwpSendSms"><?php echo __('Отправить SMS c кодом подтверждения', 'bonus-plus-wp') ?></button> 285 269 </div> 286 270 287 <div id='bpwp-verify-start' style="display:none;">288 <p><?= __('Подтвердите номер телефона', 'bonus-plus-wp') ?>289 <strong><?= $phone ?></strong>290 </p>291 <button id="bpwpSendSms"><?= __('Отправить SMS c кодом подтверждения', 'bonus-plus-wp') ?></button>292 </div>293 294 271 <div id='bpwp-verify-end' style="display:none;"> 295 <p><? =__('Введите код высланый в SMS, на номер телефона:', 'bonus-plus-wp') ?>296 <strong><? =$phone ?></strong>272 <p><?php echo __('Введите код высланый в SMS, на номер телефона:', 'bonus-plus-wp') ?> 273 <strong><?php echo $phone ?></strong> 297 274 </p> 298 275 <input id="bpwpOtpInput" type="number" maxLength="1" size="6" min="0" max="999999" pattern="[0-9]{6}" /> 299 <button id="bpwpSendOtp"><? =__('Подтвердить номер телефона', 'bonus-plus-wp') ?></button>276 <button id="bpwpSendOtp"><?php echo __('Подтвердить номер телефона', 'bonus-plus-wp') ?></button> 300 277 </div> 301 278 </div> 302 279 <?php 303 }304 305 /**306 * Добавим обязательное поле "Дата рождения" в платежный адрес307 */308 public static function bpwp_add_birth_date_billing_field($billing_fields)309 {310 $billing_fields['billing_birth_date'] = array(311 'type' => 'date',312 'label' => __('Дата рождения', 'bonus-plus-wp'),313 'class' => array('form-row-wide'),314 'priority' => 25,315 'required' => true,316 'clear' => true,317 );318 319 return $billing_fields;320 }321 322 /**323 * AJAX Callback324 * Always Echos and Exits325 */326 public static function bpwp_client_verify_phone_callback()327 {328 // Ensure we have the data we need to continue329 if (!is_user_logged_in()) {330 // If we don't - return custom error message and exit331 header('HTTP/1.1 400 Empty POST Values');332 wp_send_json('Could Not Verify POST Values.');333 wp_die();334 }335 $user_id = get_current_user_id();336 337 // if user already register, make verify phone request338 $phone = bpwp_api_get_customer_phone($user_id);339 340 if (!empty($phone)) {341 $res = bpwp_api_request(342 'customer',343 array(344 'phone' => $phone345 ),346 'GET'347 );348 if (!empty($res['request'])) {349 $response = $res['request']['response'];350 update_user_meta($user_id, 'bonus-plus', $res['request']);351 $result = $res['request'];352 // todo353 // ... parse response data and return cardnumber354 wp_send_json($res);355 wp_die();356 }357 }358 280 } 359 281 … … 379 301 $billingEmail = !empty($customer['billing_email']) ? $customer['billing_email'] : '-'; 380 302 $billingPhone = !empty($customer['billing_phone']) ? $customer['billing_phone'] : '-'; 381 // ДД.ММ.ГГГГ382 if (isset($customer['billing_birth_date'])) {383 $originalBDate = $customer['billing_birth_date'][0];384 $newBDate = date("d.m.Y", strtotime($originalBDate));385 } else {386 $newBDate = '';387 }388 303 389 304 $registrationData = array(); 390 305 391 if ($firstName && $lastName && $ newBDate && $billingEmail && $billingPhone) {306 if ($firstName && $lastName && $billingEmail && $billingPhone) { 392 307 /* 393 308 $registrationData['phone'] = $billingPhone; … … 405 320 'ln' => $lastName[0], 406 321 'desc' => __('Регистрация на сайте', 'bonus-plus-wp'), 407 'birthDay' => $newBDate,408 322 ); 409 323 //$registrationData['address'] = $billingPostcode . $billingCountry . $billingState . $billingCity . $address1 . $address2; … … 412 326 return $registrationData; 413 327 } 328 414 329 } 330 415 331 BPWPMyAccount::init(); -
bonus-plus-wp/trunk/inc/WooProductCatExport.php
r3011611 r3033150 314 314 $export = bpwp_api_request( 315 315 'product/import', 316 json_encode($params),316 wp_json_encode($params), 317 317 'POST', 318 318 ); … … 383 383 ?> 384 384 <div class="wrap"> 385 <div id="message" class="<? =esc_attr($class) ?>">385 <div id="message" class="<?php echo esc_attr($class) ?>"> 386 386 <?php 387 387 foreach ($strings as $string) { … … 404 404 //Get all terms associated with post in woocommerce's taxonomy 'product_cat' 405 405 $terms = get_the_terms($productId, 'product_cat'); 406 407 //Get an array of their IDs 408 $term_ids = wp_list_pluck($terms, 'term_id'); 409 410 //Get array of parents - 0 is not a parent 411 $parents = array_filter(wp_list_pluck($terms, 'parent')); 412 413 //Get array of IDs of terms which are not parents. 414 $term_ids_not_parents = array_diff($term_ids, $parents); 415 416 //Get corresponding term objects. 417 $terms_not_parents = array_intersect_key($terms, $term_ids_not_parents); 418 419 return $terms_not_parents; 406 407 // Check if terms exist and is not a WP_Error 408 if (is_array($terms) && !is_wp_error($terms)) { 409 410 //Get an array of their IDs 411 $term_ids = wp_list_pluck($terms, 'term_id'); 412 413 //Get array of parents - 0 is not a parent 414 $parents = array_filter(wp_list_pluck($terms, 'parent')); 415 416 //Get array of IDs of terms which are not parents. 417 $term_ids_not_parents = array_diff($term_ids, $parents); 418 419 //Get corresponding term objects. 420 $terms_not_parents = array_intersect_key($terms, $term_ids_not_parents); 421 422 return $terms_not_parents; 423 } 424 425 // Return an empty array if there are no terms or an error occurred 426 return array(); 420 427 } 421 428 } -
bonus-plus-wp/trunk/readme.txt
r3011611 r3033150 5 5 Requires at least: 4.0 6 6 Tested up to: 6.4.2 7 Stable tag: 2. 77 Stable tag: 2.8 8 8 Requires PHP: 8.1 9 9 License: GPLv2 or later … … 46 46 = Automatic installation = 47 47 48 Automatic installation is the easiest option -- WordPress will handles the file transfer, and you won’t need to leave your web browser. To do an automatic install of WP-bonus-plus, log in to your WordPress dashboard, navigate to the Plugins menu, and click “Add New.”48 Automatic installation is the easiest option -- WordPress will handles the file transfer, and you won’t need to leave your web browser. To do an automatic install of bonus-plus-wp, log in to your WordPress dashboard, navigate to the Plugins menu, and click “Add New.” 49 49 50 In the search field type “ wp-bonus-plus,” then click “Search Plugins.” Once you’ve found us, you can view details about it such as the point release, rating, and description. Most importantly of course, you can install it by! Click “Install Now,” and WordPress will take it from there.50 In the search field type “bonus-plus-wp,” then click “Search Plugins.” Once you’ve found us, you can view details about it such as the point release, rating, and description. Most importantly of course, you can install it by! Click “Install Now,” and WordPress will take it from there. 51 51 52 52 = Manual installation = 53 53 54 Manual installation method requires downloading the wp-bonus-plusplugin and uploading it to your web server via your favorite FTP application. The WordPress codex contains [instructions on how to do this here](https://wordpress.org/support/article/managing-plugins/#manual-plugin-installation).54 Manual installation method requires downloading the bonus-plus-wp plugin and uploading it to your web server via your favorite FTP application. The WordPress codex contains [instructions on how to do this here](https://wordpress.org/support/article/managing-plugins/#manual-plugin-installation). 55 55 56 56 … … 92 92 93 93 == Changelog == 94 95 = 2.8 = 96 - убрали поле "дата рождения" из личного кабинета https://github.com/evgrezanov/bonus-plus-wp/issues/58 97 - добавлена обработка ошибок при экспорте товаров и категорий https://github.com/evgrezanov/bonus-plus-wp/issues/56 98 - рефакторинг процесса авторизации и регистрации в программе лояльности https://github.com/evgrezanov/bonus-plus-wp/issues/47 99 - исправлена функция списания и резервирования бонусов https://github.com/evgrezanov/bonus-plus-wp/issues/40 100 - исправлена проблема с безопастностью при генерации QR кода в личном кабинете исправить проблему с безопастностью https://github.com/evgrezanov/bonus-plus-wp/issues/21 94 101 95 102 = 2.7 = -
bonus-plus-wp/trunk/templates/client-account.php
r2627044 r3033150 10 10 11 11 <div id='bpwp-registration' style="display:none;"> 12 <p><? =__('Вы еще не зарегистрированы в программе лояльности', 'bonus-plus-wp') ?>12 <p><?php echo __('Вы еще не зарегистрированы в программе лояльности', 'bonus-plus-wp') ?> 13 13 </p> 14 <button id="bpwpRegistration"><? =__('Продолжить регистрацию', 'bonus-plus-wp') ?></button>14 <button id="bpwpRegistration"><?php echo __('Продолжить регистрацию', 'bonus-plus-wp') ?></button> 15 15 </div> 16 16 17 17 <div id='bpwp-verify-start' style="display:none;"> 18 <p><? =__('Для завершения регистрации в Бонус+, подтвердите номер телефона, после отправки СМС', 'bonus-plus-wp') ?>19 <strong><?= $phone?></strong>18 <p><?php echo __('Для завершения регистрации в Бонус+, подтвердите номер телефона, после отправки СМС', 'bonus-plus-wp') ?> 19 <strong><?php echo $phone; ?></strong> 20 20 </p> 21 <button id="bpwpSendSms"><? = __('Отправить SMS c кодом подтверждения', 'bonus-plus-wp')?></button>21 <button id="bpwpSendSms"><?php echo __('Отправить SMS c кодом подтверждения', 'bonus-plus-wp'); ?></button> 22 22 </div> 23 23 24 24 <div id='bpwp-verify-end' style="display:none;"> 25 <p><? = __('Введите код высланый в SMS, на номер телефона:', 'bonus-plus-wp') ?>26 <strong><?= $phone?></strong>25 <p><?php echo __('Введите код высланый в SMS, на номер телефона:', 'bonus-plus-wp'); ?></p> 26 <strong><?php echo $phone; ?></strong> 27 27 </p> 28 28 <input id="bpwpOtpInput" type="number" maxLength="1" size="6" min="0" max="999999" pattern="[0-9]{6}" /> 29 <button id="bpwpSendOtp"><? = __('Подтвердить', 'bonus-plus-wp')?></button>29 <button id="bpwpSendOtp"><?php echo __('Подтвердить', 'bonus-plus-wp'); ?></button> 30 30 </div> 31 31 </div>
Note: See TracChangeset
for help on using the changeset viewer.