Changeset 3494822
- Timestamp:
- 03/30/2026 04:49:43 PM (2 days ago)
- Location:
- wc-leanpay/trunk
- Files:
-
- 13 edited
-
CHANGELOG.md (modified) (1 diff)
-
README.md (modified) (4 diffs)
-
assets/js/admin.js (modified) (2 diffs)
-
assets/js/leanpay.js (modified) (1 diff)
-
assets/js/variations.js (modified) (1 diff)
-
changelog.txt (modified) (1 diff)
-
includes/leanpay_admin_settings.php (modified) (1 diff)
-
includes/leanpay_frontend_display.php (modified) (11 diffs)
-
includes/leanpay_get_update_data.php (modified) (1 diff)
-
includes/leanpay_globals.php (modified) (2 diffs)
-
includes/leanpay_payment_confirmation.php (modified) (1 diff)
-
readme.txt (modified) (6 diffs)
-
wc-leanpay.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wc-leanpay/trunk/CHANGELOG.md
r3492436 r3494822 5 5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 8 ## [6.0.4] - 2026-03-30 9 10 ### Changed 11 - Markets limited to Slovenia (SI) and Romania (RO); Croatia and Hungary removed from settings and logic. 12 - Removed the "Double price" feature (settings and front-end display). 13 14 ### Added 15 - Added market-specific 0% interest price threshold (Romania does not support 0% interest rate); exposed to leanpay.js via localized params. 16 17 ### Fixed 18 - Variable products: fixed AJAX HTML for Leanpay block (banner + modal), nonce security, and locale switching so translated strings load on variation change. 19 - Translations: AJAX requests send `determine_locale()` and use `switch_to_locale()` so strings match the current language. 20 21 ### Technical 22 - Enqueued JS for reliable cache busting. 7 23 8 24 ## [6.0.3] - 2026-03-27 -
wc-leanpay/trunk/README.md
r3492436 r3494822 4 4 **Tags:** woocommerce, payment, payment-gateway, installment, leanpay 5 5 **Requires at least:** 5.0 6 **Tested up to:** 6.9 .16 **Tested up to:** 6.9 7 7 **Requires PHP:** 7.4 8 8 **WC requires at least:** 5.0 9 9 **WC tested up to:** 10.4.3 10 **Stable tag:** 6.0. 310 **Stable tag:** 6.0.4 11 11 **License:** GPLv2 or later 12 12 **License URI:** https://www.gnu.org/licenses/gpl-2.0.html … … 21 21 22 22 * **Easy Installment Payments** - Customers can split their purchases into affordable monthly payments 23 * **Multiple Market Support** - Available for Slovenia , Croatia, Romania, and Hungary23 * **Multiple Market Support** - Available for Slovenia and Romania 24 24 * **Flexible Display Options** - Show installment information on catalog pages, product pages, and checkout 25 25 * **Customizable Design** - Customize colors, sizes, and styling to match your store's branding … … 80 80 ### Which countries are supported? 81 81 82 Currently, the plugin supports Slovenia , Croatia, Romania, and Hungary.82 Currently, the plugin supports Slovenia and Romania. 83 83 84 84 ### Can I customize the appearance? … … 125 125 ### Service URLs 126 126 127 The plugin connects to Leanpay domains depending on the configured market (Slovenia , Croatia, Romania, Hungary) and mode (production or sandbox), for example: `app.leanpay.si`, `stage-app.leanpay.si`, `app.leanpay.hr`, `test-app.leanpay.ro`, `test-app.leanpay.hu`, etc.127 The plugin connects to Leanpay domains depending on the configured market (Slovenia or Romania) and mode (production or sandbox), for example: `app.leanpay.si`, `stage-app.leanpay.si`, `app.leanpay.ro`, `test-app.leanpay.ro`. 128 128 129 129 ### Service provider and legal documents -
wc-leanpay/trunk/assets/js/admin.js
r3492394 r3494822 1 1 jQuery(document).ready(function($) { 2 var market_endpoint = jQuery('#woocommerce_wc_leanpay_module_market_endpoint');3 2 var success_url = jQuery('#woocommerce_wc_leanpay_module_success_url_checkbox'); 4 3 var failure_url = jQuery('#woocommerce_wc_leanpay_module_failure_url_checkbox'); … … 54 53 } 55 54 }); 56 market_endpoint.on('change load', function() {57 toggle_double_price();58 });59 toggle_double_price();60 61 55 jQuery('ul.subsubsub li').click(function(e) { 62 56 jQuery(this).addClass('current'); 63 57 }); 64 65 function toggle_double_price() {66 if(market_endpoint.val() == 'hr') {67 jQuery('#woocommerce_wc_leanpay_module_double_price').closest('tr').css("display", "table-row");68 } else {69 jQuery("#woocommerce_wc_leanpay_module_double_price").closest("tr").css("display", "none");70 }71 }72 58 73 59 jQuery('#woocommerce_wc_leanpay_module_API_vendor_url').on("click", function(e) { -
wc-leanpay/trunk/assets/js/leanpay.js
r3492436 r3494822 161 161 }); 162 162 163 // Show/hide zero interest message based on price <= 300 ANDinstalments = 3163 // Show/hide zero interest message based on market-specific threshold and instalments = 3 164 164 const productPrice = parseFloat(jQuery("#leanpay_inst_slider").data("product-price")) || 0; 165 165 const activeInstalments = parseInt($active.text()) || 0; 166 166 const $zeroInterest = jQuery("#instalment_details_price_zero_interest"); 167 168 if (productPrice <= 300 && activeInstalments === 3) { 167 const threshold = (typeof leanpay_price_params !== "undefined" && typeof leanpay_price_params.price_threshold !== "undefined") 168 ? parseFloat(leanpay_price_params.price_threshold) 169 : 300; 170 171 if (productPrice <= threshold && activeInstalments === 3) { 169 172 $zeroInterest.removeClass("hidden").addClass("visible"); 170 173 } else { -
wc-leanpay/trunk/assets/js/variations.js
r3492436 r3494822 1 jQuery(document).ready(function() { 2 jQuery( '.variations_form' ).each( function() { 3 jQuery(this).on( 'found_variation', function( event, variation ) { 4 var price = variation.display_price; 5 console.log(price); 6 jQuery.ajax({ 7 type: "POST", 8 url: leanpayAjax.ajaxurl, 9 data: '&price='+price+'&action=get_leanpay_variation', 10 success: function(data) { 11 if(data!=''){ 12 console.log(data); 13 jQuery('.leanpay-product-price-wrapp').replaceWith(data); 14 } 15 else { 16 console.log("no data"); 17 } 18 }, 19 }); 20 21 }); 22 }); 23 24 jQuery( '.grouped_form' ).each( function() { 25 jQuery(this).on( 'found_variation', function( event, variation ) { 26 var price = variation.display_price; 27 console.log(price); 28 jQuery.ajax({ 29 type: "POST", 30 url: leanpayAjax.ajaxurl, 31 data: '&price='+price+'&action=get_leanpay_variation', 32 success: function(data) { 33 if(data!=''){ 34 console.log(data); 35 jQuery('.leanpay-product-price-wrapp').replaceWith(data); 36 } 37 else { 38 console.log("no data"); 39 } 40 }, 41 }); 42 43 }); 44 }); 45 46 jQuery('#leanpay_hr_instalments_status').click(function() { 47 if (jQuery('#leanpay_hr_instalments_status').prop('checked')) { 48 jQuery('.leanpay_hr_instalments_select').show('slow'); 49 } 50 }); 51 52 }); 1 jQuery( function( $ ) { 2 var leanpayInitialBlockHtml = null; 3 4 function rememberInitialLeanpayBlock() { 5 var $wrap = $( '.leanpay-product-price-wrapp' ).first(); 6 if ( $wrap.length && leanpayInitialBlockHtml === null ) { 7 leanpayInitialBlockHtml = $wrap.prop( 'outerHTML' ); 8 } 9 } 10 11 function replaceLeanpayBlock( html ) { 12 if ( ! html || typeof html !== 'string' || html.trim() === '' ) { 13 return; 14 } 15 var $target = $( '.leanpay-product-price-wrapp' ).first(); 16 if ( $target.length ) { 17 $target.replaceWith( html ); 18 } 19 } 20 21 function fetchLeanpayForPrice( price ) { 22 var n = parseFloat( price ); 23 if ( isNaN( n ) || n <= 0 ) { 24 return; 25 } 26 $.ajax( { 27 type: 'POST', 28 url: leanpayAjax.ajaxurl, 29 data: { 30 action: 'get_leanpay_variation', 31 price: n, 32 nonce: leanpayAjax.nonce, 33 locale: typeof leanpayAjax.locale !== 'undefined' ? leanpayAjax.locale : '' 34 }, 35 success: function( data ) { 36 replaceLeanpayBlock( data ); 37 } 38 } ); 39 } 40 41 $( document.body ).on( 'found_variation', '.variations_form', function( event, variation ) { 42 rememberInitialLeanpayBlock(); 43 var price = variation.display_price; 44 if ( price === undefined || price === null || price === '' ) { 45 price = variation.price; 46 } 47 fetchLeanpayForPrice( price ); 48 } ); 49 50 $( document.body ).on( 'hide_variation', '.variations_form', function() { 51 if ( leanpayInitialBlockHtml ) { 52 replaceLeanpayBlock( leanpayInitialBlockHtml ); 53 } 54 } ); 55 56 rememberInitialLeanpayBlock(); 57 } ); -
wc-leanpay/trunk/changelog.txt
r3492436 r3494822 1 1 == Changelog == 2 3 = 6.0.4 - 2026-03-30 = 4 * Removed Croatia and Hungary market options; only Slovenia (SI) and Romania (RO) are supported. 5 * Removed the "Double price" setting and all related front-end logic. 6 * Added market-specific 0% interest price threshold (Romania does not support 0% interest rate); exposed to leanpay.js via localized params. 7 * Enqueued JS for reliable cache busting. 8 * Variable products: fixed AJAX HTML for Leanpay block (banner + modal), nonce security, and locale switching so translated strings load on variation change. 2 9 3 10 = 6.0.3 - 2026-03-27 = -
wc-leanpay/trunk/includes/leanpay_admin_settings.php
r3492436 r3494822 327 327 'class' => 'wc-enhanced-select', 328 328 'description' => __('Select the market endpoint for the payment method', 'wc-leanpay') , 329 'default' => ' Slovenia',329 'default' => 'si', 330 330 'options' => array( 331 331 'si' => 'Slovenia', 332 'hr' => 'Croatia',333 332 'ro' => 'Romania', 334 'hu' => 'Hungary',335 333 ) 336 334 ) , 337 'double_price' => array(338 'title' => __('Double price', 'wc-leanpay') ,339 'label' => __('Enabled / Disabled', 'wc-leanpay') ,340 'type' => 'checkbox',341 'description' => __('Croatia specific - Showing multi-currency prices at divided prices (example: EUR and Kn both)', 'wc-leanpay') ,342 'desc_tip' => __('Croatia specific - Showing multi-currency prices at divided prices (example: EUR and Kn both)', 'wc-leanpay') ,343 'default' => 'no',344 ),345 335 'test_ips' => array( 346 336 'title' => __('Limit from which IP addresses can Leanpay payment method be used (for testing)', 'wc-leanpay') , -
wc-leanpay/trunk/includes/leanpay_frontend_display.php
r3492436 r3494822 27 27 global $product; 28 28 $settings = new Leanpay_Gateway(); 29 $price_threshold = leanpay_get_price_threshold( $settings->market_endpoint ); 29 30 $price = wc_get_price_including_tax($product); 30 31 … … 72 73 73 74 // Check if price is below threshold for 0% interest display 74 $is_interest_free = ($price <= LEANPAY_PRICE_THRESHOLD);75 $is_interest_free = ($price <= $price_threshold); 75 76 76 77 // For prices <= threshold: show fewest installments (last element - most expensive per month) … … 82 83 $installment_amount = $selected_installment['installmentAmout']; 83 84 $show_price = wc_price( $installment_amount ); 84 if( $settings->double_price == 'yes' )85 {86 if( get_woocommerce_currency() == 'HRK' )87 $show_price .= ' (' . wc_price( $installment_amount / 7.53450, array( 'currency' => 'EUR' ) ) . ')';88 elseif( get_woocommerce_currency() == 'EUR' )89 $show_price .= ' (' . wc_price( $installment_amount * 7.53450, array( 'currency' => 'HRK' ) ) . ')';90 }91 85 92 86 … … 120 114 { 121 115 $settings = new Leanpay_Gateway(); 116 $price_threshold = leanpay_get_price_threshold( $settings->market_endpoint ); 122 117 123 118 if ((!is_product() && $variation_price == '') || ($settings->API_id == "") || ($settings->on_product_pages == 'no')) return; … … 160 155 161 156 // Check if price is below threshold for 0% interest display 162 $is_interest_free = ($price <= LEANPAY_PRICE_THRESHOLD);157 $is_interest_free = ($price <= $price_threshold); 163 158 164 159 $html .= '<div class="leanpay-product-price-wrapp">'; … … 199 194 $show_price = wc_price( $selected_installment['installmentAmout'] ); 200 195 $show_price_plain = wp_strip_all_tags($show_price); 201 if( $settings->double_price == 'yes' )202 {203 if( get_woocommerce_currency() == 'HRK' )204 $show_price .= ' (' . wc_price( $selected_installment['installmentAmout'] / 7.53450, array( 'currency' => 'EUR' ) ) . ')';205 elseif( get_woocommerce_currency() == 'EUR' )206 $show_price .= ' (' . wc_price( $selected_installment['installmentAmout'] * 7.53450, array( 'currency' => 'HRK' ) ) . ')';207 }208 196 209 197 // Banner-style button … … 229 217 { 230 218 $months[] = $instalment_option['numberOfMonths']; 231 if( $settings->double_price == 'yes' ) 232 { 233 if( get_woocommerce_currency() == 'HRK' ) 234 $inst_amount[] = wc_price( $instalment_option['installmentAmout'] ) . ' (' . wc_price( $instalment_option['installmentAmout'] / 7.53450, array( 'currency' => 'EUR' ) ) . ')'; 235 elseif( get_woocommerce_currency() == 'EUR' ) 236 $inst_amount[] = wc_price( $instalment_option['installmentAmout'] ) . ' (' . wc_price( $instalment_option['installmentAmout'] * 7.53450, array( 'currency' => 'HRK' ) ) . ')'; 237 } 238 else 239 $inst_amount[] = wc_price( $instalment_option['installmentAmout'] ); 219 $inst_amount[] = wc_price( $instalment_option['installmentAmout'] ); 240 220 } 241 221 … … 297 277 298 278 299 if ($tag == "leanpay_product_page") 300 { 279 if ($tag === 'leanpay_product_page' || $tag === 'variation') { 301 280 return wp_kses_post($html); 302 281 } 303 else 304 { 305 echo wp_kses_post($html); 306 } 282 283 echo wp_kses_post($html); 307 284 } 308 285 … … 315 292 } 316 293 $market_endpoint = $settings->market_endpoint; 294 $price_threshold = leanpay_get_price_threshold( $market_endpoint ); 317 295 $price = WC()->cart->total; 318 296 319 297 // Check if price is below threshold for 0% interest display 320 $is_interest_free = ($price <= LEANPAY_PRICE_THRESHOLD);298 $is_interest_free = ($price <= $price_threshold); 321 299 322 300 if ($price < $settings->min_order_total || $price > $settings->max_order_total || ($settings->on_checkout_page == 'no')) return ''; … … 380 358 $show_price = wc_price( $selected_installment['installmentAmout'] ); 381 359 $show_price_plain = wp_strip_all_tags($show_price); 382 if( $settings->double_price == 'yes' )383 {384 if( get_woocommerce_currency() == 'HRK' )385 $show_price .= ' (' . wc_price( $selected_installment['installmentAmout'] / 7.53450, array( 'currency' => 'EUR' ) ) . ')';386 elseif( get_woocommerce_currency() == 'EUR' )387 $show_price .= ' (' . wc_price( $selected_installment['installmentAmout'] * 7.53450, array( 'currency' => 'HRK' ) ) . ')';388 }389 360 390 361 // Banner-style button … … 410 381 { 411 382 $months[] = $instalment_option['numberOfMonths']; 412 if( $settings->double_price == 'yes' ) 413 { 414 if( get_woocommerce_currency() == 'HRK' ) 415 $inst_amount[] = wc_price( $instalment_option['installmentAmout'] ) . ' (' . wc_price( $instalment_option['installmentAmout'] / 7.53450, array( 'currency' => 'EUR' ) ) . ')'; 416 elseif( get_woocommerce_currency() == 'EUR' ) 417 $inst_amount[] = wc_price( $instalment_option['installmentAmout'] ) . ' (' . wc_price( $instalment_option['installmentAmout'] * 7.53450, array( 'currency' => 'HRK' ) ) . ')'; 418 } 419 else 420 $inst_amount[] = wc_price( $instalment_option['installmentAmout'] ); 383 $inst_amount[] = wc_price( $instalment_option['installmentAmout'] ); 421 384 } 422 385 -
wc-leanpay/trunk/includes/leanpay_get_update_data.php
r3492436 r3494822 175 175 176 176 $environment = "app"; 177 if( ( $settings->sandbox_mode == 'yes' ) && ( ( $settings->market_endpoint == 'ro' ) || ( $settings->market_endpoint == 'hu' )) )177 if( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'ro' ) ) 178 178 $environment = 'test-app'; 179 179 elseif( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'si' ) ) -
wc-leanpay/trunk/includes/leanpay_globals.php
r3492436 r3494822 9 9 */ 10 10 define('LEANPAY_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__DIR__))); 11 define('LEANPAY_VERSION', '6.0. 3'); // WRCS: DEFINED_VERSION. Must match Plugin Version in main file header.11 define('LEANPAY_VERSION', '6.0.4'); // WRCS: DEFINED_VERSION. Must match Plugin Version in main file header. 12 12 define('LEANPAY_MIN_PHP_VER', '1.0.0'); 13 13 define('LEANPAY_MIN_WC_VER', '5.9'); … … 24 24 define('LEANPAY_PRICE_THRESHOLD', 300); 25 25 26 /** 27 * Return market-specific threshold for 0% interest messaging. 28 * 29 * @param string $market_endpoint Leanpay market endpoint. 30 * @return int 31 */ 32 function leanpay_get_price_threshold( $market_endpoint ) { 33 return ( $market_endpoint === 'ro' ) ? 0 : LEANPAY_PRICE_THRESHOLD; 34 } 35 26 36 ?> -
wc-leanpay/trunk/includes/leanpay_payment_confirmation.php
r3492436 r3494822 26 26 $leanpay_environment = "app"; 27 27 28 if( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( ( $leanpay_settings->market_endpoint == 'ro' ) || ( $leanpay_settings->market_endpoint == 'hu' )) )28 if( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( $leanpay_settings->market_endpoint == 'ro' ) ) 29 29 $leanpay_environment = 'test-app'; 30 30 elseif( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( $leanpay_settings->market_endpoint == 'si' ) ) -
wc-leanpay/trunk/readme.txt
r3492436 r3494822 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 6.0. 37 Stable tag: 6.0.4 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 19 19 * Installment payment option on checkout 20 20 * Installment display on catalog and product pages 21 * Support for Slovenia , Croatia, Romania, and Hungary21 * Support for Slovenia and Romania 22 22 * Sandbox mode for testing 23 23 * WooCommerce Blocks compatibility … … 50 50 = Which markets are supported? = 51 51 52 Slovenia , Croatia, Romania, and Hungary.52 Slovenia and Romania. 53 53 54 54 == External services == … … 75 75 76 76 The plugin connects to Leanpay domains based on selected market and mode, for example: 77 `app.leanpay.si`, `stage-app.leanpay.si`, `app.leanpay.ro`, `test-app.leanpay.ro` , `app.leanpay.hu`, `test-app.leanpay.hu`.77 `app.leanpay.si`, `stage-app.leanpay.si`, `app.leanpay.ro`, `test-app.leanpay.ro`. 78 78 79 79 = Service provider terms and privacy = … … 93 93 == Changelog == 94 94 95 = 6.0. 3=95 = 6.0.4 = 96 96 97 97 See `changelog.txt` for full release history. … … 99 99 == Upgrade Notice == 100 100 101 = 6.0. 3=101 = 6.0.4 = 102 102 103 Ma intenance and compatibility updates for WordPress.org requirements.103 Market-specific pricing thresholds, improved variable-product Leanpay UI, translation fixes for AJAX, and script cache-busting. Croatia and Hungary markets removed; Slovenia and Romania only. -
wc-leanpay/trunk/wc-leanpay.php
r3492436 r3494822 7 7 * Author: Leanpay 8 8 * Author URI: https://leanpay.com 9 * Version: 6.0. 39 * Version: 6.0.4 10 10 * Text Domain: wc-leanpay 11 11 * Domain Path: /languages 12 12 * WC tested up to: 10.4.3 13 * WordPress tested up to: 6.9 .113 * WordPress tested up to: 6.9 14 14 * License: GPL-2.0+ 15 15 * Requires Plugins: woocommerce … … 400 400 public $check_limit_url; 401 401 public $sandbox_mode; 402 public $double_price;403 402 public $test_ips; 404 403 public $completed_status; … … 462 461 $this->info_page_url = $this->get_option("info_page_url"); 463 462 $this->market_endpoint = $this->get_option("market_endpoint"); 464 $this->double_price = $this->get_option("double_price");465 463 $this->test_ips = $this->get_option("test_ips"); 466 464 … … 530 528 add_action("admin_enqueue_scripts", [$this, "admin_scripts"]); 531 529 532 add_action( 'wp_enqueue_scripts', [$this, "leanpay_localize_wc_price_params"]); 533 534 535 } 536 537 function leanpay_localize_wc_price_params() { 538 // ensure woocommerce is active 539 if ( ! function_exists( 'wc_get_price_decimals' ) ) { 540 return; 541 } 542 543 $params = array( 544 'currency_symbol' => html_entity_decode( get_woocommerce_currency_symbol() ), // € 545 'currency_pos' => get_option( 'woocommerce_currency_pos', 'left' ), // left, right, left_space, right_space 546 'decimal_separator' => wc_get_price_decimal_separator(), // . or , 547 'thousand_separator' => wc_get_price_thousand_separator(), // , or . 548 'decimals' => wc_get_price_decimals(), // int 549 ); 550 551 // Replace 'my-script-handle' with the handle of the script that needs params. 552 // If you don't have a custom script, enqueue one and localize it. 553 wp_enqueue_script( 'leanpay-price-script', get_stylesheet_directory_uri() . '/js/my-price.js', array(), 1, true ); 554 wp_localize_script( 'leanpay-price-script', 'leanpay_price_params', $params ); 555 } 530 } 531 532 private function leanpay_get_wc_price_params() { 533 if ( ! function_exists( 'wc_get_price_decimals' ) ) { 534 return array(); 535 } 536 537 return array( 538 'currency_symbol' => html_entity_decode( get_woocommerce_currency_symbol() ), 539 'currency_pos' => get_option( 'woocommerce_currency_pos', 'left' ), 540 'decimal_separator' => wc_get_price_decimal_separator(), 541 'thousand_separator' => wc_get_price_thousand_separator(), 542 'decimals' => wc_get_price_decimals(), 543 'price_threshold' => leanpay_get_price_threshold( $this->market_endpoint ), 544 ); 545 } 556 546 557 547 function init_form_fields() … … 694 684 plugin_dir_url(__FILE__) . "assets/js/leanpay.js", 695 685 [], 696 "1.0.0",686 LEANPAY_VERSION, 697 687 true 698 688 ); 689 wp_localize_script( "leanpay_script", "leanpay_price_params", $this->leanpay_get_wc_price_params() ); 699 690 700 691 wp_register_script( 701 692 "leanpay_variations_js", 702 693 plugin_dir_url(__FILE__) . "assets/js/variations.js", 703 [],704 "1.0.0",694 array( 'jquery', 'wc-add-to-cart-variation' ), 695 LEANPAY_VERSION, 705 696 true 706 697 ); 707 wp_localize_script("leanpay_variations_js", "leanpayAjax", [ 708 "ajaxurl" => admin_url("admin-ajax.php"), 709 ]); 710 wp_enqueue_script("leanpay_variations_js"); 698 wp_localize_script( 699 "leanpay_variations_js", 700 "leanpayAjax", 701 array( 702 'ajaxurl' => admin_url( 'admin-ajax.php' ), 703 'nonce' => wp_create_nonce( 'leanpay_variation' ), 704 // Current frontend locale (Polylang/WPML/multilingual plugins filter determine_locale). 705 'locale' => determine_locale(), 706 ) 707 ); 708 wp_enqueue_script( 'leanpay_variations_js' ); 711 709 } 712 710 … … 894 892 if ($this->market_endpoint == 'ro') 895 893 $amount = 250; 896 elseif ($this->market_endpoint == 'hu')897 $amount = 25000;898 894 else 899 895 $amount = 50; … … 915 911 if ($this->market_endpoint == 'ro') 916 912 $amount = 25000; 917 elseif ($this->market_endpoint == 'hu')918 $amount = 2000000;919 913 else 920 914 $amount = 5000; … … 937 931 public function validate_market_endpoint_field($key, $value) 938 932 { 933 if ( ! in_array( $value, array( 'si', 'ro' ), true ) ) { 934 return 'si'; 935 } 939 936 // legacy code, to be removed 940 937 /* … … 946 943 if ($value == "si") { 947 944 $slug = "leanpay_info_page"; 948 leanpay_generate_info_page($slug, $remove_old);949 }950 elseif ($value == "hr") {951 $slug = "leanpay_info_page_hr";952 945 leanpay_generate_info_page($slug, $remove_old); 953 946 } … … 1218 1211 $environment = "app"; 1219 1212 1220 if( ( $settings->sandbox_mode == 'yes' ) && ( ( $settings->market_endpoint == 'ro' ) || ( $settings->market_endpoint == 'hu' )) )1213 if( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'ro' ) ) 1221 1214 $environment = 'test-app'; 1222 1215 elseif( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'si' ) ) … … 1254 1247 $environment = "app"; 1255 1248 1256 if( ( $settings->sandbox_mode == 'yes' ) && ( ( $settings->market_endpoint == 'ro' ) || ( $settings->market_endpoint == 'hu' )) )1249 if( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'ro' ) ) 1257 1250 $environment = 'test-app'; 1258 1251 elseif( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'si' ) ) … … 1277 1270 function leanpay_get_variation() 1278 1271 { 1279 // Verify nonce for AJAX request (optional for non-logged-in users, but recommended) 1280 if (is_user_logged_in()) { 1281 if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'leanpay_variation')) { 1282 wp_die(); 1283 } 1284 } 1272 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'leanpay_variation' ) ) { 1273 wp_die( '', '', 403 ); 1274 } 1275 1285 1276 require_once plugin_dir_path(__FILE__) ."/includes/leanpay_frontend_display.php"; 1286 1277 $price = isset($_POST["price"]) ? sanitize_text_field(wp_unslash($_POST["price"])) : ''; … … 1292 1283 $price = floatval($price); 1293 1284 1294 echo esc_html(leanpay_show_on_product_page("", "", "variation", $price)); 1295 die(); 1285 // Match the page language: admin-ajax.php defaults to site locale; switch for gettext/WooCommerce strings. 1286 $locale = isset( $_POST['locale'] ) ? sanitize_text_field( wp_unslash( $_POST['locale'] ) ) : ''; 1287 if ( $locale !== '' && ! preg_match( '/^[a-zA-Z0-9_-]+$/', $locale ) ) { 1288 $locale = ''; 1289 } 1290 1291 $switched = false; 1292 if ( $locale !== '' && function_exists( 'switch_to_locale' ) ) { 1293 $switched = (bool) switch_to_locale( $locale ); 1294 } 1295 1296 $output = leanpay_show_on_product_page( '', '', 'variation', $price ); 1297 1298 if ( $switched && function_exists( 'restore_previous_locale' ) ) { 1299 restore_previous_locale(); 1300 } 1301 1302 echo $output; 1303 wp_die(); 1296 1304 } 1297 1305
Note: See TracChangeset
for help on using the changeset viewer.