Plugin Directory

Changeset 3494822


Ignore:
Timestamp:
03/30/2026 04:49:43 PM (2 days ago)
Author:
leanpay
Message:

Release 6.0.4

Location:
wc-leanpay/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • wc-leanpay/trunk/CHANGELOG.md

    r3492436 r3494822  
    55The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
    66and 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.
    723
    824## [6.0.3] - 2026-03-27
  • wc-leanpay/trunk/README.md

    r3492436 r3494822  
    44**Tags:** woocommerce, payment, payment-gateway, installment, leanpay
    55**Requires at least:** 5.0 
    6 **Tested up to:** 6.9.1
     6**Tested up to:** 6.9
    77**Requires PHP:** 7.4 
    88**WC requires at least:** 5.0 
    99**WC tested up to:** 10.4.3
    10 **Stable tag:** 6.0.3 
     10**Stable tag:** 6.0.4 
    1111**License:** GPLv2 or later 
    1212**License URI:** https://www.gnu.org/licenses/gpl-2.0.html
     
    2121
    2222* **Easy Installment Payments** - Customers can split their purchases into affordable monthly payments
    23 * **Multiple Market Support** - Available for Slovenia, Croatia, Romania, and Hungary
     23* **Multiple Market Support** - Available for Slovenia and Romania
    2424* **Flexible Display Options** - Show installment information on catalog pages, product pages, and checkout
    2525* **Customizable Design** - Customize colors, sizes, and styling to match your store's branding
     
    8080### Which countries are supported?
    8181
    82 Currently, the plugin supports Slovenia, Croatia, Romania, and Hungary.
     82Currently, the plugin supports Slovenia and Romania.
    8383
    8484### Can I customize the appearance?
     
    125125### Service URLs
    126126
    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.
     127The 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`.
    128128
    129129### Service provider and legal documents
  • wc-leanpay/trunk/assets/js/admin.js

    r3492394 r3494822  
    11jQuery(document).ready(function($) {
    2     var market_endpoint = jQuery('#woocommerce_wc_leanpay_module_market_endpoint');
    32    var success_url = jQuery('#woocommerce_wc_leanpay_module_success_url_checkbox');
    43    var failure_url = jQuery('#woocommerce_wc_leanpay_module_failure_url_checkbox');
     
    5453        }
    5554    });
    56     market_endpoint.on('change load', function() {
    57         toggle_double_price();
    58     });
    59     toggle_double_price();
    60 
    6155    jQuery('ul.subsubsub li').click(function(e) {
    6256        jQuery(this).addClass('current');
    6357    });
    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    }
    7258
    7359  jQuery('#woocommerce_wc_leanpay_module_API_vendor_url').on("click", function(e) {
  • wc-leanpay/trunk/assets/js/leanpay.js

    r3492436 r3494822  
    161161    });
    162162   
    163     // Show/hide zero interest message based on price <= 300 AND instalments = 3
     163    // Show/hide zero interest message based on market-specific threshold and instalments = 3
    164164    const productPrice = parseFloat(jQuery("#leanpay_inst_slider").data("product-price")) || 0;
    165165    const activeInstalments = parseInt($active.text()) || 0;
    166166    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) {
    169172        $zeroInterest.removeClass("hidden").addClass("visible");
    170173    } 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 });
     1jQuery( 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  
    11== 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.
    29
    310= 6.0.3 - 2026-03-27 =
  • wc-leanpay/trunk/includes/leanpay_admin_settings.php

    r3492436 r3494822  
    327327            'class' => 'wc-enhanced-select',
    328328            'description' => __('Select the market endpoint for the payment method', 'wc-leanpay') ,
    329             'default' => 'Slovenia',
     329            'default' => 'si',
    330330            'options' => array(
    331331                'si' => 'Slovenia',
    332                 'hr' => 'Croatia',
    333332                'ro' => 'Romania',
    334                 'hu' => 'Hungary',
    335333            )
    336334        ) ,
    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         ),
    345335        'test_ips' => array(
    346336            '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  
    2727    global $product;
    2828    $settings = new Leanpay_Gateway();
     29    $price_threshold = leanpay_get_price_threshold( $settings->market_endpoint );
    2930    $price = wc_get_price_including_tax($product);
    3031
     
    7273       
    7374        // 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);
    7576       
    7677        // For prices <= threshold: show fewest installments (last element - most expensive per month)
     
    8283        $installment_amount = $selected_installment['installmentAmout'];
    8384        $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         }
    9185 
    9286
     
    120114{
    121115    $settings = new Leanpay_Gateway();
     116    $price_threshold = leanpay_get_price_threshold( $settings->market_endpoint );
    122117
    123118    if ((!is_product() && $variation_price == '') || ($settings->API_id == "") || ($settings->on_product_pages == 'no')) return;
     
    160155
    161156        // 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);
    163158       
    164159        $html .= '<div class="leanpay-product-price-wrapp">';
     
    199194    $show_price = wc_price( $selected_installment['installmentAmout'] );
    200195    $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     }
    208196
    209197        // Banner-style button
     
    229217        {
    230218            $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'] );
    240220        }
    241221
     
    297277   
    298278
    299     if ($tag == "leanpay_product_page")
    300     {
     279    if ($tag === 'leanpay_product_page' || $tag === 'variation') {
    301280        return wp_kses_post($html);
    302281    }
    303     else
    304     {
    305         echo wp_kses_post($html);
    306     }
     282
     283    echo wp_kses_post($html);
    307284}
    308285
     
    315292    }
    316293    $market_endpoint = $settings->market_endpoint;
     294    $price_threshold = leanpay_get_price_threshold( $market_endpoint );
    317295    $price = WC()->cart->total;
    318296   
    319297    // 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);
    321299
    322300    if ($price < $settings->min_order_total || $price > $settings->max_order_total || ($settings->on_checkout_page == 'no')) return '';
     
    380358        $show_price = wc_price( $selected_installment['installmentAmout'] );
    381359        $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         }
    389360
    390361        // Banner-style button
     
    410381        {
    411382            $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'] );
    421384        }
    422385
  • wc-leanpay/trunk/includes/leanpay_get_update_data.php

    r3492436 r3494822  
    175175
    176176    $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' ) )
    178178        $environment = 'test-app';
    179179    elseif( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'si' ) )
  • wc-leanpay/trunk/includes/leanpay_globals.php

    r3492436 r3494822  
    99 */
    1010define('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.
     11define('LEANPAY_VERSION', '6.0.4'); // WRCS: DEFINED_VERSION. Must match Plugin Version in main file header.
    1212define('LEANPAY_MIN_PHP_VER', '1.0.0');
    1313define('LEANPAY_MIN_WC_VER', '5.9');
     
    2424define('LEANPAY_PRICE_THRESHOLD', 300);
    2525
     26/**
     27 * Return market-specific threshold for 0% interest messaging.
     28 *
     29 * @param string $market_endpoint Leanpay market endpoint.
     30 * @return int
     31 */
     32function leanpay_get_price_threshold( $market_endpoint ) {
     33    return ( $market_endpoint === 'ro' ) ? 0 : LEANPAY_PRICE_THRESHOLD;
     34}
     35
    2636?>
  • wc-leanpay/trunk/includes/leanpay_payment_confirmation.php

    r3492436 r3494822  
    2626$leanpay_environment = "app";
    2727
    28 if( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( ( $leanpay_settings->market_endpoint == 'ro' ) || ( $leanpay_settings->market_endpoint == 'hu' ) ) )
     28if( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( $leanpay_settings->market_endpoint == 'ro' ) )
    2929    $leanpay_environment = 'test-app';
    3030elseif( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( $leanpay_settings->market_endpoint == 'si' ) )
  • wc-leanpay/trunk/readme.txt

    r3492436 r3494822  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 6.0.3
     7Stable tag: 6.0.4
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1919* Installment payment option on checkout
    2020* Installment display on catalog and product pages
    21 * Support for Slovenia, Croatia, Romania, and Hungary
     21* Support for Slovenia and Romania
    2222* Sandbox mode for testing
    2323* WooCommerce Blocks compatibility
     
    5050= Which markets are supported? =
    5151
    52 Slovenia, Croatia, Romania, and Hungary.
     52Slovenia and Romania.
    5353
    5454== External services ==
     
    7575
    7676The 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`.
    7878
    7979= Service provider terms and privacy =
     
    9393== Changelog ==
    9494
    95 = 6.0.3 =
     95= 6.0.4 =
    9696
    9797See `changelog.txt` for full release history.
     
    9999== Upgrade Notice ==
    100100
    101 = 6.0.3 =
     101= 6.0.4 =
    102102
    103 Maintenance and compatibility updates for WordPress.org requirements.
     103Market-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  
    77 * Author: Leanpay
    88 * Author URI: https://leanpay.com
    9  * Version: 6.0.3
     9 * Version: 6.0.4
    1010 * Text Domain: wc-leanpay
    1111 * Domain Path: /languages
    1212 * WC tested up to: 10.4.3
    13  * WordPress tested up to: 6.9.1
     13 * WordPress tested up to: 6.9
    1414 * License: GPL-2.0+
    1515 * Requires Plugins: woocommerce
     
    400400        public $check_limit_url;
    401401        public $sandbox_mode;
    402         public $double_price;
    403402        public $test_ips;
    404403        public $completed_status;
     
    462461            $this->info_page_url = $this->get_option("info_page_url");
    463462            $this->market_endpoint = $this->get_option("market_endpoint");
    464             $this->double_price    = $this->get_option("double_price");
    465463            $this->test_ips        = $this->get_option("test_ips");
    466464
     
    530528            add_action("admin_enqueue_scripts", [$this, "admin_scripts"]);
    531529
    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        }
    556546
    557547        function init_form_fields()
     
    694684                plugin_dir_url(__FILE__) . "assets/js/leanpay.js",
    695685                [],
    696                 "1.0.0",
     686                LEANPAY_VERSION,
    697687                true
    698688            );
     689            wp_localize_script( "leanpay_script", "leanpay_price_params", $this->leanpay_get_wc_price_params() );
    699690           
    700691            wp_register_script(
    701692                "leanpay_variations_js",
    702693                plugin_dir_url(__FILE__) . "assets/js/variations.js",
    703                 [],
    704                 "1.0.0",
     694                array( 'jquery', 'wc-add-to-cart-variation' ),
     695                LEANPAY_VERSION,
    705696                true
    706697            );
    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' );
    711709        }
    712710
     
    894892            if ($this->market_endpoint == 'ro')
    895893                $amount = 250;
    896             elseif ($this->market_endpoint == 'hu')
    897                 $amount = 25000;
    898894            else
    899895                $amount = 50;
     
    915911            if ($this->market_endpoint == 'ro')
    916912                $amount = 25000;
    917             elseif ($this->market_endpoint == 'hu')
    918                 $amount = 2000000;
    919913            else
    920914                $amount = 5000;
     
    937931        public function validate_market_endpoint_field($key, $value)
    938932        {
     933            if ( ! in_array( $value, array( 'si', 'ro' ), true ) ) {
     934                return 'si';
     935            }
    939936            // legacy code, to be removed
    940937/*
     
    946943            if ($value == "si") {
    947944                $slug = "leanpay_info_page";
    948                 leanpay_generate_info_page($slug, $remove_old);
    949             }
    950             elseif ($value == "hr") {
    951                 $slug = "leanpay_info_page_hr";
    952945                leanpay_generate_info_page($slug, $remove_old);
    953946            }
     
    12181211    $environment = "app";
    12191212
    1220     if( ( $settings->sandbox_mode == 'yes' ) && ( ( $settings->market_endpoint == 'ro' ) || ( $settings->market_endpoint == 'hu' ) ) )
     1213    if( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'ro' ) )
    12211214        $environment = 'test-app';
    12221215    elseif( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'si' ) )
     
    12541247    $environment = "app";
    12551248
    1256     if( ( $settings->sandbox_mode == 'yes' ) && ( ( $settings->market_endpoint == 'ro' ) || ( $settings->market_endpoint == 'hu' ) ) )
     1249    if( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'ro' ) )
    12571250        $environment = 'test-app';
    12581251    elseif( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'si' ) )
     
    12771270function leanpay_get_variation()
    12781271{
    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
    12851276    require_once plugin_dir_path(__FILE__) ."/includes/leanpay_frontend_display.php";
    12861277    $price = isset($_POST["price"]) ? sanitize_text_field(wp_unslash($_POST["price"])) : '';
     
    12921283    $price = floatval($price);
    12931284
    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();
    12961304}
    12971305
Note: See TracChangeset for help on using the changeset viewer.