Plugin Directory

Changeset 3492436


Ignore:
Timestamp:
03/27/2026 08:22:34 AM (6 days ago)
Author:
leanpay
Message:

Release 6.0.3

Location:
wc-leanpay/trunk
Files:
2 added
4 deleted
17 edited

Legend:

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

    r3492394 r3492436  
    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.3] - 2026-03-27
     9
     10### Changed
     11- WordPress.org release version.
     12- Updated readme/changelog packaging and release metadata for WordPress.org distribution.
    713
    814## [6.0.2] - 2026-02-03
  • wc-leanpay/trunk/README.md

    r3492394 r3492436  
    44**Tags:** woocommerce, payment, payment-gateway, installment, leanpay
    55**Requires at least:** 5.0 
    6 **Tested up to:** 6.9 
     6**Tested up to:** 6.9.1
    77**Requires PHP:** 7.4 
    88**WC requires at least:** 5.0 
    9 **WC tested up to:** 10.4.
    10 **Stable tag:** 6.0.0 
     9**WC tested up to:** 10.4.3
     10**Stable tag:** 6.0.3 
    1111**License:** GPLv2 or later 
    1212**License URI:** https://www.gnu.org/licenses/gpl-2.0.html
     
    103103* Documentation: Contact Leanpay support
    104104
     105## External services
     106
     107This plugin relies on the **Leanpay** payment gateway service to process installment payments. Leanpay is a third-party external service. When you use this plugin, your store and your customers' data are sent to Leanpay's servers under the conditions described below.
     108
     109### What the service is and what it is used for
     110
     111Leanpay is a payment service that enables customers to pay for purchases in monthly installments. This plugin connects to the Leanpay API to:
     112- Retrieve available installment plan pricing
     113- Create payment tokens when customers choose Leanpay at checkout
     114- Redirect customers to the Leanpay hosted checkout page to complete payment
     115- Confirm order delivery and request verification documents
     116
     117### What data is sent and when
     118
     119- **Installment plans update** — When the store admin updates installment plans (scheduled or manual), the plugin sends the merchant API key to Leanpay to fetch current pricing. Endpoint: `/vendor/installment-plans`.
     120- **Payment token** — When a customer selects Leanpay at checkout, the plugin sends order details (order ID, amount, redirect URLs) and billing information (name, phone, address, postal code, city) to obtain a payment token. Endpoint: `/vendor/token`.
     121- **Checkout** — The customer's browser is redirected to Leanpay's hosted checkout page to complete the payment.
     122- **Delivery confirmation** — When the admin confirms delivery, the plugin sends the merchant API key and transaction ID to Leanpay. Endpoint: `/transaction/delivery`.
     123- **Verification** — The plugin may request customer verification status using the merchant API key and transaction ID. Endpoint: `/api/verification-document/get`.
     124
     125### Service URLs
     126
     127The 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.
     128
     129### Service provider and legal documents
     130
     131This service is provided by **Leanpay d.o.o.** (Slovenia).
     132
     133- Website: [https://www.leanpay.si](https://www.leanpay.si)
     134- **Terms of use:** [https://nbg1.your-objectstorage.com/leanpay/documents/Terms_and_conditions_08.07.2025.pdf?AWSAccessKeyId=YD5H3O5Y2IQQT0ZF0R8G&Signature=A8pHaBTlkuspM17fpHqzDt7TAM8%3D&Expires=1775662940](https://nbg1.your-objectstorage.com/leanpay/documents/Terms_and_conditions_08.07.2025.pdf?AWSAccessKeyId=YD5H3O5Y2IQQT0ZF0R8G&Signature=A8pHaBTlkuspM17fpHqzDt7TAM8%3D&Expires=1775662940)
     135- **Privacy policy:** [https://nbg1.your-objectstorage.com/leanpay/documents/Privacy_policy_20260209.pdf?AWSAccessKeyId=YD5H3O5Y2IQQT0ZF0R8G&Signature=tqxSlHJZNJVPFAG3XXBmrcaNRjg%3D&Expires=1775662940](https://nbg1.your-objectstorage.com/leanpay/documents/Privacy_policy_20260209.pdf?AWSAccessKeyId=YD5H3O5Y2IQQT0ZF0R8G&Signature=tqxSlHJZNJVPFAG3XXBmrcaNRjg%3D&Expires=1775662940)
     136
    105137## Credits
    106138
  • wc-leanpay/trunk/assets/css/style.css

    r3492394 r3492436  
     1/* Scope: prevent theme/global styles from affecting .lp_bottom content */
     2.lp_bottom *,
     3.lp_bottom *::before,
     4.lp_bottom *::after {
     5    box-sizing: border-box;
     6}
     7.lp_bottom p {
     8    margin: 0 0 1em 0;
     9    padding: 0;
     10    font-size: 16px;
     11    line-height: 130%;
     12    color: #5A5A6D;
     13    font-weight: normal;
     14}
     15.lp_bottom p:last-child {
     16    margin-bottom: 0;
     17}
     18.lp_bottom div {
     19    margin: 0;
     20    padding: 0;
     21}
     22.lp_bottom a {
     23    color: inherit;
     24    text-decoration: none;
     25    font-size: inherit;
     26    line-height: inherit;
     27    font-weight: inherit;
     28}
     29.lp_bottom img {
     30    max-width: 100%;
     31    height: auto;
     32    vertical-align: middle;
     33    border: 0;
     34}
     35.lp_bottom span {
     36    margin: 0;
     37    padding: 0;
     38}
     39.lp_bottom ul,
     40.lp_bottom ol {
     41    margin: 0;
     42    padding: 0;
     43    list-style: none;
     44}
     45.lp_bottom h1,
     46.lp_bottom h2,
     47.lp_bottom h3,
     48.lp_bottom h4,
     49.lp_bottom h5,
     50.lp_bottom h6 {
     51    margin: 0 0 0.5em 0;
     52    padding: 0;
     53    font-size: inherit;
     54    line-height: 130%;
     55    font-weight: normal;
     56    color: #5A5A6D;
     57}
     58
     59
    160#leanpayObrocneCeneAdmin .page-title {
    261    background-size: auto;
     
    87146    line-height:130%;
    88147    gap: 16px;
     148    font-family: 'Raleway', 'Roboto', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
    89149}
    90150
     
    245305    display:none;
    246306    user-select: none;
    247 }
     307    font-family: 'Raleway', 'Roboto', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
     308}
     309
    248310
    249311@media (max-width: 768px) {
     
    693755}
    694756
    695 .leanpay_inst_slider_item {
     757.lp_bottom .leanpay_inst_slider_item {
    696758    background: #fff;
    697759    color: #000;
     
    703765}
    704766
    705 .leanpay_inst_slider_item::after {
     767.lp_bottom .leanpay_inst_slider_item::after {
    706768    content: '';
    707769    position: absolute;
  • wc-leanpay/trunk/assets/js/admin_meta_box.js

    r3492394 r3492436  
    44    transaction_btn.on('click', function(){
    55        $.ajax({
    6             url: myAjax.ajaxurl,
     6            url: leanpayAjax.ajaxurl,
    77            dataType: 'json',
    88            method:'POST',
     
    3131    transaction_btn.on('click', function(){
    3232        $.ajax({
    33             url: myAjax.ajaxurl,
     33            url: leanpayAjax.ajaxurl,
    3434            dataType: 'json',
    3535            method:'POST',
  • wc-leanpay/trunk/assets/js/checkout.js

    r3492394 r3492436  
    99    useEffect(() => {
    1010        jQuery.get(
    11             '/wp-admin/admin-ajax.php?action=get_leanpay_calculator',
     11            leanpayBlocksData.ajaxUrl + '?action=get_leanpay_calculator',
    1212            function (data) {
    1313                setDescription(data);
  • wc-leanpay/trunk/assets/js/leanpay.js

    r3492394 r3492436  
    8888
    8989        const pageX = e.pageX || e.originalEvent.touches[0].pageX;
    90         const containerLeft = $("#leanpay_inst_slider").offset().left;
    91         const x = pageX - containerLeft;
     90        const $container = $("#leanpay_inst_slider");
     91        const containerLeft = $container.offset().left;
     92        const containerWidth = $container.outerWidth();
     93        let x = pageX - containerLeft;
     94
     95        // Clamp to track: min 15px (path start), max 100% (containerWidth - 15)
     96        const minX = 15;
     97        const maxX = Math.max(minX, containerWidth - 15);
     98        x = Math.max(minX, Math.min(x, maxX));
    9299
    93100        jQuery("#leanpay_bullet").css("left", x + "px");
     
    214221
    215222function leanpay_wc_price(amount) {
    216     amount = Number(amount).toFixed(parseInt(wc_price_params.decimals));
     223    amount = Number(amount).toFixed(parseInt(leanpay_price_params.decimals));
    217224
    218225    let parts = amount.split('.');
    219     parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, wc_price_params.thousand_separator);
    220 
    221     let formatted = parts.join(wc_price_params.decimal_separator);
    222 
    223     switch (wc_price_params.currency_pos) {
     226    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, leanpay_price_params.thousand_separator);
     227
     228    let formatted = parts.join(leanpay_price_params.decimal_separator);
     229
     230    switch (leanpay_price_params.currency_pos) {
    224231        case 'left':
    225             return wc_price_params.currency_symbol + formatted;
     232            return leanpay_price_params.currency_symbol + formatted;
    226233        case 'right':
    227             return formatted + wc_price_params.currency_symbol;
     234            return formatted + leanpay_price_params.currency_symbol;
    228235        case 'left_space':
    229             return wc_price_params.currency_symbol + ' ' + formatted;
     236            return leanpay_price_params.currency_symbol + ' ' + formatted;
    230237        case 'right_space':
    231             return formatted + ' ' + wc_price_params.currency_symbol;
     238            return formatted + ' ' + leanpay_price_params.currency_symbol;
    232239    }
    233240}
  • wc-leanpay/trunk/assets/js/variations.js

    r3492394 r3492436  
    66            jQuery.ajax({
    77                type: "POST",
    8                 url: myAjax.ajaxurl,
     8                url: leanpayAjax.ajaxurl,
    99                data: '&price='+price+'&action=get_leanpay_variation',
    1010                success: function(data) {
     
    2828            jQuery.ajax({
    2929                type: "POST",
    30                 url: myAjax.ajaxurl,
     30                url: leanpayAjax.ajaxurl,
    3131                data: '&price='+price+'&action=get_leanpay_variation',
    3232                success: function(data) {
  • wc-leanpay/trunk/blocks/horizontal/block.json

    r3492394 r3492436  
    11{
    2     "apiVersion": 2,
     2    "apiVersion": 3,
    33    "name": "wc-leanpay/horizontal-widget",
    44    "title": "LeanPay Horizontal Widget",
  • wc-leanpay/trunk/blocks/vertical/block.json

    r3492394 r3492436  
    11{
    2     "apiVersion": 2,
     2    "apiVersion": 3,
    33    "name": "wc-leanpay/vertical-widget",
    44    "title": "LeanPay Vertical Widget",
  • wc-leanpay/trunk/includes/leanpay_admin_settings.php

    r3492394 r3492436  
    66require_once plugin_dir_path(__FILE__) . '/leanpay_get_update_data.php';
    77
    8 $current_panel = isset($_REQUEST['panel'])
    9     ? sanitize_text_field(wp_unslash($_REQUEST['panel']))
    10     : '';
    11 $market_endpoint = isset($_REQUEST['lng'])
    12     ? sanitize_text_field(wp_unslash($_REQUEST['lng']))
    13     : '';
    14 $statuses = wc_get_order_statuses();
     8// Only use panel/lng from request when nonce is valid (links add this nonce).
     9$leanpay_current_panel = '';
     10$leanpay_market_endpoint = '';
     11if ( ( isset( $_REQUEST['panel'] ) || isset( $_REQUEST['lng'] ) ) && isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'leanpay_settings_panel' ) ) {
     12    $leanpay_current_panel  = isset( $_REQUEST['panel'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['panel'] ) ) : '';
     13    $leanpay_market_endpoint = isset( $_REQUEST['lng'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lng'] ) ) : '';
     14}
     15$leanpay_statuses = wc_get_order_statuses();
    1516
    1617leanpay_install_table_if_not_exists();
    1718
    18 $temp_financial_product = $default_financial_product ="";
    19 $financial_products_arr = array();
    20 $financial_products = get_financial_product($market_endpoint);
    21 if (!empty($financial_products)) $financial_products = explode('#', $financial_products);
    22 
    23 if (is_array($financial_products))
    24 {
    25     foreach ($financial_products as $financial_product)
     19$leanpay_temp_financial_product = $leanpay_default_financial_product ="";
     20$leanpay_financial_products_arr = array();
     21$leanpay_financial_products = leanpay_get_financial_product($leanpay_market_endpoint);
     22if (!empty($leanpay_financial_products)) $leanpay_financial_products = explode('#', $leanpay_financial_products);
     23
     24if (is_array($leanpay_financial_products))
     25{
     26    foreach ($leanpay_financial_products as $leanpay_financial_product)
    2627    {
    27         if ($financial_product != "")
     28        if ($leanpay_financial_product != "")
    2829        {
    29             $financial_products_arr[$financial_product] = $financial_product;
    30 //            $financial_products_arr[] = array( $financial_product => $financial_product );
     30            $leanpay_financial_products_arr[$leanpay_financial_product] = $leanpay_financial_product;
     31//            $leanpay_financial_products_arr[] = array( $leanpay_financial_product => $leanpay_financial_product );
    3132        }
    3233    }
    3334}
    3435
    35 if( isset($financial_products_arr[0]))
    36 {
    37     $default_financial_product = implode(" ",$financial_products_arr[0]);
     36if( isset($leanpay_financial_products_arr[0]))
     37{
     38    $leanpay_default_financial_product = implode(" ",$leanpay_financial_products_arr[0]);
    3839}
    3940else
    4041{
    41     $default_financial_product = __('Please enter API Key', 'wc-leanpay');
     42    $leanpay_default_financial_product = __('Please enter API Key', 'wc-leanpay');
    4243}
    4344
     
    6263// }
    6364
    64 $site_url = get_site_url().'/wp-content/plugins/wc-leanpay/status.php';
    65 
    66 $pages_url = array();
     65$leanpay_site_url = rest_url('wc-leanpay/v1/status');
     66
     67$leanpay_pages_url = array();
    6768$pages = get_pages();
    6869
    6970foreach($pages as $page)
    70     $pages_url[$page->ID] = $page->post_name;
    71 
    72 if ( $current_panel == 'payment-configuration' )
    73 {
    74     $leanpay_settings = apply_filters('wc_leanpay_settings', array(
     71    $leanpay_pages_url[$page->ID] = $page->post_name;
     72
     73if ( $leanpay_current_panel == 'payment-configuration' )
     74{
     75    $leanpay_settings = apply_filters('leanpay_wc_settings', array(
    7576        'title' => array(
    7677            'title' => __('Payment title', 'wc-leanpay') ,
     
    9293            'description' => __('Status shown when the order is succesful', 'wc-leanpay') ,
    9394            'default' => 'wc-processing',
    94             'options' => $statuses
     95            'options' => $leanpay_statuses
    9596        ) ,
    9697        'failed_status' => array(
     
    100101            'description' => __('Status shown when the order fails', 'wc-leanpay') ,
    101102            'default' => 'wc-failed',
    102             'options' => $statuses
     103            'options' => $leanpay_statuses
    103104        ) ,
    104105        'min_order_total' => array(
     
    116117    ));
    117118}
    118 else if ( $current_panel == 'settings' )
    119 {
    120     $leanpay_settings = apply_filters('wc_leanpay_settings', array(
     119else if ( $leanpay_current_panel == 'settings' )
     120{
     121    $leanpay_settings = apply_filters('leanpay_wc_settings', array(
    121122        'financial_product' => array(
    122123            'title' => __('Financial product', 'wc-leanpay') ,
     
    124125            'description' => __('Select the product available in the webshop', 'wc-leanpay') ,
    125126            'desc_tip' => __('Select the product available in the webshop', 'wc-leanpay') ,
    126             'default' => $default_financial_product,
    127             'options' => ( !empty($financial_products_arr) ) ? $financial_products_arr : $default_financial_product
     127            'default' => $leanpay_default_financial_product,
     128            'options' => ( !empty($leanpay_financial_products_arr) ) ? $leanpay_financial_products_arr : $leanpay_default_financial_product
    128129        ) ,
    129130        'update_schedule' => array(
     
    259260    ));
    260261}
    261 else if ( $current_panel == 'advanced' )
    262 {
    263     $leanpay_settings = apply_filters('wc_leanpay_settings', array(
    264         'custom_css' => array(
    265             'title' => __('Custom CSS', 'wc-leanpay') ,
    266             'type' => 'textarea',
    267             'description' => __('Enter custom CSS code that will be added to the front-end. This CSS will override default styles.', 'wc-leanpay') ,
    268             'desc_tip' => __('Add custom CSS to style Leanpay elements on your site. No <style> tags needed.', 'wc-leanpay') ,
    269             'default' => '',
    270             'css' => 'min-height:300px; font-family: monospace;',
    271         ) ,
    272     ));
    273 }
    274262else
    275263{
    276     $leanpay_settings = apply_filters('wc_leanpay_settings', array(
     264    $leanpay_settings = apply_filters('leanpay_wc_settings', array(
    277265        'enabled' => array(
    278266            'title' => __('Payment method', 'wc-leanpay') ,
     
    315303            'default' => '',
    316304        ),
    317         'API_vendor_url' => array(
     305        'API_vendor_url' => array(
    318306            'title' => __('API Vendor URL', 'wc-leanpay') ,
    319307            'type' => 'text',
    320             'default' => $site_url,
     308            'default' => $leanpay_site_url,
    321309            'custom_attributes' => array('readonly' => 'readonly'),
    322310            'desc_tip' => __('The displayed API URL is used to send order statuses. To successfully receive order statuses, copy the entire link and enter it in your Leanpay application under the Company -> API URL tab', 'wc-leanpay'),
    323311        ),
    324         'info_page_url' => array(
     312        'info_page_url' => array(
    325313            'title' => __('Info Page URL', 'wc-leanpay') ,
    326314            'type' => 'text',
    327315            'default' => '',
    328316            'desc_tip' => __('You can set your own info page URL for more information about Leanpay.', 'wc-leanpay'),
     317        ),
     318        'check_limit_url' => array(
     319            'title' => __('Pre-qualify URL', 'wc-leanpay') ,
     320            'type'  => 'text',
     321            'default' => '',
     322            'desc_tip' => __('Optional: custom URL for the \"Check your limit\" button. If left empty, a default Leanpay pre-qualify URL is used based on the selected market and sandbox mode.', 'wc-leanpay'),
    329323        ),
    330324        'market_endpoint' => array(
     
    368362}
    369363
    370 return apply_filters('wc_leanpay_settings', $leanpay_settings);
     364return apply_filters('leanpay_wc_settings', $leanpay_settings);
  • wc-leanpay/trunk/includes/leanpay_frontend_display.php

    r3492394 r3492436  
    1212require_once plugin_dir_path(__FILE__) . '/leanpay_get_update_data.php';
    1313
    14 function lp_round( $price, $market_endpoint = '' )
     14function leanpay_round( $price, $market_endpoint = '' )
    1515{
    1616    if( $market_endpoint == "ro" )
     
    2323 * Show Leanpay lowest Installment plan per month on archive page - TO DO (Hrvaška, currency, napisi)
    2424*/
    25 function show_leanpay_on_archive_page()
     25function leanpay_show_on_archive_page()
    2626{
    2727    global $product;
    28     $settings = new WC_Leanpay();
     28    $settings = new Leanpay_Gateway();
    2929    $price = wc_get_price_including_tax($product);
    3030
     
    4040    $currcode = get_woocommerce_currency_symbol();
    4141
    42     $raw = get_leanpay_prices();
     42    $raw = leanpay_get_leanpay_prices();
    4343
    4444    $leanpay_prices = is_string($raw)
     
    5555    foreach ($leanpay_prices['loanAmounts'] as $leanpay_price)
    5656    {
    57         if ($leanpay_price['loanAmount'] == lp_round($price, $settings->market_endpoint))
     57        if ($leanpay_price['loanAmount'] == leanpay_round($price, $settings->market_endpoint))
    5858        {
    5959            foreach ($leanpay_price['possibleInstallments'] as $installment)
     
    7272       
    7373        // Check if price is below threshold for 0% interest display
    74         $is_interest_free = ($price <= WC_LEANPAY_PRICE_THRESHOLD);
     74        $is_interest_free = ($price <= LEANPAY_PRICE_THRESHOLD);
    7575       
    7676        // For prices <= threshold: show fewest installments (last element - most expensive per month)
     
    112112}
    113113
    114 add_shortcode('leanpay_catalog', 'show_leanpay_on_archive_page');
     114add_shortcode('leanpay_catalog', 'leanpay_show_on_archive_page');
    115115
    116116/*
    117117 * Show Leanpay Calculation / Installment plan options on product page - TO DO (Hrvaška, currency, napisi)
    118118*/
    119 function show_leanpay_on_product_page($atts = array() , $content = null, $tag = null, $variation_price = '')
     119function leanpay_show_on_product_page($atts = array() , $content = null, $tag = null, $variation_price = '')
    120120{
    121     $settings = new WC_Leanpay();
     121    $settings = new Leanpay_Gateway();
    122122
    123123    if ((!is_product() && $variation_price == '') || ($settings->API_id == "") || ($settings->on_product_pages == 'no')) return;
     
    144144    $currcode = get_woocommerce_currency_symbol();
    145145
    146     $raw = get_leanpay_prices();
     146    $raw = leanpay_get_leanpay_prices();
    147147
    148148    $leanpay_prices = is_string($raw)
     
    160160
    161161        // Check if price is below threshold for 0% interest display
    162         $is_interest_free = ($price <= WC_LEANPAY_PRICE_THRESHOLD);
     162        $is_interest_free = ($price <= LEANPAY_PRICE_THRESHOLD);
    163163       
    164164        $html .= '<div class="leanpay-product-price-wrapp">';
     
    169169        foreach ($leanpay_prices['loanAmounts'] as $leanpay_price)
    170170        {
    171             if ($leanpay_price['loanAmount'] == lp_round($price, $settings->market_endpoint))
     171            if ($leanpay_price['loanAmount'] == leanpay_round($price, $settings->market_endpoint))
    172172            {
    173173                foreach ($leanpay_price['possibleInstallments'] as $installment)
     
    299299    if ($tag == "leanpay_product_page")
    300300    {
    301         return $html;
    302     }
    303 
     301        return wp_kses_post($html);
     302    }
    304303    else
    305304    {
    306         // $html is already built with escaped content, but we should use wp_kses_post for safety
    307305        echo wp_kses_post($html);
    308306    }
     
    310308
    311309
    312 function show_leanpay_on_checkout()
     310function leanpay_show_on_checkout()
    313311{
    314312    $settings = WC()->payment_gateways()->payment_gateways()['wc_leanpay_module'] ?? null;
     
    320318   
    321319    // Check if price is below threshold for 0% interest display
    322     $is_interest_free = ($price <= WC_LEANPAY_PRICE_THRESHOLD);
     320    $is_interest_free = ($price <= LEANPAY_PRICE_THRESHOLD);
    323321
    324322    if ($price < $settings->min_order_total || $price > $settings->max_order_total || ($settings->on_checkout_page == 'no')) return '';
     
    333331    $currcode = get_woocommerce_currency_symbol();
    334332
    335     $raw = get_leanpay_prices();
     333    $raw = leanpay_get_leanpay_prices();
    336334
    337335    $leanpay_prices = is_string($raw)
     
    352350        foreach ($leanpay_prices['loanAmounts'] as $leanpay_price)
    353351        {
    354             if ($leanpay_price['loanAmount'] == lp_round($price, $settings->market_endpoint))
     352            if ($leanpay_price['loanAmount'] == leanpay_round($price, $settings->market_endpoint))
    355353            {
    356354                foreach ($leanpay_price['possibleInstallments'] as $installment)
     
    484482 * Format installment price - TO DO : preveri če je sploh potrebno
    485483*/
    486 function moneyFormat($cena)
     484function leanpay_money_format($cena)
    487485{
    488486    $cena = round($cena, 2);
  • wc-leanpay/trunk/includes/leanpay_get_update_data.php

    r3492394 r3492436  
    55}
    66
     7/**
     8 * Return the Leanpay prices table name if it contains only safe characters.
     9 *
     10 * @return string|null Table name or null if invalid.
     11 */
     12function leanpay_get_prices_table() {
     13    global $wpdb;
     14    $table = $wpdb->prefix . 'leanpay_cene_tmp_2022';
     15    if ( ! preg_match( '/^[a-zA-Z0-9_]+$/', $table ) ) {
     16        return null;
     17    }
     18    return $table;
     19}
     20
    721
    822
     
    1529    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    1630
    17     $table_name = $wpdb->prefix . 'leanpay_cene_tmp_2022';
    18     $table_name = esc_sql($table_name);
     31    $table_name = leanpay_get_prices_table();
     32    if ( $table_name === null ) {
     33        return;
     34    }
    1935    $charset_collate = $wpdb->get_charset_collate();
    2036
     
    3450 * Update Instalment plan
    3551*/
    36 function update_installment_plans()
    37 {
    38     $settings = new WC_Leanpay();
    39     $calculationsArray = call_leanpay($settings->market_endpoint);
     52function leanpay_update_installment_plans()
     53{
     54    $settings = new Leanpay_Gateway();
     55    $calculationsArray = leanpay_call_leanpay($settings->market_endpoint);
    4056
    4157    $financial_product = '';
    4258    if (is_array($calculationsArray) && count($calculationsArray) > 0)
    4359    {
    44         delete_old_price_groups($settings->market_endpoint);
     60        leanpay_delete_old_price_groups($settings->market_endpoint);
    4561        foreach ($calculationsArray['groups'] as $produkt)
    4662        {
     
    4864            {
    4965                $financial_product .= $produkt['groupName'] . "#";
    50                 update_financial_product_prices($produkt['groupName'], $produkt, $settings->market_endpoint);
    51             }
    52         }
    53         save_financial_product($financial_product, $settings->market_endpoint);
     66                leanpay_update_financial_product_prices($produkt['groupName'], $produkt, $settings->market_endpoint);
     67            }
     68        }
     69        leanpay_save_financial_product($financial_product, $settings->market_endpoint);
    5470
    5571        $lp = get_option( 'woocommerce_wc_leanpay_module_settings' );
     
    6278        {
    6379            global $wpdb;
    64             $table = $wpdb->prefix . 'leanpay_cene_tmp_2022';
    65             $table = esc_sql($table);
     80            $table = leanpay_get_prices_table();
     81            if ( $table === null ) {
     82                return;
     83            }
     84            // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Custom table; name from leanpay_get_prices_table() (validated [a-zA-Z0-9_]+); no identifier placeholder in prepare().
    6685            $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM `{$table}` WHERE title = 'groups' AND lng = %s", $settings->market_endpoint), ARRAY_A );
    6786
     
    82101 * Delete old price groups from database for language, passed as parameter
    83102*/
    84 function delete_old_price_groups($lng)
    85 {
    86     global $wpdb;
    87     $table = $wpdb->prefix . 'leanpay_cene_tmp_2022';
    88     $table = esc_sql($table);
     103function leanpay_delete_old_price_groups($lng)
     104{
     105    global $wpdb;
     106    $table = leanpay_get_prices_table();
     107    if ( $table === null ) {
     108        return;
     109    }
    89110    $lng = sanitize_text_field($lng);
     111    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Custom table; name from leanpay_get_prices_table() (validated [a-zA-Z0-9_]+); no identifier placeholder in prepare().
    90112    $wpdb->query($wpdb->prepare("DELETE FROM `{$table}` WHERE lng = %s", $lng));
    91113}
     
    94116 * Update prices based on country
    95117*/
    96 function update_financial_product_prices($title, $prices, $lng)
    97 {
    98     global $wpdb;
    99     $table = $wpdb->prefix . 'leanpay_cene_tmp_2022';
    100     $table = esc_sql($table);
     118function leanpay_update_financial_product_prices($title, $prices, $lng)
     119{
     120    global $wpdb;
     121    $table = leanpay_get_prices_table();
     122    if ( $table === null ) {
     123        return;
     124    }
    101125    $title = sanitize_text_field($title);
    102126    $lng = sanitize_text_field($lng);
     127    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Custom table; name from leanpay_get_prices_table() (validated [a-zA-Z0-9_]+); no identifier placeholder in prepare().
    103128    $wpdb->query($wpdb->prepare("DELETE FROM `{$table}` WHERE title = %s AND lng = %s", trim($title), $lng));
    104129
     
    111136        'timestamp' => gmdate('d.m.Y H:i:s')
    112137    );
     138    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom plugin table; no WP API.
    113139    $wpdb->insert($table, $post_data);
    114140//    echo $wpdb->last_error;
     
    118144 * Save financial product after instalment prices update
    119145*/
    120 function save_financial_product($data, $lng = 'si')
    121 {
    122     global $wpdb;
    123     $table = $wpdb->prefix . 'leanpay_cene_tmp_2022';
     146function leanpay_save_financial_product($data, $lng = 'si')
     147{
     148    global $wpdb;
     149    $table = leanpay_get_prices_table();
     150    if ( $table === null ) {
     151        return;
     152    }
    124153    $lng = sanitize_text_field($lng);
    125154    $data = sanitize_textarea_field($data);
     
    133162        'timestamp' => gmdate('d.m.Y H:i:s')
    134163    );
     164    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom plugin table; no WP API.
    135165    $wpdb->insert($table, $post_data);
    136166//    echo $wpdb->last_error;
     
    140170 * Get prices from Leanpay and return to function
    141171*/
    142 function call_leanpay($lng = 'si')
    143 {
    144     $settings = new WC_Leanpay();
    145     ini_set('memory_limit', '2048M');
    146 
     172function leanpay_call_leanpay($lng = 'si')
     173{
     174    $settings = new Leanpay_Gateway();
    147175
    148176    $environment = "app";
     
    175203
    176204    $response_body = wp_remote_retrieve_body($response);
     205
     206    $original_memory_limit = ini_get('memory_limit');
     207    wp_raise_memory_limit( 'admin' );
    177208    $result = json_decode($response_body, true);
     209    // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- Restore memory limit after wp_raise_memory_limit() for large JSON.
     210    ini_set('memory_limit', $original_memory_limit);
     211
    178212    return $result;
    179213}
     
    182216 * Get all financial products from database (based on language; default language is Slovenian)
    183217*/
    184 function get_financial_product($lng)
    185 {
    186     global $wpdb;
    187     $table = $wpdb->prefix . 'leanpay_cene_tmp_2022';
    188     $table = esc_sql($table);
     218function leanpay_get_financial_product($lng)
     219{
     220    global $wpdb;
     221    $table = leanpay_get_prices_table();
     222    if ( $table === null ) {
     223        return null;
     224    }
    189225    $lng = sanitize_text_field($lng);
     226    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Custom table; name from leanpay_get_prices_table() (validated [a-zA-Z0-9_]+); no identifier placeholder in prepare().
    190227    $result = $wpdb->get_results($wpdb->prepare("SELECT content FROM `{$table}` WHERE title='groups' AND lng = %s ORDER by id DESC LIMIT 1", $lng), ARRAY_A);
    191228    foreach ($result as $instance)
     
    196233 * Get Leanpay installment plans based on selected financial product from database - TO DO (financial product ID)
    197234*/
    198 function get_leanpay_prices()
    199 {
    200     ini_set('memory_limit', '2048M');
    201     global $wpdb;
    202     $settings = new WC_Leanpay();
    203 
    204     $table = $wpdb->prefix . 'leanpay_cene_tmp_2022';
    205     $table = esc_sql($table);
     235function leanpay_get_leanpay_prices()
     236{
     237    global $wpdb;
     238    $settings = new Leanpay_Gateway();
     239
     240    $table = leanpay_get_prices_table();
     241    if ( $table === null ) {
     242        return null;
     243    }
    206244    $financial_product = sanitize_text_field($settings->financial_product);
    207245    $market_endpoint = sanitize_text_field($settings->market_endpoint);
     246    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Custom table; name from leanpay_get_prices_table() (validated [a-zA-Z0-9_]+); no identifier placeholder in prepare().
    208247    $result = $wpdb->get_var($wpdb->prepare("SELECT content FROM `{$table}` WHERE title = %s AND lng = %s LIMIT 1", $financial_product, $market_endpoint));
    209248
     
    214253 * Send delivery confirmation and get verification document
    215254*/
    216 function delivery_verification_confirmation($apiKey, $market_endpoint, $environment, $api_url, $order_id)
     255function leanpay_delivery_verification_confirmation($apiKey, $market_endpoint, $environment, $api_url, $order_id)
    217256{
    218257    $apiKey = sanitize_text_field($apiKey);
     
    277316
    278317
    279 function lp_headersToArray( $str )
     318function leanpay_headers_to_array( $str )
    280319{
    281320    $headers = array();
  • wc-leanpay/trunk/includes/leanpay_globals.php

    r3492394 r3492436  
    88 * Required minimums and constants
    99 */
    10 define('WC_LEANPAY_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__DIR__)));
    11 define('WC_LEANPAY_VERSION', '1.0.0'); // WRCS: DEFINED_VERSION.
    12 define('WC_LEANPAY_MIN_PHP_VER', '1.0.0');
    13 define('WC_LEANPAY_MIN_WC_VER', '5.9');
    14 define('WC_LEANPAY_FUTURE_MIN_WC_VER', '6.0');
    15 define('WC_LEANPAY_MAIN_FILE', __FILE__);
    16 define('WC_LEANPAY_ABSPATH', __DIR__ . '/');
    17 define('WC_LEANPAY_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)) , basename(__FILE__))));
     10define('LEANPAY_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__DIR__)));
     11define('LEANPAY_VERSION', '6.0.3'); // WRCS: DEFINED_VERSION. Must match Plugin Version in main file header.
     12define('LEANPAY_MIN_PHP_VER', '1.0.0');
     13define('LEANPAY_MIN_WC_VER', '5.9');
     14define('LEANPAY_FUTURE_MIN_WC_VER', '6.0');
     15define('LEANPAY_MAIN_FILE', __FILE__);
     16define('LEANPAY_ABSPATH', __DIR__ . '/');
     17define('LEANPAY_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)) , basename(__FILE__))));
    1818
    1919/**
     
    2222 * Products above this price will show regular interest messaging
    2323 */
    24 define('WC_LEANPAY_PRICE_THRESHOLD', 300);
     24define('LEANPAY_PRICE_THRESHOLD', 300);
    2525
    2626?>
  • wc-leanpay/trunk/includes/leanpay_payment_confirmation.php

    r3492394 r3492436  
    11<?php
    2 require_once ('../../../../wp-load.php');
     2if ( ! defined( 'ABSPATH' ) ) {
     3    require_once '../../../../wp-load.php';
     4}
    35
    4 if (!defined('ABSPATH')) {
     6if ( ! defined( 'ABSPATH' ) ) {
    57    exit;
    68}
    7 $settings = new WC_Leanpay();
     9$leanpay_settings = new Leanpay_Gateway();
    810
    911if (!isset($_GET['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['nonce'])), 'order_id_' . (isset($_GET["orderId"]) ? absint($_GET["orderId"]) : 0))) {
     
    1214
    1315
    14 $order_id = isset($_GET["orderId"]) ? absint($_GET["orderId"]) : 0;
    15 if (empty($order_id)) {
     16$leanpay_order_id = isset($_GET["orderId"]) ? absint($_GET["orderId"]) : 0;
     17if (empty($leanpay_order_id)) {
    1618    wp_die(esc_html__('Invalid order ID', 'wc-leanpay'));
    1719}
    18 $order = wc_get_order($order_id);
     20$order = wc_get_order($leanpay_order_id);
    1921if (!$order) {
    2022    wp_die(esc_html__('Order not found', 'wc-leanpay'));
    2123}
    2224
    23 $link_checkout = $link_token = "";
    24 $environment = "app";
     25$leanpay_link_checkout = $leanpay_link_token = "";
     26$leanpay_environment = "app";
    2527
    26 if( ( $settings->sandbox_mode == 'yes' ) && ( ( $settings->market_endpoint == 'ro' ) || ( $settings->market_endpoint == 'hu' ) ) )
    27     $environment = 'test-app';
    28 elseif( ( $settings->sandbox_mode == 'yes' ) && ( $settings->market_endpoint == 'si' ) )
    29     $environment = 'stage-app';
     28if( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( ( $leanpay_settings->market_endpoint == 'ro' ) || ( $leanpay_settings->market_endpoint == 'hu' ) ) )
     29    $leanpay_environment = 'test-app';
     30elseif( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( $leanpay_settings->market_endpoint == 'si' ) )
     31    $leanpay_environment = 'stage-app';
    3032
    31 $market_endpoint_safe = sanitize_text_field($settings->market_endpoint);
    32 $link_checkout = "https://" . esc_attr($environment) . ".leanpay." . esc_attr($market_endpoint_safe) . "/vendor/checkout";
    33 $link_token = "https://" . esc_attr($environment) . ".leanpay." . esc_attr($market_endpoint_safe) . "/vendor/token";
     33$leanpay_market_endpoint_safe = sanitize_text_field($leanpay_settings->market_endpoint);
     34$leanpay_link_checkout = "https://" . esc_attr($leanpay_environment) . ".leanpay." . esc_attr($leanpay_market_endpoint_safe) . "/vendor/checkout";
     35$leanpay_link_token = "https://" . esc_attr($leanpay_environment) . ".leanpay." . esc_attr($leanpay_market_endpoint_safe) . "/vendor/token";
    3436
    35 $cart_items = array();
     37$leanpay_cart_items = array();
    3638
    3739foreach (WC()
    3840    ->cart
    39     ->get_cart() as $cart_item)
     41    ->get_cart() as $leanpay_cart_item)
    4042{
    41     $product = $cart_item['data'];
    42     array_push($cart_items, array(
    43         'name' => $cart_item['data']->get_name() ,
    44         'sku' => $cart_item['data']->get_sku() ,
    45         'price' => $cart_item['data']->get_price() ,
    46         'qty' => $cart_item['quantity']
     43    $leanpay_product = $leanpay_cart_item['data'];
     44    array_push($leanpay_cart_items, array(
     45        'name' => $leanpay_cart_item['data']->get_name() ,
     46        'sku' => $leanpay_cart_item['data']->get_sku() ,
     47        'price' => $leanpay_cart_item['data']->get_price() ,
     48        'qty' => $leanpay_cart_item['quantity']
    4749    ));
    4850}
     
    5153?>
    5254
    53 <form method="post" id="leanpay_html_form" action="<?php echo esc_url($link_checkout); ?>">
     55<form method="post" id="leanpay_html_form" action="<?php echo esc_url($leanpay_link_checkout); ?>">
    5456
    5557<?php
    56 $success_url = ($settings->failure_url_checkbox == 'no' || empty($settings->success_url))
     58$leanpay_success_url = ($leanpay_settings->failure_url_checkbox == 'no' || empty($leanpay_settings->success_url))
    5759    ? $order->get_checkout_order_received_url()
    58     : esc_url_raw($settings->success_url);
    59 $error_url = ($settings->failure_url_checkbox == 'no' || empty($settings->failure_url))
     60    : esc_url_raw($leanpay_settings->success_url);
     61$leanpay_error_url = ($leanpay_settings->failure_url_checkbox == 'no' || empty($leanpay_settings->failure_url))
    6062    ? wc_get_checkout_url()
    61     : esc_url_raw($settings->failure_url);
     63    : esc_url_raw($leanpay_settings->failure_url);
    6264
    63 $data = array(
    64     'vendorApiKey' => sanitize_text_field($settings->API_id),
    65     'vendorTransactionId' => absint($order_id) . "-" . time() ,
     65$leanpay_data = array(
     66    'vendorApiKey' => sanitize_text_field($leanpay_settings->API_id),
     67    'vendorTransactionId' => absint($leanpay_order_id) . "-" . time() ,
    6668    'amount' => floatval($order->get_total()) ,
    67     'successUrl' => $success_url,
    68     'errorUrl' => $error_url,
     69    'successUrl' => $leanpay_success_url,
     70    'errorUrl' => $leanpay_error_url,
    6971    'vendorPhoneNumber' => sanitize_text_field($order->get_billing_phone()) ,
    7072    'vendorFirstName' => sanitize_text_field($order->get_billing_first_name()) ,
     
    7375    'vendorZip' => sanitize_text_field($order->get_billing_postcode()) ,
    7476    'vendorCity' => sanitize_text_field($order->get_billing_city()) ,
    75     'language' => sanitize_text_field($settings->market_endpoint),
    76     'CartItems' => $cart_items
     77    'language' => sanitize_text_field($leanpay_settings->market_endpoint),
     78    'CartItems' => $leanpay_cart_items
    7779);
    7880
    79 $data_json = wp_json_encode($data);
     81$leanpay_data_json = wp_json_encode($leanpay_data);
    8082
    81 $response = wp_remote_post($link_token, array(
    82     'body' => $data_json,
     83$leanpay_response = wp_remote_post($leanpay_link_token, array(
     84    'body' => $leanpay_data_json,
    8385    'headers' => array(
    8486        'Content-Type' => 'application/json',
     
    8991));
    9092
    91 if (is_wp_error($response)) {
    92     echo esc_html("Error: " . $response->get_error_message());
    93     $result = array();
     93if (is_wp_error($leanpay_response)) {
     94    echo esc_html("Error: " . $leanpay_response->get_error_message());
     95    $leanpay_result = array();
    9496} else {
    95     $response_body = wp_remote_retrieve_body($response);
    96     $result = json_decode($response_body, true);
     97    $leanpay_response_body = wp_remote_retrieve_body($leanpay_response);
     98    $leanpay_result = json_decode($leanpay_response_body, true);
    9799}
    98100
    99101?>
    100102
    101   <input type="hidden" name="token" value="<?php echo isset($result['token']) ? esc_attr($result['token']) : ''; ?>" />
     103  <input type="hidden" name="token" value="<?php echo isset($leanpay_result['token']) ? esc_attr($leanpay_result['token']) : ''; ?>" />
    102104  <input type="submit" value="Buy with Leanpay" style="display:none;">
    103105
    104106</form>
    105 <script>
    106     document.getElementById("leanpay_html_form").submit();
    107 </script>
     107<?php
     108wp_register_script( 'leanpay-form-submit', false, [], ( defined( 'LEANPAY_VERSION' ) ? LEANPAY_VERSION : '1.0' ), true );
     109wp_add_inline_script( 'leanpay-form-submit', 'document.getElementById("leanpay_html_form").submit();' );
     110wp_enqueue_script( 'leanpay-form-submit' );
     111wp_print_scripts( 'leanpay-form-submit' );
     112?>
    108113</body>
    109114</html>
  • wc-leanpay/trunk/languages/wc-leanpay-hr.po

    r3492394 r3492436  
    1313"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    1414"X-Generator: Loco https://localise.biz/\n"
    15 "X-Domain: leanpay-obrocne-cene\n"
     15"X-Domain: wc-leanpay\n"
    1616"POT-Creation-Date: 2025-10-28 09:08+0000\n"
    1717"X-Loco-Version: 2.8.0; wp-6.8.3; php-8.3.7"
  • wc-leanpay/trunk/status.php

    r3492394 r3492436  
    11<?php
    2 
    3 require_once('../../../wp-load.php');
    4 
    5 if (!defined('ABSPATH')) {
    6     exit;
     2// Webhook requests are now handled via the REST API at /wp-json/wc-leanpay/v1/status
     3// This file is kept for backwards compatibility and does nothing.
     4if ( ! defined( 'ABSPATH' ) ) {
     5    exit;
    76}
    8 
    9 $settings = new WC_Leanpay();
    10 
    11 $raw_post = file_get_contents('php://input');
    12 $decoded = json_decode($raw_post, true);
    13 
    14 if (!empty($decoded) && is_array($decoded))
    15 {
    16     // Validate and sanitize input data
    17     if (empty($decoded['vendorTransactionId']) || !is_string($decoded['vendorTransactionId'])) {
    18         status_header(400);
    19         echo esc_html("Invalid vendorTransactionId");
    20         exit;
    21     }
    22    
    23     $vendorTransactionId = sanitize_text_field($decoded['vendorTransactionId']);
    24     $orderId = absint(preg_replace("/[^0-9]/", "", strtok($vendorTransactionId, "-")));
    25    
    26     if (empty($orderId)) {
    27         status_header(400);
    28         echo esc_html("Invalid order ID");
    29         exit;
    30     }
    31    
    32     $order = wc_get_order($orderId);
    33     if (!$order || $order->get_payment_method() != 'wc_leanpay_module') {
    34         status_header(400);
    35         echo esc_html("Invalid order or payment method");
    36         exit;
    37     }
    38    
    39     $has_transaction_id = $order->get_meta( 'leanpay_vendor_transaction_id' );
    40     if( $has_transaction_id ) {
    41         status_header(200);
    42         echo esc_html("Transaction already processed");
    43         exit;
    44     }
    45    
    46     // Validate and sanitize amount
    47     if (!isset($decoded['amount']) || !is_numeric($decoded['amount'])) {
    48         status_header(400);
    49         echo esc_html("Invalid amount");
    50         exit;
    51     }
    52     $amount = (string)number_format(floatval($decoded['amount']), 2, ".", "");
    53    
    54     // Validate and sanitize status
    55     $valid_statuses = array('SUCCESS', 'FAILED', 'CANCELED', 'EXPIRED');
    56     if (empty($decoded['status']) || !in_array($decoded['status'], $valid_statuses, true)) {
    57         $status = isset($decoded['status']) ? sanitize_text_field($decoded['status']) : 'UNKNOWN';
    58     } else {
    59         $status = sanitize_text_field($decoded['status']);
    60     }
    61    
    62     $md5secretPass = md5($settings->API_secret);
    63    
    64     switch ($status)
    65     {
    66         case 'SUCCESS':
    67             if (empty($decoded['leanPayTransactionId']) || !is_string($decoded['leanPayTransactionId'])) {
    68                 status_header(400);
    69                 echo esc_html("Invalid leanPayTransactionId");
    70                 exit;
    71             }
    72             $leanPayTransactionId = sanitize_text_field($decoded['leanPayTransactionId']);
    73             $md5hashValidation = md5($leanPayTransactionId . $vendorTransactionId . $md5secretPass . $amount . $status);
    74            
    75             $md5Signature = isset($decoded['md5Signature']) ? sanitize_text_field($decoded['md5Signature']) : '';
    76            
    77             $order->update_status($settings->completed_status, sprintf(__('Your purchase was completed successfully.', 'wc-leanpay') , get_woocommerce_currency() , $order->get_total()));
    78             if ($md5Signature === $md5hashValidation)
    79             {
    80                 $order->update_meta_data("leanpay_vendor_transaction_id", $vendorTransactionId);
    81                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status));
    82             }
    83             else
    84             {
    85                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status) . ". NOTICE: md5 hashes do not match, compare order attributes and values in woocommerce and leanpay vendor dashboard.");
    86             }
    87         break;
    88 
    89         case 'FAILED':
    90             $leanPayTransactionId = "null";
    91             $md5hashValidation = md5($leanPayTransactionId . $vendorTransactionId . $md5secretPass . $amount . $status);
    92             $md5Signature = isset($decoded['md5Signature']) ? sanitize_text_field($decoded['md5Signature']) : '';
    93            
    94             $order->update_status($settings->failed_status, sprintf(__('The transaction was not successfully completed.', 'wc-leanpay')));
    95             if ($md5Signature === $md5hashValidation)
    96             {
    97                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status));
    98             }
    99             else
    100             {
    101                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status) . ". NOTICE: md5 hashes do not match, compare order attributes and values in woocommerce and leanpay vendor dashboard.");
    102             }
    103         break;
    104 
    105         case 'CANCELED':
    106             $leanPayTransactionId = "null";
    107             $md5hashValidation = md5($leanPayTransactionId . $vendorTransactionId . $md5secretPass . $amount . $status);
    108             $md5Signature = isset($decoded['md5Signature']) ? sanitize_text_field($decoded['md5Signature']) : '';
    109            
    110             $order->update_status($settings->failed_status, sprintf(__('The transaction was cancelled.', 'wc-leanpay')));
    111             if ($md5Signature === $md5hashValidation)
    112             {
    113                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status));
    114             }
    115             else
    116             {
    117                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status) . ". NOTICE: md5 hashes do not match, compare order attributes and values in woocommerce and leanpay vendor dashboard.");
    118             }
    119         break;
    120 
    121         case 'EXPIRED':
    122             $leanPayTransactionId = "null";
    123             $md5hashValidation = md5($leanPayTransactionId . $vendorTransactionId . $md5secretPass . $amount . $status);
    124             $md5Signature = isset($decoded['md5Signature']) ? sanitize_text_field($decoded['md5Signature']) : '';
    125            
    126             $order->update_status($settings->failed_status, sprintf(__('Your session has expired.', 'wc-leanpay')));
    127             if ($md5Signature === $md5hashValidation)
    128             {
    129                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status));
    130             }
    131             else
    132             {
    133                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status) . ". NOTICE: md5 hashes do not match, compare order attributes and values in woocommerce and leanpay vendor dashboard.");
    134             }
    135         break;
    136 
    137         default:
    138             $leanPayTransactionId = "null";
    139             $order->update_status($settings->failed_status, sprintf(__('An error occurred, please try again.', 'wc-leanpay')));
    140             $md5hashValidation = md5($leanPayTransactionId . $vendorTransactionId . $md5secretPass . $amount . $status);
    141             $md5Signature = isset($decoded['md5Signature']) ? sanitize_text_field($decoded['md5Signature']) : '';
    142            
    143             if ($md5Signature === $md5hashValidation)
    144             {
    145                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status));
    146             }
    147             else
    148             {
    149                 $order->update_meta_data("leanpay_order_status", "LeanPay Response Status: " . strtoupper($status) . ". NOTICE: md5 hashes do not match, compare order attributes and values in woocommerce and leanpay vendor dashboard.");
    150             }
    151         break;
    152     }
    153     $order->save();
    154     echo esc_html($status);
    155 }
    156 else
    157 {
    158     status_header(400);
    159     echo esc_html("No input found");
    160 }
    161 
  • wc-leanpay/trunk/wc-leanpay.php

    r3492394 r3492436  
    77 * Author: Leanpay
    88 * Author URI: https://leanpay.com
    9  * Version: 6.0.2
     9 * Version: 6.0.3
    1010 * Text Domain: wc-leanpay
    1111 * Domain Path: /languages
    12  * WC tested up to: 10.4.2
     12 * WC tested up to: 10.4.3
     13 * WordPress tested up to: 6.9.1
    1314 * License: GPL-2.0+
     15 * Requires Plugins: woocommerce
    1416 */
    1517
     
    2224
    2325use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
     26
     27add_action( 'rest_api_init', function() {
     28    register_rest_route( 'wc-leanpay/v1', '/status', array(
     29        array(
     30            'methods'             => 'GET',
     31            'callback'            => function() {
     32                return new WP_REST_Response( array(
     33                    'code'    => 'leanpay_webhook',
     34                    'message' => __( 'Leanpay webhook endpoint. Order status updates must be sent via POST with JSON body.', 'wc-leanpay' ),
     35                ), 200 );
     36            },
     37            'permission_callback' => '__return_true',
     38        ),
     39        array(
     40            'methods'             => 'POST',
     41            'callback'            => 'leanpay_webhook_handler',
     42            'permission_callback' => '__return_true',
     43        ),
     44    ) );
     45} );
     46
     47function leanpay_webhook_handler( $request ) {
     48    $decoded = $request->get_json_params();
     49
     50    if ( empty( $decoded ) || ! is_array( $decoded ) ) {
     51        return new WP_REST_Response( 'No input found', 400 );
     52    }
     53
     54    if ( empty( $decoded['vendorTransactionId'] ) || ! is_string( $decoded['vendorTransactionId'] ) ) {
     55        return new WP_REST_Response( 'Invalid vendorTransactionId', 400 );
     56    }
     57
     58    $vendorTransactionId = sanitize_text_field( $decoded['vendorTransactionId'] );
     59    $orderId             = absint( preg_replace( '/[^0-9]/', '', strtok( $vendorTransactionId, '-' ) ) );
     60
     61    if ( empty( $orderId ) ) {
     62        return new WP_REST_Response( 'Invalid order ID', 400 );
     63    }
     64
     65    $order = wc_get_order( $orderId );
     66    if ( ! $order || $order->get_payment_method() !== 'wc_leanpay_module' ) {
     67        return new WP_REST_Response( 'Invalid order or payment method', 400 );
     68    }
     69
     70    if ( $order->get_meta( 'leanpay_vendor_transaction_id' ) ) {
     71        return new WP_REST_Response( 'Transaction already processed', 200 );
     72    }
     73
     74    if ( ! isset( $decoded['amount'] ) || ! is_numeric( $decoded['amount'] ) ) {
     75        return new WP_REST_Response( 'Invalid amount', 400 );
     76    }
     77    $amount = number_format( floatval( $decoded['amount'] ), 2, '.', '' );
     78
     79    $valid_statuses = array( 'SUCCESS', 'FAILED', 'CANCELED', 'EXPIRED' );
     80    $status         = ( ! empty( $decoded['status'] ) && in_array( $decoded['status'], $valid_statuses, true ) )
     81        ? sanitize_text_field( $decoded['status'] )
     82        : 'UNKNOWN';
     83
     84    $settings       = new Leanpay_Gateway();
     85    $md5secretPass  = md5( $settings->API_secret );
     86
     87    $leanPayTransactionId = 'null';
     88    if ( $status === 'SUCCESS' ) {
     89        if ( empty( $decoded['leanPayTransactionId'] ) || ! is_string( $decoded['leanPayTransactionId'] ) ) {
     90            return new WP_REST_Response( 'Invalid leanPayTransactionId', 400 );
     91        }
     92        $leanPayTransactionId = sanitize_text_field( $decoded['leanPayTransactionId'] );
     93    }
     94
     95    $md5hashValidation = md5( $leanPayTransactionId . $vendorTransactionId . $md5secretPass . $amount . $status );
     96    $md5Signature      = isset( $decoded['md5Signature'] ) ? sanitize_text_field( $decoded['md5Signature'] ) : '';
     97
     98    if ( $md5Signature !== $md5hashValidation ) {
     99        return new WP_REST_Response( 'Invalid signature', 403 );
     100    }
     101
     102    switch ( $status ) {
     103        case 'SUCCESS':
     104            $order->update_status( $settings->completed_status, __( 'Your purchase was completed successfully.', 'wc-leanpay' ) );
     105            $order->update_meta_data( 'leanpay_vendor_transaction_id', $vendorTransactionId );
     106            break;
     107
     108        case 'FAILED':
     109            $order->update_status( $settings->failed_status, __( 'The transaction was not successfully completed.', 'wc-leanpay' ) );
     110            break;
     111
     112        case 'CANCELED':
     113            $order->update_status( $settings->failed_status, __( 'The transaction was cancelled.', 'wc-leanpay' ) );
     114            break;
     115
     116        case 'EXPIRED':
     117            $order->update_status( $settings->failed_status, __( 'Your session has expired.', 'wc-leanpay' ) );
     118            break;
     119
     120        default:
     121            $order->update_status( $settings->failed_status, __( 'An error occurred, please try again.', 'wc-leanpay' ) );
     122            break;
     123    }
     124
     125    $order->update_meta_data( 'leanpay_order_status', 'LeanPay Response Status: ' . strtoupper( $status ) );
     126    $order->save();
     127
     128    return new WP_REST_Response( $status, 200 );
     129}
    24130
    25131add_action( 'before_woocommerce_init', function() {
     
    39145function leanpay_add_gateway_class($gateways)
    40146{
    41     //     $gateways[] = 'WC_Leanpay'; // your class name is here
    42     array_unshift($gateways, "WC_Leanpay");
     147    //     $gateways[] = 'Leanpay_Gateway'; // your class name is here
     148    array_unshift($gateways, "Leanpay_Gateway");
    43149
    44150    return $gateways;
     
    46152
    47153// Render callback for horizontal block
    48 function wc_leanpay_render_horizontal($attrs){
     154function leanpay_render_horizontal($attrs){
    49155    $price = isset($attrs['price']) ? esc_html($attrs['price']) : '10 EUR';
    50156    ob_start();
     
    64170
    65171// Render callback for horizontal block
    66 function wc_leanpay_render_vertical($attrs){
     172function leanpay_render_vertical($attrs){
    67173    $price = isset($attrs['price']) ? esc_html($attrs['price']) : '10 EUR';
    68174    ob_start();
     
    84190add_action('init', function(){
    85191    register_block_type(__DIR__.'/blocks/horizontal', [
    86         'render_callback' => 'wc_leanpay_render_horizontal'
     192        'render_callback' => 'leanpay_render_horizontal'
    87193    ]);
    88194    register_block_type(__DIR__.'/blocks/vertical', [
    89         'render_callback' => 'wc_leanpay_render_vertical'
     195        'render_callback' => 'leanpay_render_vertical'
    90196    ]);
    91197});
     
    124230    $args = null
    125231) {
    126     $settings = new WC_Leanpay();
     232    $settings = new Leanpay_Gateway();
    127233    if (
    128234        $settings->enabled != "no" &&
     
    130236        $settings->on_catalog_pages == "yes"
    131237    ) {
    132         $before = show_leanpay_on_archive_page();
     238        $before = leanpay_show_on_archive_page();
    133239        return $before . $add_to_cart_html;
    134240    }
     
    166272
    167273function leanpay_get_banners() {
    168     require_once ABSPATH . "wp-admin/includes/file.php";
    169274    $images = glob(plugin_dir_path(__FILE__) ."images/banners/*.png");
    170275    foreach( $images as $image ):
     
    175280function leanpay_upload_banner_on_activation($image_abs_url)
    176281{
    177     require_once ABSPATH . "wp-admin/includes/file.php";
     282    if ( ! function_exists( 'download_url' ) ) {
     283        require_once ABSPATH . 'wp-admin/includes/file.php';
     284    }
    178285   
    179286    $image_url = plugin_dir_url(__FILE__) . "images/banners/".basename($image_abs_url);
     
    213320    }
    214321
    215     require_once ABSPATH . "wp-admin/includes/image.php";
     322    if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
     323        require_once ABSPATH . 'wp-admin/includes/image.php';
     324    }
    216325
    217326    wp_update_attachment_metadata(
     
    276385    }
    277386
    278    
    279     load_plugin_textdomain(
    280         "wc-leanpay",
    281         false,
    282         plugin_basename(dirname(__FILE__)) . "/languages"
    283     );
    284    
    285 
    286     class WC_Leanpay extends WC_Payment_Gateway
     387    $domain = 'wc-leanpay';
     388    if ( ! is_textdomain_loaded( $domain ) ) {
     389        load_plugin_textdomain( $domain, false, plugin_basename(dirname(__FILE__)) . "/languages" );
     390    }
     391
     392
     393    class Leanpay_Gateway extends WC_Payment_Gateway
    287394    {
    288395        public $API_id;
     
    321428        public $wc_leanpay_price_color;
    322429        public $wc_leanpay_action_color;
    323         public $custom_css;
    324430        public $is_rendered = false;
    325431
     
    352458            $this->API_secret = $this->sandbox_mode == "yes" ? $this->get_option("sandbox_API_secret") : $this->get_option("API_secret");
    353459            //$this->API_vendor_url = $this->get_option("API_vendor_url");
    354             $this->update_option("API_vendor_url", get_site_url().'/wp-content/plugins/wc-leanpay/status.php');
    355             $this->API_vendor_url = get_site_url().'/wp-content/plugins/wc-leanpay/status.php';
     460            $this->update_option("API_vendor_url", rest_url('wc-leanpay/v1/status'));
     461            $this->API_vendor_url = rest_url('wc-leanpay/v1/status');
    356462            $this->info_page_url = $this->get_option("info_page_url");
    357463            $this->market_endpoint = $this->get_option("market_endpoint");
    358             $this->double_price = $this->get_option("double_price");
    359             $this->test_ips = $this->get_option("test_ips");
    360 
    361             if( $this->sandbox_mode == "yes" ) {
    362                 $this->check_limit_url = "https://stage-app.leanpay.".$this->market_endpoint."/vendor/pre-qualified?vendor=j45qye";
    363             } else {
    364                 $this->check_limit_url = "https://app.leanpay.".$this->market_endpoint."/vendor/pre-qualified?vendor=j45qye";
     464            $this->double_price    = $this->get_option("double_price");
     465            $this->test_ips        = $this->get_option("test_ips");
     466
     467            // Pre-qualify URL (Check your limit)
     468            $this->check_limit_url = $this->get_option( 'check_limit_url' );
     469
     470            if ( empty( $this->check_limit_url ) ) {
     471                if ( $this->sandbox_mode === 'yes' ) {
     472                    $this->check_limit_url = 'https://stage-app.leanpay.' . $this->market_endpoint . '/vendor/pre-qualified?vendor=j45qye';
     473                } else {
     474                    $this->check_limit_url = 'https://app.leanpay.' . $this->market_endpoint . '/vendor/pre-qualified?vendor=j45qye';
     475                }
    365476            }
    366477           
     
    404515            $this->success_url_checkbox = $this->get_option("success_url_checkbox");
    405516            $this->failure_url_checkbox = $this->get_option("failure_url_checkbox");
    406             $this->custom_css = $this->get_option("custom_css");
    407517
    408518           
     
    441551                // Replace 'my-script-handle' with the handle of the script that needs params.
    442552                // If you don't have a custom script, enqueue one and localize it.
    443                 wp_enqueue_script( 'my-price-script', get_stylesheet_directory_uri() . '/js/my-price.js', array(), 1, true );
    444                 wp_localize_script( 'my-price-script', 'wc_price_params', $params );
     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 );
    445555            }
    446556
     
    497607
    498608            wp_register_script(
    499                 "admin_js",
     609                "leanpay-admin-js",
    500610                plugin_dir_url(__FILE__) . "assets/js/admin.js",
    501611                ["jquery"],
    502                 "2.0.2"
     612                LEANPAY_VERSION,
     613                false
    503614            );
    504             wp_enqueue_script("admin_js");
     615            wp_enqueue_script("leanpay-admin-js");
    505616
    506617            wp_register_style(
    507                 "admin_css",
     618                "leanpay-admin-css",
    508619                plugin_dir_url(__FILE__) . "assets/css/admin.css",
    509620                false,
    510                 "2.0.2"
     621                LEANPAY_VERSION
    511622            );
    512             wp_enqueue_style("admin_css");
     623            wp_enqueue_style("leanpay-admin-css");
    513624        }
    514625
     
    573684                plugin_dir_url(__FILE__) . "assets/css/style.css",
    574685                false,
    575                 "2.0.2"
     686                LEANPAY_VERSION
    576687            );
    577688
    578689            wp_enqueue_style("leanpay_cene_css");
    579690            wp_enqueue_style("leanpay_slider_css");
    580 
    581             // Add custom CSS if provided
    582             if (!empty($this->custom_css)) {
    583                 wp_add_inline_style("leanpay_cene_css", wp_strip_all_tags($this->custom_css));
    584             }
    585691
    586692            wp_enqueue_script(
     
    599705                true
    600706            );
    601             wp_localize_script("leanpay_variations_js", "myAjax", [
     707            wp_localize_script("leanpay_variations_js", "leanpayAjax", [
    602708                "ajaxurl" => admin_url("admin-ajax.php"),
    603709            ]);
     
    658764        function checkout_generate_title()
    659765        {
    660             $prices = show_leanpay_on_checkout();
     766            $prices = leanpay_show_on_checkout();
    661767            if ($prices == "") {
    662768                return [$prices, true];
     
    674780                if ($this->API_id == "") {
    675781                    add_action("admin_notices", function() {
    676                         admin_notices_message(__("Warning: enter API ID", "wc-leanpay"));
     782                        leanpay_admin_notices_message(__("Warning: enter API ID", "wc-leanpay"));
    677783                    });
    678784                    return;
    679785                }
    680786
    681                 if (!wp_next_scheduled("update_installment_plans_action")) {
     787                if (!wp_next_scheduled("leanpay_update_plans_action")) {
    682788                    wp_schedule_event(
    683789                        strtotime(gmdate("H:i", strtotime($this->update_schedule))),
    684790                        "daily",
    685                         "update_installment_plans_action"
     791                        "leanpay_update_plans_action"
    686792                    );
    687793                    add_action("admin_notices", function() {
    688                         admin_notices_message(__("Leanpay updates installment prices in the background.", "wc-leanpay"));
     794                        leanpay_admin_notices_message(__("Leanpay updates installment prices in the background.", "wc-leanpay"));
    689795                    });
    690796                }
     
    701807            $current_panel = empty($_REQUEST["section"])
    702808                ? ""
    703                 : sanitize_text_field(urldecode($_REQUEST["section"]));
     809                : sanitize_text_field(wp_unslash($_REQUEST["section"]));
     810
    704811            if (
    705812                isset($_POST["leanpay_manual_update"]) &&
    706813                $current_panel == "wc_leanpay_module"
    707814            ) {
     815                if ( ! isset( $_POST['leanpay_manual_update_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['leanpay_manual_update_nonce'] ) ), 'leanpay_manual_update' ) ) {
     816                    add_action( 'admin_notices', function() {
     817                        leanpay_admin_notices_message( __( 'Security check failed. Please try again.', 'wc-leanpay' ), 'error' );
     818                    } );
     819                    return;
     820                }
     821
     822                if ( ! current_user_can( 'manage_woocommerce' ) ) {
     823                    return;
     824                }
     825
    708826                if ($this->API_id == "") {
    709827                    add_action("admin_notices", function() {
    710                         admin_notices_message("Warning: enter API ID");
     828                        leanpay_admin_notices_message("Warning: enter API ID");
    711829                    });
    712830                    return;
    713831                }
    714832
    715                 if ( !wp_next_scheduled("manual_update_installment_plans_action") ) {
     833                if ( !wp_next_scheduled("manual_leanpay_update_plans_action") ) {
    716834                    wp_schedule_single_event(
    717835                        time() + 10,
    718                         "manual_update_installment_plans_action"
     836                        "manual_leanpay_update_plans_action"
    719837                    );
    720838                    add_action("admin_notices", function() {
    721                         admin_notices_message(__( "Leanpay updates installment prices in the background.","wc-leanpay"),"updated");
     839                        leanpay_admin_notices_message(__( "Leanpay updates installment prices in the background.","wc-leanpay"),"updated");
    722840                    });
    723841                }
     
    755873                $data["title"]
    756874            ); ?></span></legend>
    757                         <form method="post">
    758                             <?php wp_nonce_field('leanpay_manual_update', '_wpnonce'); ?>
     875                        <form method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wc_leanpay_module' ) ); ?>">
     876                            <?php wp_nonce_field( 'leanpay_manual_update', 'leanpay_manual_update_nonce', true ); ?>
     877                            <input type="hidden" name="leanpay_manual_update" value="all" />
    759878                            <?php echo esc_html(submit_button(
    760879                          __("Update product prices", "wc-leanpay")
    761880                      )); ?>
    762                             <input type="hidden" name="leanpay_manual_update" value="all" />
    763                         </form>
     881                    </form>
    764882                        <?php echo esc_html($this->get_description_html($data)); ?>
    765883                    </fieldset>
     
    784902                add_action("admin_notices", function() use ($amount) {
    785903                    // translators: %s is the minimum allowed order total amount.
    786                     admin_notices_message(sprintf(__("The chosen minimum total amount is too low (the minimum limit is %s)", "wc-leanpay"), $amount));
     904                    leanpay_admin_notices_message(sprintf(__("The chosen minimum total amount is too low (the minimum limit is %s)", "wc-leanpay"), $amount));
    787905                });
    788906                return $amount;
     
    805923                add_action("admin_notices", function() use ($amount) {
    806924                    // translators: %s is the maximum allowed order total amount.
    807                     admin_notices_message(sprintf(__("The chosen maximum total amount is too high (the maximum limit is %s)", "wc-leanpay"), $amount));
     925                    leanpay_admin_notices_message(sprintf(__("The chosen maximum total amount is too high (the maximum limit is %s)", "wc-leanpay"), $amount));
    808926                });
    809927                return $amount;
     
    844962add_filter(
    845963    'woocommerce_available_payment_gateways',
    846     'change_leanpay_payment_gateway_description',
     964    'leanpay_change_payment_gateway_description',
    847965    10,
    848966    1
    849967);
    850968
    851 function change_leanpay_payment_gateway_description( $gateways ) {
     969function leanpay_change_payment_gateway_description( $gateways ) {
    852970
    853971    if ( ! isset( $gateways['wc_leanpay_module'] ) ) {
     
    857975        return $gateways;
    858976    }
    859     $html = show_leanpay_on_checkout();
     977    $html = leanpay_show_on_checkout();
    860978    $gateways['wc_leanpay_module']->description = $html . $gateways['wc_leanpay_module']->description;
    861979    $gateways['wc_leanpay_module']->is_rendered = true;
     
    869987 */
    870988add_action(
    871     "update_installment_plans_action",
    872     "update_installment_plans_function"
     989    "leanpay_update_plans_action",
     990    "leanpay_update_installment_plans_function"
    873991);
    874992add_action(
    875     "manual_update_installment_plans_action",
    876     "update_installment_plans_function"
     993    "manual_leanpay_update_plans_action",
     994    "leanpay_update_installment_plans_function"
    877995);
    878 function update_installment_plans_function()
     996function     leanpay_update_installment_plans_function()
    879997{
    880998    require_once plugin_dir_path(__FILE__) .
    881999        "/includes/leanpay_get_update_data.php";
    882     update_installment_plans();
    883 }
    884 //add_action("wp_ajax_update_installment_plans_function", "update_installment_plans_function");
    885 //add_action("wp_ajax_nopriv_update_installment_plans_function", "update_installment_plans_function");
     1000    leanpay_update_installment_plans();
     1001}
     1002//add_action("wp_ajax_update_installment_plans_function", "leanpay_update_installment_plans_function");
     1003//add_action("wp_ajax_nopriv_update_installment_plans_function", "leanpay_update_installment_plans_function");
    8861004
    8871005/**
    8881006 * Product page Leanpay calculation
    8891007 */
    890 add_action("woocommerce_simple_add_to_cart", "product_page_calculation");
    891 add_action("woocommerce_variable_add_to_cart", "product_page_calculation");
    892 add_action("woocommerce_grouped_add_to_cart", "product_page_calculation");
    893 
    894 add_shortcode('leanpay_product_page', 'product_page_calculation');
    895 
    896 function product_page_calculation($atts = array())
     1008add_action("woocommerce_simple_add_to_cart", "leanpay_product_page_calculation");
     1009add_action("woocommerce_variable_add_to_cart", "leanpay_product_page_calculation");
     1010add_action("woocommerce_grouped_add_to_cart", "leanpay_product_page_calculation");
     1011
     1012add_shortcode('leanpay_product_page', 'leanpay_product_page_calculation');
     1013
     1014function leanpay_product_page_calculation($atts = array(), $content = null, $tag = null)
    8971015{
    8981016    require_once plugin_dir_path(__FILE__) .
    8991017        "/includes/leanpay_frontend_display.php";
    900     if (!is_product()) return '';
    901     show_leanpay_on_product_page($atts);
    902 }
    903 
    904 function product_page_calculation2()
     1018    if (!is_product() && $tag !== 'leanpay_product_page') return '';
     1019    return leanpay_show_on_product_page($atts, $content, $tag);
     1020}
     1021
     1022function leanpay_product_page_calculation2()
    9051023{
    9061024    require_once plugin_dir_path(__FILE__) .
    9071025        "/includes/leanpay_frontend_display.php";
    908     echo wp_kses_post(show_leanpay_on_checkout());
     1026    echo wp_kses_post(leanpay_show_on_checkout());
    9091027    exit();
    9101028}
    911 add_action("wp_ajax_get_leanpay_calculator", "product_page_calculation2");
    912 add_action("wp_ajax_nopriv_get_leanpay_calculator", "product_page_calculation2");
     1029add_action("wp_ajax_get_leanpay_calculator", "leanpay_product_page_calculation2");
     1030add_action("wp_ajax_nopriv_get_leanpay_calculator", "leanpay_product_page_calculation2");
    9131031
    9141032/**
     
    9171035add_action(
    9181036    "woocommerce_sections_checkout",
    919     "action_woocommerce_sections_my_custom_tab",
     1037    "leanpay_action_woocommerce_sections_my_custom_tab",
    9201038    10
    9211039);
    922 function action_woocommerce_sections_my_custom_tab()
     1040function leanpay_action_woocommerce_sections_my_custom_tab()
    9231041{
    9241042    global $current_section;
    925     $settings = new WC_Leanpay();
     1043    $settings = new Leanpay_Gateway();
    9261044
    9271045    $tab_name = "checkout";
     
    9321050        "payment-configuration" => __("Payment Configuration", "wc-leanpay"),
    9331051        "settings" => __("Settings", "wc-leanpay"),
    934         "advanced" => __("Advanced", "wc-leanpay"),
    9351052    ];
    9361053
     
    9501067                    $settings->market_endpoint
    9511068            );
     1069            $url = wp_nonce_url( $url, 'leanpay_settings_panel' );
    9521070            $class = $current_section === $id ? "current" : "";
    9531071            $separator = end($array_keys) === $id ? "" : "|";
    9541072            $text = esc_html($label);
    955             echo "<li><a href='$url' class='$class'>$text</a> $separator </li>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
     1073            echo "<li><a href='" . esc_url( $url ) . "' class='" . esc_attr( $class ) . "'>" . esc_html( $text ) . "</a> " . esc_html( $separator ) . " </li>";
    9561074        }
    9571075        echo '</ul><br class="clear leanpay" />';
     
    9661084add_filter(
    9671085    "plugin_action_links_" . plugin_basename(__FILE__),
    968     "lp_plugin_action_links"
     1086    "leanpay_plugin_action_links"
    9691087);
    970 function lp_plugin_action_links($links)
     1088function leanpay_plugin_action_links($links)
    9711089{
    9721090    $plugin_links = [
     
    9881106{
    9891107    wp_register_script(
    990         "admin_meta_box_js",
     1108        "leanpay-admin-meta-box-js",
    9911109        plugin_dir_url(__FILE__) . "assets/js/admin_meta_box.js",
    9921110        ["jquery"],
    993         "2.0.2"
     1111        LEANPAY_VERSION,
     1112        false
    9941113    );
    995     wp_enqueue_script("admin_meta_box_js");
    996     wp_localize_script("admin_meta_box_js", "myAjax", [
     1114    wp_enqueue_script("leanpay-admin-meta-box-js");
     1115    wp_localize_script("leanpay-admin-meta-box-js", "leanpayAjax", [
    9971116        "ajaxurl" => admin_url("admin-ajax.php"),
    9981117    ]);
     
    10251144            echo "<p>" . esc_html($order->get_meta("leanpay_order_status", true)) . "</p>";
    10261145            echo "</div></li></ul>";
    1027             add_button_transaction_delivery();
     1146            leanpay_add_button_transaction_delivery();
    10281147        }
    10291148        else {
     
    10361155 * Add button inside meta box for transaction delivery on admin order details page
    10371156 */
    1038 if (!function_exists("add_button_transaction_delivery")) {
    1039     function add_button_transaction_delivery()
     1157if (!function_exists("leanpay_add_button_transaction_delivery")) {
     1158    function leanpay_add_button_transaction_delivery()
    10401159    {
    10411160        $order = wc_get_order(get_the_ID());
     
    10951214    require_once plugin_dir_path(__FILE__) .
    10961215        "/includes/leanpay_get_update_data.php";
    1097     $settings = new WC_Leanpay();
     1216    $settings = new Leanpay_Gateway();
    10981217
    10991218    $environment = "app";
     
    11101229    }
    11111230
    1112     delivery_verification_confirmation($settings->API_id, $settings->market_endpoint, $environment, "/vendor/transaction/delivery", $order_id);
     1231    leanpay_delivery_verification_confirmation($settings->API_id, $settings->market_endpoint, $environment, "/vendor/transaction/delivery", $order_id);
    11131232    wp_die();
    11141233}
     
    11321251    require_once plugin_dir_path(__FILE__) .
    11331252        "/includes/leanpay_get_update_data.php";
    1134     $settings = new WC_Leanpay();
     1253    $settings = new Leanpay_Gateway();
    11351254    $environment = "app";
    11361255
     
    11461265    }
    11471266
    1148     delivery_verification_confirmation($settings->API_id, $settings->market_endpoint, $environment, "/api/verification-document/get", $order_id);
     1267    leanpay_delivery_verification_confirmation($settings->API_id, $settings->market_endpoint, $environment, "/api/verification-document/get", $order_id);
    11491268    wp_die();
    11501269}
     
    11541273 */
    11551274
    1156 add_action("wp_ajax_get_leanpay_variation", "get_leanpay_variation");
    1157 add_action("wp_ajax_nopriv_get_leanpay_variation", "get_leanpay_variation");
    1158 function get_leanpay_variation()
     1275add_action("wp_ajax_get_leanpay_variation", "leanpay_get_variation");
     1276add_action("wp_ajax_nopriv_get_leanpay_variation", "leanpay_get_variation");
     1277function leanpay_get_variation()
    11591278{
    11601279    // Verify nonce for AJAX request (optional for non-logged-in users, but recommended)
     
    11731292    $price = floatval($price);
    11741293
    1175     echo esc_html(show_leanpay_on_product_page("", "", "variation", $price));
     1294    echo esc_html(leanpay_show_on_product_page("", "", "variation", $price));
    11761295    die();
    11771296}
     
    11801299 * Admin notice for manual instalment plan update error
    11811300 */
    1182 function admin_notices_message($message,$type = 'error')
     1301function leanpay_admin_notices_message($message,$type = 'error')
    11831302{
    11841303    global $current_screen;
     
    11931312        return;
    11941313
    1195     class WC_Leanpay_Blocks extends AbstractPaymentMethodType
     1314    class Leanpay_Blocks_Integration extends AbstractPaymentMethodType
    11961315    {
    11971316        private $gateway;
     
    12001319        public function initialize()
    12011320        {
    1202             $this->gateway = new WC_Leanpay();
     1321            $this->gateway = new Leanpay_Gateway();
    12031322        }
    12041323
     
    12201339                    'wp-i18n',
    12211340                ],
    1222                 null,
     1341                LEANPAY_VERSION,
    12231342                true
    12241343            );
     1344
     1345            wp_localize_script( 'leanpay-blocks-integration', 'leanpayBlocksData', [
     1346                'ajaxUrl' => admin_url( 'admin-ajax.php' ),
     1347            ] );
    12251348
    12261349            if( function_exists( 'wp_set_script_translations' ) )
     
    12401363
    12411364    add_action( 'woocommerce_blocks_payment_method_type_registration', function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
    1242         $payment_method_registry->register( new WC_Leanpay_Blocks );
     1365        $payment_method_registry->register( new Leanpay_Blocks_Integration );
    12431366    } );
    12441367}
Note: See TracChangeset for help on using the changeset viewer.