Changeset 3492436
- Timestamp:
- 03/27/2026 08:22:34 AM (6 days ago)
- Location:
- wc-leanpay/trunk
- Files:
-
- 2 added
- 4 deleted
- 17 edited
-
CHANGELOG.md (modified) (1 diff)
-
README.md (modified) (2 diffs)
-
assets/css/__jquery-ui.css (deleted)
-
assets/css/style.css (modified) (5 diffs)
-
assets/css/style.css.bak (deleted)
-
assets/css/style.css.prod (deleted)
-
assets/css/style.min.css (deleted)
-
assets/js/admin_meta_box.js (modified) (2 diffs)
-
assets/js/checkout.js (modified) (1 diff)
-
assets/js/leanpay.js (modified) (2 diffs)
-
assets/js/variations.js (modified) (2 diffs)
-
blocks/horizontal/block.json (modified) (1 diff)
-
blocks/vertical/block.json (modified) (1 diff)
-
changelog.txt (added)
-
includes/leanpay_admin_settings.php (modified) (9 diffs)
-
includes/leanpay_frontend_display.php (modified) (15 diffs)
-
includes/leanpay_get_update_data.php (modified) (16 diffs)
-
includes/leanpay_globals.php (modified) (2 diffs)
-
includes/leanpay_payment_confirmation.php (modified) (5 diffs)
-
languages/wc-leanpay-hr.po (modified) (1 diff)
-
readme.txt (added)
-
status.php (modified) (1 diff)
-
wc-leanpay.php (modified) (46 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wc-leanpay/trunk/CHANGELOG.md
r3492394 r3492436 5 5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 8 ## [6.0.3] - 2026-03-27 9 10 ### Changed 11 - WordPress.org release version. 12 - Updated readme/changelog packaging and release metadata for WordPress.org distribution. 7 13 8 14 ## [6.0.2] - 2026-02-03 -
wc-leanpay/trunk/README.md
r3492394 r3492436 4 4 **Tags:** woocommerce, payment, payment-gateway, installment, leanpay 5 5 **Requires at least:** 5.0 6 **Tested up to:** 6.9 6 **Tested up to:** 6.9.1 7 7 **Requires PHP:** 7.4 8 8 **WC requires at least:** 5.0 9 **WC tested up to:** 10.4. 210 **Stable tag:** 6.0. 09 **WC tested up to:** 10.4.3 10 **Stable tag:** 6.0.3 11 11 **License:** GPLv2 or later 12 12 **License URI:** https://www.gnu.org/licenses/gpl-2.0.html … … 103 103 * Documentation: Contact Leanpay support 104 104 105 ## External services 106 107 This 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 111 Leanpay 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 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. 128 129 ### Service provider and legal documents 130 131 This 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 105 137 ## Credits 106 138 -
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 1 60 #leanpayObrocneCeneAdmin .page-title { 2 61 background-size: auto; … … 87 146 line-height:130%; 88 147 gap: 16px; 148 font-family: 'Raleway', 'Roboto', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif; 89 149 } 90 150 … … 245 305 display:none; 246 306 user-select: none; 247 } 307 font-family: 'Raleway', 'Roboto', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif; 308 } 309 248 310 249 311 @media (max-width: 768px) { … … 693 755 } 694 756 695 .l eanpay_inst_slider_item {757 .lp_bottom .leanpay_inst_slider_item { 696 758 background: #fff; 697 759 color: #000; … … 703 765 } 704 766 705 .l eanpay_inst_slider_item::after {767 .lp_bottom .leanpay_inst_slider_item::after { 706 768 content: ''; 707 769 position: absolute; -
wc-leanpay/trunk/assets/js/admin_meta_box.js
r3492394 r3492436 4 4 transaction_btn.on('click', function(){ 5 5 $.ajax({ 6 url: myAjax.ajaxurl,6 url: leanpayAjax.ajaxurl, 7 7 dataType: 'json', 8 8 method:'POST', … … 31 31 transaction_btn.on('click', function(){ 32 32 $.ajax({ 33 url: myAjax.ajaxurl,33 url: leanpayAjax.ajaxurl, 34 34 dataType: 'json', 35 35 method:'POST', -
wc-leanpay/trunk/assets/js/checkout.js
r3492394 r3492436 9 9 useEffect(() => { 10 10 jQuery.get( 11 '/wp-admin/admin-ajax.php?action=get_leanpay_calculator',11 leanpayBlocksData.ajaxUrl + '?action=get_leanpay_calculator', 12 12 function (data) { 13 13 setDescription(data); -
wc-leanpay/trunk/assets/js/leanpay.js
r3492394 r3492436 88 88 89 89 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)); 92 99 93 100 jQuery("#leanpay_bullet").css("left", x + "px"); … … 214 221 215 222 function leanpay_wc_price(amount) { 216 amount = Number(amount).toFixed(parseInt( wc_price_params.decimals));223 amount = Number(amount).toFixed(parseInt(leanpay_price_params.decimals)); 217 224 218 225 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) { 224 231 case 'left': 225 return wc_price_params.currency_symbol + formatted;232 return leanpay_price_params.currency_symbol + formatted; 226 233 case 'right': 227 return formatted + wc_price_params.currency_symbol;234 return formatted + leanpay_price_params.currency_symbol; 228 235 case 'left_space': 229 return wc_price_params.currency_symbol + ' ' + formatted;236 return leanpay_price_params.currency_symbol + ' ' + formatted; 230 237 case 'right_space': 231 return formatted + ' ' + wc_price_params.currency_symbol;238 return formatted + ' ' + leanpay_price_params.currency_symbol; 232 239 } 233 240 } -
wc-leanpay/trunk/assets/js/variations.js
r3492394 r3492436 6 6 jQuery.ajax({ 7 7 type: "POST", 8 url: myAjax.ajaxurl,8 url: leanpayAjax.ajaxurl, 9 9 data: '&price='+price+'&action=get_leanpay_variation', 10 10 success: function(data) { … … 28 28 jQuery.ajax({ 29 29 type: "POST", 30 url: myAjax.ajaxurl,30 url: leanpayAjax.ajaxurl, 31 31 data: '&price='+price+'&action=get_leanpay_variation', 32 32 success: function(data) { -
wc-leanpay/trunk/blocks/horizontal/block.json
r3492394 r3492436 1 1 { 2 "apiVersion": 2,2 "apiVersion": 3, 3 3 "name": "wc-leanpay/horizontal-widget", 4 4 "title": "LeanPay Horizontal Widget", -
wc-leanpay/trunk/blocks/vertical/block.json
r3492394 r3492436 1 1 { 2 "apiVersion": 2,2 "apiVersion": 3, 3 3 "name": "wc-leanpay/vertical-widget", 4 4 "title": "LeanPay Vertical Widget", -
wc-leanpay/trunk/includes/leanpay_admin_settings.php
r3492394 r3492436 6 6 require_once plugin_dir_path(__FILE__) . '/leanpay_get_update_data.php'; 7 7 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 = ''; 11 if ( ( 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(); 15 16 16 17 leanpay_install_table_if_not_exists(); 17 18 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); 22 if (!empty($leanpay_financial_products)) $leanpay_financial_products = explode('#', $leanpay_financial_products); 23 24 if (is_array($leanpay_financial_products)) 25 { 26 foreach ($leanpay_financial_products as $leanpay_financial_product) 26 27 { 27 if ($ financial_product != "")28 if ($leanpay_financial_product != "") 28 29 { 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 ); 31 32 } 32 33 } 33 34 } 34 35 35 if( isset($ financial_products_arr[0]))36 { 37 $ default_financial_product = implode(" ",$financial_products_arr[0]);36 if( isset($leanpay_financial_products_arr[0])) 37 { 38 $leanpay_default_financial_product = implode(" ",$leanpay_financial_products_arr[0]); 38 39 } 39 40 else 40 41 { 41 $ default_financial_product = __('Please enter API Key', 'wc-leanpay');42 $leanpay_default_financial_product = __('Please enter API Key', 'wc-leanpay'); 42 43 } 43 44 … … 62 63 // } 63 64 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(); 67 68 $pages = get_pages(); 68 69 69 70 foreach($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 73 if ( $leanpay_current_panel == 'payment-configuration' ) 74 { 75 $leanpay_settings = apply_filters('leanpay_wc_settings', array( 75 76 'title' => array( 76 77 'title' => __('Payment title', 'wc-leanpay') , … … 92 93 'description' => __('Status shown when the order is succesful', 'wc-leanpay') , 93 94 'default' => 'wc-processing', 94 'options' => $ statuses95 'options' => $leanpay_statuses 95 96 ) , 96 97 'failed_status' => array( … … 100 101 'description' => __('Status shown when the order fails', 'wc-leanpay') , 101 102 'default' => 'wc-failed', 102 'options' => $ statuses103 'options' => $leanpay_statuses 103 104 ) , 104 105 'min_order_total' => array( … … 116 117 )); 117 118 } 118 else if ( $ current_panel == 'settings' )119 { 120 $leanpay_settings = apply_filters(' wc_leanpay_settings', array(119 else if ( $leanpay_current_panel == 'settings' ) 120 { 121 $leanpay_settings = apply_filters('leanpay_wc_settings', array( 121 122 'financial_product' => array( 122 123 'title' => __('Financial product', 'wc-leanpay') , … … 124 125 'description' => __('Select the product available in the webshop', 'wc-leanpay') , 125 126 '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_product127 'default' => $leanpay_default_financial_product, 128 'options' => ( !empty($leanpay_financial_products_arr) ) ? $leanpay_financial_products_arr : $leanpay_default_financial_product 128 129 ) , 129 130 'update_schedule' => array( … … 259 260 )); 260 261 } 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 }274 262 else 275 263 { 276 $leanpay_settings = apply_filters(' wc_leanpay_settings', array(264 $leanpay_settings = apply_filters('leanpay_wc_settings', array( 277 265 'enabled' => array( 278 266 'title' => __('Payment method', 'wc-leanpay') , … … 315 303 'default' => '', 316 304 ), 317 'API_vendor_url' => array(305 'API_vendor_url' => array( 318 306 'title' => __('API Vendor URL', 'wc-leanpay') , 319 307 'type' => 'text', 320 'default' => $ site_url,308 'default' => $leanpay_site_url, 321 309 'custom_attributes' => array('readonly' => 'readonly'), 322 310 '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'), 323 311 ), 324 'info_page_url' => array(312 'info_page_url' => array( 325 313 'title' => __('Info Page URL', 'wc-leanpay') , 326 314 'type' => 'text', 327 315 'default' => '', 328 316 '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'), 329 323 ), 330 324 'market_endpoint' => array( … … 368 362 } 369 363 370 return apply_filters(' wc_leanpay_settings', $leanpay_settings);364 return apply_filters('leanpay_wc_settings', $leanpay_settings); -
wc-leanpay/trunk/includes/leanpay_frontend_display.php
r3492394 r3492436 12 12 require_once plugin_dir_path(__FILE__) . '/leanpay_get_update_data.php'; 13 13 14 function l p_round( $price, $market_endpoint = '' )14 function leanpay_round( $price, $market_endpoint = '' ) 15 15 { 16 16 if( $market_endpoint == "ro" ) … … 23 23 * Show Leanpay lowest Installment plan per month on archive page - TO DO (Hrvaška, currency, napisi) 24 24 */ 25 function show_leanpay_on_archive_page()25 function leanpay_show_on_archive_page() 26 26 { 27 27 global $product; 28 $settings = new WC_Leanpay();28 $settings = new Leanpay_Gateway(); 29 29 $price = wc_get_price_including_tax($product); 30 30 … … 40 40 $currcode = get_woocommerce_currency_symbol(); 41 41 42 $raw = get_leanpay_prices();42 $raw = leanpay_get_leanpay_prices(); 43 43 44 44 $leanpay_prices = is_string($raw) … … 55 55 foreach ($leanpay_prices['loanAmounts'] as $leanpay_price) 56 56 { 57 if ($leanpay_price['loanAmount'] == l p_round($price, $settings->market_endpoint))57 if ($leanpay_price['loanAmount'] == leanpay_round($price, $settings->market_endpoint)) 58 58 { 59 59 foreach ($leanpay_price['possibleInstallments'] as $installment) … … 72 72 73 73 // 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); 75 75 76 76 // For prices <= threshold: show fewest installments (last element - most expensive per month) … … 112 112 } 113 113 114 add_shortcode('leanpay_catalog', ' show_leanpay_on_archive_page');114 add_shortcode('leanpay_catalog', 'leanpay_show_on_archive_page'); 115 115 116 116 /* 117 117 * Show Leanpay Calculation / Installment plan options on product page - TO DO (Hrvaška, currency, napisi) 118 118 */ 119 function show_leanpay_on_product_page($atts = array() , $content = null, $tag = null, $variation_price = '')119 function leanpay_show_on_product_page($atts = array() , $content = null, $tag = null, $variation_price = '') 120 120 { 121 $settings = new WC_Leanpay();121 $settings = new Leanpay_Gateway(); 122 122 123 123 if ((!is_product() && $variation_price == '') || ($settings->API_id == "") || ($settings->on_product_pages == 'no')) return; … … 144 144 $currcode = get_woocommerce_currency_symbol(); 145 145 146 $raw = get_leanpay_prices();146 $raw = leanpay_get_leanpay_prices(); 147 147 148 148 $leanpay_prices = is_string($raw) … … 160 160 161 161 // 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); 163 163 164 164 $html .= '<div class="leanpay-product-price-wrapp">'; … … 169 169 foreach ($leanpay_prices['loanAmounts'] as $leanpay_price) 170 170 { 171 if ($leanpay_price['loanAmount'] == l p_round($price, $settings->market_endpoint))171 if ($leanpay_price['loanAmount'] == leanpay_round($price, $settings->market_endpoint)) 172 172 { 173 173 foreach ($leanpay_price['possibleInstallments'] as $installment) … … 299 299 if ($tag == "leanpay_product_page") 300 300 { 301 return $html; 302 } 303 301 return wp_kses_post($html); 302 } 304 303 else 305 304 { 306 // $html is already built with escaped content, but we should use wp_kses_post for safety307 305 echo wp_kses_post($html); 308 306 } … … 310 308 311 309 312 function show_leanpay_on_checkout()310 function leanpay_show_on_checkout() 313 311 { 314 312 $settings = WC()->payment_gateways()->payment_gateways()['wc_leanpay_module'] ?? null; … … 320 318 321 319 // 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); 323 321 324 322 if ($price < $settings->min_order_total || $price > $settings->max_order_total || ($settings->on_checkout_page == 'no')) return ''; … … 333 331 $currcode = get_woocommerce_currency_symbol(); 334 332 335 $raw = get_leanpay_prices();333 $raw = leanpay_get_leanpay_prices(); 336 334 337 335 $leanpay_prices = is_string($raw) … … 352 350 foreach ($leanpay_prices['loanAmounts'] as $leanpay_price) 353 351 { 354 if ($leanpay_price['loanAmount'] == l p_round($price, $settings->market_endpoint))352 if ($leanpay_price['loanAmount'] == leanpay_round($price, $settings->market_endpoint)) 355 353 { 356 354 foreach ($leanpay_price['possibleInstallments'] as $installment) … … 484 482 * Format installment price - TO DO : preveri če je sploh potrebno 485 483 */ 486 function moneyFormat($cena)484 function leanpay_money_format($cena) 487 485 { 488 486 $cena = round($cena, 2); -
wc-leanpay/trunk/includes/leanpay_get_update_data.php
r3492394 r3492436 5 5 } 6 6 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 */ 12 function 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 7 21 8 22 … … 15 29 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 16 30 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 } 19 35 $charset_collate = $wpdb->get_charset_collate(); 20 36 … … 34 50 * Update Instalment plan 35 51 */ 36 function update_installment_plans()37 { 38 $settings = new WC_Leanpay();39 $calculationsArray = call_leanpay($settings->market_endpoint);52 function leanpay_update_installment_plans() 53 { 54 $settings = new Leanpay_Gateway(); 55 $calculationsArray = leanpay_call_leanpay($settings->market_endpoint); 40 56 41 57 $financial_product = ''; 42 58 if (is_array($calculationsArray) && count($calculationsArray) > 0) 43 59 { 44 delete_old_price_groups($settings->market_endpoint);60 leanpay_delete_old_price_groups($settings->market_endpoint); 45 61 foreach ($calculationsArray['groups'] as $produkt) 46 62 { … … 48 64 { 49 65 $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); 54 70 55 71 $lp = get_option( 'woocommerce_wc_leanpay_module_settings' ); … … 62 78 { 63 79 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(). 66 85 $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM `{$table}` WHERE title = 'groups' AND lng = %s", $settings->market_endpoint), ARRAY_A ); 67 86 … … 82 101 * Delete old price groups from database for language, passed as parameter 83 102 */ 84 function delete_old_price_groups($lng) 85 { 86 global $wpdb; 87 $table = $wpdb->prefix . 'leanpay_cene_tmp_2022'; 88 $table = esc_sql($table); 103 function leanpay_delete_old_price_groups($lng) 104 { 105 global $wpdb; 106 $table = leanpay_get_prices_table(); 107 if ( $table === null ) { 108 return; 109 } 89 110 $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(). 90 112 $wpdb->query($wpdb->prepare("DELETE FROM `{$table}` WHERE lng = %s", $lng)); 91 113 } … … 94 116 * Update prices based on country 95 117 */ 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); 118 function 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 } 101 125 $title = sanitize_text_field($title); 102 126 $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(). 103 128 $wpdb->query($wpdb->prepare("DELETE FROM `{$table}` WHERE title = %s AND lng = %s", trim($title), $lng)); 104 129 … … 111 136 'timestamp' => gmdate('d.m.Y H:i:s') 112 137 ); 138 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom plugin table; no WP API. 113 139 $wpdb->insert($table, $post_data); 114 140 // echo $wpdb->last_error; … … 118 144 * Save financial product after instalment prices update 119 145 */ 120 function save_financial_product($data, $lng = 'si') 121 { 122 global $wpdb; 123 $table = $wpdb->prefix . 'leanpay_cene_tmp_2022'; 146 function leanpay_save_financial_product($data, $lng = 'si') 147 { 148 global $wpdb; 149 $table = leanpay_get_prices_table(); 150 if ( $table === null ) { 151 return; 152 } 124 153 $lng = sanitize_text_field($lng); 125 154 $data = sanitize_textarea_field($data); … … 133 162 'timestamp' => gmdate('d.m.Y H:i:s') 134 163 ); 164 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Custom plugin table; no WP API. 135 165 $wpdb->insert($table, $post_data); 136 166 // echo $wpdb->last_error; … … 140 170 * Get prices from Leanpay and return to function 141 171 */ 142 function call_leanpay($lng = 'si') 143 { 144 $settings = new WC_Leanpay(); 145 ini_set('memory_limit', '2048M'); 146 172 function leanpay_call_leanpay($lng = 'si') 173 { 174 $settings = new Leanpay_Gateway(); 147 175 148 176 $environment = "app"; … … 175 203 176 204 $response_body = wp_remote_retrieve_body($response); 205 206 $original_memory_limit = ini_get('memory_limit'); 207 wp_raise_memory_limit( 'admin' ); 177 208 $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 178 212 return $result; 179 213 } … … 182 216 * Get all financial products from database (based on language; default language is Slovenian) 183 217 */ 184 function get_financial_product($lng) 185 { 186 global $wpdb; 187 $table = $wpdb->prefix . 'leanpay_cene_tmp_2022'; 188 $table = esc_sql($table); 218 function leanpay_get_financial_product($lng) 219 { 220 global $wpdb; 221 $table = leanpay_get_prices_table(); 222 if ( $table === null ) { 223 return null; 224 } 189 225 $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(). 190 227 $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); 191 228 foreach ($result as $instance) … … 196 233 * Get Leanpay installment plans based on selected financial product from database - TO DO (financial product ID) 197 234 */ 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); 235 function 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 } 206 244 $financial_product = sanitize_text_field($settings->financial_product); 207 245 $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(). 208 247 $result = $wpdb->get_var($wpdb->prepare("SELECT content FROM `{$table}` WHERE title = %s AND lng = %s LIMIT 1", $financial_product, $market_endpoint)); 209 248 … … 214 253 * Send delivery confirmation and get verification document 215 254 */ 216 function delivery_verification_confirmation($apiKey, $market_endpoint, $environment, $api_url, $order_id)255 function leanpay_delivery_verification_confirmation($apiKey, $market_endpoint, $environment, $api_url, $order_id) 217 256 { 218 257 $apiKey = sanitize_text_field($apiKey); … … 277 316 278 317 279 function l p_headersToArray( $str )318 function leanpay_headers_to_array( $str ) 280 319 { 281 320 $headers = array(); -
wc-leanpay/trunk/includes/leanpay_globals.php
r3492394 r3492436 8 8 * Required minimums and constants 9 9 */ 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__))));10 define('LEANPAY_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__DIR__))); 11 define('LEANPAY_VERSION', '6.0.3'); // WRCS: DEFINED_VERSION. Must match Plugin Version in main file header. 12 define('LEANPAY_MIN_PHP_VER', '1.0.0'); 13 define('LEANPAY_MIN_WC_VER', '5.9'); 14 define('LEANPAY_FUTURE_MIN_WC_VER', '6.0'); 15 define('LEANPAY_MAIN_FILE', __FILE__); 16 define('LEANPAY_ABSPATH', __DIR__ . '/'); 17 define('LEANPAY_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)) , basename(__FILE__)))); 18 18 19 19 /** … … 22 22 * Products above this price will show regular interest messaging 23 23 */ 24 define(' WC_LEANPAY_PRICE_THRESHOLD', 300);24 define('LEANPAY_PRICE_THRESHOLD', 300); 25 25 26 26 ?> -
wc-leanpay/trunk/includes/leanpay_payment_confirmation.php
r3492394 r3492436 1 1 <?php 2 require_once ('../../../../wp-load.php'); 2 if ( ! defined( 'ABSPATH' ) ) { 3 require_once '../../../../wp-load.php'; 4 } 3 5 4 if ( !defined('ABSPATH')) {6 if ( ! defined( 'ABSPATH' ) ) { 5 7 exit; 6 8 } 7 $ settings = new WC_Leanpay();9 $leanpay_settings = new Leanpay_Gateway(); 8 10 9 11 if (!isset($_GET['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['nonce'])), 'order_id_' . (isset($_GET["orderId"]) ? absint($_GET["orderId"]) : 0))) { … … 12 14 13 15 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; 17 if (empty($leanpay_order_id)) { 16 18 wp_die(esc_html__('Invalid order ID', 'wc-leanpay')); 17 19 } 18 $order = wc_get_order($ order_id);20 $order = wc_get_order($leanpay_order_id); 19 21 if (!$order) { 20 22 wp_die(esc_html__('Order not found', 'wc-leanpay')); 21 23 } 22 24 23 $l ink_checkout = $link_token = "";24 $ environment = "app";25 $leanpay_link_checkout = $leanpay_link_token = ""; 26 $leanpay_environment = "app"; 25 27 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';28 if( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( ( $leanpay_settings->market_endpoint == 'ro' ) || ( $leanpay_settings->market_endpoint == 'hu' ) ) ) 29 $leanpay_environment = 'test-app'; 30 elseif( ( $leanpay_settings->sandbox_mode == 'yes' ) && ( $leanpay_settings->market_endpoint == 'si' ) ) 31 $leanpay_environment = 'stage-app'; 30 32 31 $ market_endpoint_safe = sanitize_text_field($settings->market_endpoint);32 $l ink_checkout = "https://" . esc_attr($environment) . ".leanpay." . esc_attr($market_endpoint_safe) . "/vendor/checkout";33 $l ink_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"; 34 36 35 $ cart_items = array();37 $leanpay_cart_items = array(); 36 38 37 39 foreach (WC() 38 40 ->cart 39 ->get_cart() as $ cart_item)41 ->get_cart() as $leanpay_cart_item) 40 42 { 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'] 47 49 )); 48 50 } … … 51 53 ?> 52 54 53 <form method="post" id="leanpay_html_form" action="<?php echo esc_url($l ink_checkout); ?>">55 <form method="post" id="leanpay_html_form" action="<?php echo esc_url($leanpay_link_checkout); ?>"> 54 56 55 57 <?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)) 57 59 ? $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)) 60 62 ? wc_get_checkout_url() 61 : esc_url_raw($ settings->failure_url);63 : esc_url_raw($leanpay_settings->failure_url); 62 64 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() , 66 68 'amount' => floatval($order->get_total()) , 67 'successUrl' => $ success_url,68 'errorUrl' => $ error_url,69 'successUrl' => $leanpay_success_url, 70 'errorUrl' => $leanpay_error_url, 69 71 'vendorPhoneNumber' => sanitize_text_field($order->get_billing_phone()) , 70 72 'vendorFirstName' => sanitize_text_field($order->get_billing_first_name()) , … … 73 75 'vendorZip' => sanitize_text_field($order->get_billing_postcode()) , 74 76 'vendorCity' => sanitize_text_field($order->get_billing_city()) , 75 'language' => sanitize_text_field($ settings->market_endpoint),76 'CartItems' => $ cart_items77 'language' => sanitize_text_field($leanpay_settings->market_endpoint), 78 'CartItems' => $leanpay_cart_items 77 79 ); 78 80 79 $ data_json = wp_json_encode($data);81 $leanpay_data_json = wp_json_encode($leanpay_data); 80 82 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, 83 85 'headers' => array( 84 86 'Content-Type' => 'application/json', … … 89 91 )); 90 92 91 if (is_wp_error($ response)) {92 echo esc_html("Error: " . $ response->get_error_message());93 $ result = array();93 if (is_wp_error($leanpay_response)) { 94 echo esc_html("Error: " . $leanpay_response->get_error_message()); 95 $leanpay_result = array(); 94 96 } 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); 97 99 } 98 100 99 101 ?> 100 102 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']) : ''; ?>" /> 102 104 <input type="submit" value="Buy with Leanpay" style="display:none;"> 103 105 104 106 </form> 105 <script> 106 document.getElementById("leanpay_html_form").submit(); 107 </script> 107 <?php 108 wp_register_script( 'leanpay-form-submit', false, [], ( defined( 'LEANPAY_VERSION' ) ? LEANPAY_VERSION : '1.0' ), true ); 109 wp_add_inline_script( 'leanpay-form-submit', 'document.getElementById("leanpay_html_form").submit();' ); 110 wp_enqueue_script( 'leanpay-form-submit' ); 111 wp_print_scripts( 'leanpay-form-submit' ); 112 ?> 108 113 </body> 109 114 </html> -
wc-leanpay/trunk/languages/wc-leanpay-hr.po
r3492394 r3492436 13 13 "Plural-Forms: nplurals=2; plural=(n != 1);\n" 14 14 "X-Generator: Loco https://localise.biz/\n" 15 "X-Domain: leanpay-obrocne-cene\n"15 "X-Domain: wc-leanpay\n" 16 16 "POT-Creation-Date: 2025-10-28 09:08+0000\n" 17 17 "X-Loco-Version: 2.8.0; wp-6.8.3; php-8.3.7" -
wc-leanpay/trunk/status.php
r3492394 r3492436 1 1 <?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. 4 if ( ! defined( 'ABSPATH' ) ) { 5 exit; 7 6 } 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 data17 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 amount47 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 status55 $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 else84 {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 else100 {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 else116 {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 else132 {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 else148 {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 else157 {158 status_header(400);159 echo esc_html("No input found");160 }161 -
wc-leanpay/trunk/wc-leanpay.php
r3492394 r3492436 7 7 * Author: Leanpay 8 8 * Author URI: https://leanpay.com 9 * Version: 6.0. 29 * Version: 6.0.3 10 10 * Text Domain: wc-leanpay 11 11 * 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 13 14 * License: GPL-2.0+ 15 * Requires Plugins: woocommerce 14 16 */ 15 17 … … 22 24 23 25 use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; 26 27 add_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 47 function 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 } 24 130 25 131 add_action( 'before_woocommerce_init', function() { … … 39 145 function leanpay_add_gateway_class($gateways) 40 146 { 41 // $gateways[] = ' WC_Leanpay'; // your class name is here42 array_unshift($gateways, " WC_Leanpay");147 // $gateways[] = 'Leanpay_Gateway'; // your class name is here 148 array_unshift($gateways, "Leanpay_Gateway"); 43 149 44 150 return $gateways; … … 46 152 47 153 // Render callback for horizontal block 48 function wc_leanpay_render_horizontal($attrs){154 function leanpay_render_horizontal($attrs){ 49 155 $price = isset($attrs['price']) ? esc_html($attrs['price']) : '10 EUR'; 50 156 ob_start(); … … 64 170 65 171 // Render callback for horizontal block 66 function wc_leanpay_render_vertical($attrs){172 function leanpay_render_vertical($attrs){ 67 173 $price = isset($attrs['price']) ? esc_html($attrs['price']) : '10 EUR'; 68 174 ob_start(); … … 84 190 add_action('init', function(){ 85 191 register_block_type(__DIR__.'/blocks/horizontal', [ 86 'render_callback' => ' wc_leanpay_render_horizontal'192 'render_callback' => 'leanpay_render_horizontal' 87 193 ]); 88 194 register_block_type(__DIR__.'/blocks/vertical', [ 89 'render_callback' => ' wc_leanpay_render_vertical'195 'render_callback' => 'leanpay_render_vertical' 90 196 ]); 91 197 }); … … 124 230 $args = null 125 231 ) { 126 $settings = new WC_Leanpay();232 $settings = new Leanpay_Gateway(); 127 233 if ( 128 234 $settings->enabled != "no" && … … 130 236 $settings->on_catalog_pages == "yes" 131 237 ) { 132 $before = show_leanpay_on_archive_page();238 $before = leanpay_show_on_archive_page(); 133 239 return $before . $add_to_cart_html; 134 240 } … … 166 272 167 273 function leanpay_get_banners() { 168 require_once ABSPATH . "wp-admin/includes/file.php";169 274 $images = glob(plugin_dir_path(__FILE__) ."images/banners/*.png"); 170 275 foreach( $images as $image ): … … 175 280 function leanpay_upload_banner_on_activation($image_abs_url) 176 281 { 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 } 178 285 179 286 $image_url = plugin_dir_url(__FILE__) . "images/banners/".basename($image_abs_url); … … 213 320 } 214 321 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 } 216 325 217 326 wp_update_attachment_metadata( … … 276 385 } 277 386 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 287 394 { 288 395 public $API_id; … … 321 428 public $wc_leanpay_price_color; 322 429 public $wc_leanpay_action_color; 323 public $custom_css;324 430 public $is_rendered = false; 325 431 … … 352 458 $this->API_secret = $this->sandbox_mode == "yes" ? $this->get_option("sandbox_API_secret") : $this->get_option("API_secret"); 353 459 //$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'); 356 462 $this->info_page_url = $this->get_option("info_page_url"); 357 463 $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 } 365 476 } 366 477 … … 404 515 $this->success_url_checkbox = $this->get_option("success_url_checkbox"); 405 516 $this->failure_url_checkbox = $this->get_option("failure_url_checkbox"); 406 $this->custom_css = $this->get_option("custom_css");407 517 408 518 … … 441 551 // Replace 'my-script-handle' with the handle of the script that needs params. 442 552 // 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 ); 445 555 } 446 556 … … 497 607 498 608 wp_register_script( 499 " admin_js",609 "leanpay-admin-js", 500 610 plugin_dir_url(__FILE__) . "assets/js/admin.js", 501 611 ["jquery"], 502 "2.0.2" 612 LEANPAY_VERSION, 613 false 503 614 ); 504 wp_enqueue_script(" admin_js");615 wp_enqueue_script("leanpay-admin-js"); 505 616 506 617 wp_register_style( 507 " admin_css",618 "leanpay-admin-css", 508 619 plugin_dir_url(__FILE__) . "assets/css/admin.css", 509 620 false, 510 "2.0.2"621 LEANPAY_VERSION 511 622 ); 512 wp_enqueue_style(" admin_css");623 wp_enqueue_style("leanpay-admin-css"); 513 624 } 514 625 … … 573 684 plugin_dir_url(__FILE__) . "assets/css/style.css", 574 685 false, 575 "2.0.2"686 LEANPAY_VERSION 576 687 ); 577 688 578 689 wp_enqueue_style("leanpay_cene_css"); 579 690 wp_enqueue_style("leanpay_slider_css"); 580 581 // Add custom CSS if provided582 if (!empty($this->custom_css)) {583 wp_add_inline_style("leanpay_cene_css", wp_strip_all_tags($this->custom_css));584 }585 691 586 692 wp_enqueue_script( … … 599 705 true 600 706 ); 601 wp_localize_script("leanpay_variations_js", " myAjax", [707 wp_localize_script("leanpay_variations_js", "leanpayAjax", [ 602 708 "ajaxurl" => admin_url("admin-ajax.php"), 603 709 ]); … … 658 764 function checkout_generate_title() 659 765 { 660 $prices = show_leanpay_on_checkout();766 $prices = leanpay_show_on_checkout(); 661 767 if ($prices == "") { 662 768 return [$prices, true]; … … 674 780 if ($this->API_id == "") { 675 781 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")); 677 783 }); 678 784 return; 679 785 } 680 786 681 if (!wp_next_scheduled(" update_installment_plans_action")) {787 if (!wp_next_scheduled("leanpay_update_plans_action")) { 682 788 wp_schedule_event( 683 789 strtotime(gmdate("H:i", strtotime($this->update_schedule))), 684 790 "daily", 685 " update_installment_plans_action"791 "leanpay_update_plans_action" 686 792 ); 687 793 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")); 689 795 }); 690 796 } … … 701 807 $current_panel = empty($_REQUEST["section"]) 702 808 ? "" 703 : sanitize_text_field(urldecode($_REQUEST["section"])); 809 : sanitize_text_field(wp_unslash($_REQUEST["section"])); 810 704 811 if ( 705 812 isset($_POST["leanpay_manual_update"]) && 706 813 $current_panel == "wc_leanpay_module" 707 814 ) { 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 708 826 if ($this->API_id == "") { 709 827 add_action("admin_notices", function() { 710 admin_notices_message("Warning: enter API ID");828 leanpay_admin_notices_message("Warning: enter API ID"); 711 829 }); 712 830 return; 713 831 } 714 832 715 if ( !wp_next_scheduled("manual_ update_installment_plans_action") ) {833 if ( !wp_next_scheduled("manual_leanpay_update_plans_action") ) { 716 834 wp_schedule_single_event( 717 835 time() + 10, 718 "manual_ update_installment_plans_action"836 "manual_leanpay_update_plans_action" 719 837 ); 720 838 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"); 722 840 }); 723 841 } … … 755 873 $data["title"] 756 874 ); ?></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§ion=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" /> 759 878 <?php echo esc_html(submit_button( 760 879 __("Update product prices", "wc-leanpay") 761 880 )); ?> 762 <input type="hidden" name="leanpay_manual_update" value="all" /> 763 </form> 881 </form> 764 882 <?php echo esc_html($this->get_description_html($data)); ?> 765 883 </fieldset> … … 784 902 add_action("admin_notices", function() use ($amount) { 785 903 // 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)); 787 905 }); 788 906 return $amount; … … 805 923 add_action("admin_notices", function() use ($amount) { 806 924 // 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)); 808 926 }); 809 927 return $amount; … … 844 962 add_filter( 845 963 'woocommerce_available_payment_gateways', 846 ' change_leanpay_payment_gateway_description',964 'leanpay_change_payment_gateway_description', 847 965 10, 848 966 1 849 967 ); 850 968 851 function change_leanpay_payment_gateway_description( $gateways ) {969 function leanpay_change_payment_gateway_description( $gateways ) { 852 970 853 971 if ( ! isset( $gateways['wc_leanpay_module'] ) ) { … … 857 975 return $gateways; 858 976 } 859 $html = show_leanpay_on_checkout();977 $html = leanpay_show_on_checkout(); 860 978 $gateways['wc_leanpay_module']->description = $html . $gateways['wc_leanpay_module']->description; 861 979 $gateways['wc_leanpay_module']->is_rendered = true; … … 869 987 */ 870 988 add_action( 871 " update_installment_plans_action",872 " update_installment_plans_function"989 "leanpay_update_plans_action", 990 "leanpay_update_installment_plans_function" 873 991 ); 874 992 add_action( 875 "manual_ update_installment_plans_action",876 " update_installment_plans_function"993 "manual_leanpay_update_plans_action", 994 "leanpay_update_installment_plans_function" 877 995 ); 878 function update_installment_plans_function()996 function leanpay_update_installment_plans_function() 879 997 { 880 998 require_once plugin_dir_path(__FILE__) . 881 999 "/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"); 886 1004 887 1005 /** 888 1006 * Product page Leanpay calculation 889 1007 */ 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())1008 add_action("woocommerce_simple_add_to_cart", "leanpay_product_page_calculation"); 1009 add_action("woocommerce_variable_add_to_cart", "leanpay_product_page_calculation"); 1010 add_action("woocommerce_grouped_add_to_cart", "leanpay_product_page_calculation"); 1011 1012 add_shortcode('leanpay_product_page', 'leanpay_product_page_calculation'); 1013 1014 function leanpay_product_page_calculation($atts = array(), $content = null, $tag = null) 897 1015 { 898 1016 require_once plugin_dir_path(__FILE__) . 899 1017 "/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 1022 function leanpay_product_page_calculation2() 905 1023 { 906 1024 require_once plugin_dir_path(__FILE__) . 907 1025 "/includes/leanpay_frontend_display.php"; 908 echo wp_kses_post( show_leanpay_on_checkout());1026 echo wp_kses_post(leanpay_show_on_checkout()); 909 1027 exit(); 910 1028 } 911 add_action("wp_ajax_get_leanpay_calculator", " product_page_calculation2");912 add_action("wp_ajax_nopriv_get_leanpay_calculator", " product_page_calculation2");1029 add_action("wp_ajax_get_leanpay_calculator", "leanpay_product_page_calculation2"); 1030 add_action("wp_ajax_nopriv_get_leanpay_calculator", "leanpay_product_page_calculation2"); 913 1031 914 1032 /** … … 917 1035 add_action( 918 1036 "woocommerce_sections_checkout", 919 " action_woocommerce_sections_my_custom_tab",1037 "leanpay_action_woocommerce_sections_my_custom_tab", 920 1038 10 921 1039 ); 922 function action_woocommerce_sections_my_custom_tab()1040 function leanpay_action_woocommerce_sections_my_custom_tab() 923 1041 { 924 1042 global $current_section; 925 $settings = new WC_Leanpay();1043 $settings = new Leanpay_Gateway(); 926 1044 927 1045 $tab_name = "checkout"; … … 932 1050 "payment-configuration" => __("Payment Configuration", "wc-leanpay"), 933 1051 "settings" => __("Settings", "wc-leanpay"), 934 "advanced" => __("Advanced", "wc-leanpay"),935 1052 ]; 936 1053 … … 950 1067 $settings->market_endpoint 951 1068 ); 1069 $url = wp_nonce_url( $url, 'leanpay_settings_panel' ); 952 1070 $class = $current_section === $id ? "current" : ""; 953 1071 $separator = end($array_keys) === $id ? "" : "|"; 954 1072 $text = esc_html($label); 955 echo "<li><a href=' $url' class='$class'>$text</a> $separator </li>"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped1073 echo "<li><a href='" . esc_url( $url ) . "' class='" . esc_attr( $class ) . "'>" . esc_html( $text ) . "</a> " . esc_html( $separator ) . " </li>"; 956 1074 } 957 1075 echo '</ul><br class="clear leanpay" />'; … … 966 1084 add_filter( 967 1085 "plugin_action_links_" . plugin_basename(__FILE__), 968 "l p_plugin_action_links"1086 "leanpay_plugin_action_links" 969 1087 ); 970 function l p_plugin_action_links($links)1088 function leanpay_plugin_action_links($links) 971 1089 { 972 1090 $plugin_links = [ … … 988 1106 { 989 1107 wp_register_script( 990 " admin_meta_box_js",1108 "leanpay-admin-meta-box-js", 991 1109 plugin_dir_url(__FILE__) . "assets/js/admin_meta_box.js", 992 1110 ["jquery"], 993 "2.0.2" 1111 LEANPAY_VERSION, 1112 false 994 1113 ); 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", [ 997 1116 "ajaxurl" => admin_url("admin-ajax.php"), 998 1117 ]); … … 1025 1144 echo "<p>" . esc_html($order->get_meta("leanpay_order_status", true)) . "</p>"; 1026 1145 echo "</div></li></ul>"; 1027 add_button_transaction_delivery();1146 leanpay_add_button_transaction_delivery(); 1028 1147 } 1029 1148 else { … … 1036 1155 * Add button inside meta box for transaction delivery on admin order details page 1037 1156 */ 1038 if (!function_exists(" add_button_transaction_delivery")) {1039 function add_button_transaction_delivery()1157 if (!function_exists("leanpay_add_button_transaction_delivery")) { 1158 function leanpay_add_button_transaction_delivery() 1040 1159 { 1041 1160 $order = wc_get_order(get_the_ID()); … … 1095 1214 require_once plugin_dir_path(__FILE__) . 1096 1215 "/includes/leanpay_get_update_data.php"; 1097 $settings = new WC_Leanpay();1216 $settings = new Leanpay_Gateway(); 1098 1217 1099 1218 $environment = "app"; … … 1110 1229 } 1111 1230 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); 1113 1232 wp_die(); 1114 1233 } … … 1132 1251 require_once plugin_dir_path(__FILE__) . 1133 1252 "/includes/leanpay_get_update_data.php"; 1134 $settings = new WC_Leanpay();1253 $settings = new Leanpay_Gateway(); 1135 1254 $environment = "app"; 1136 1255 … … 1146 1265 } 1147 1266 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); 1149 1268 wp_die(); 1150 1269 } … … 1154 1273 */ 1155 1274 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()1275 add_action("wp_ajax_get_leanpay_variation", "leanpay_get_variation"); 1276 add_action("wp_ajax_nopriv_get_leanpay_variation", "leanpay_get_variation"); 1277 function leanpay_get_variation() 1159 1278 { 1160 1279 // Verify nonce for AJAX request (optional for non-logged-in users, but recommended) … … 1173 1292 $price = floatval($price); 1174 1293 1175 echo esc_html( show_leanpay_on_product_page("", "", "variation", $price));1294 echo esc_html(leanpay_show_on_product_page("", "", "variation", $price)); 1176 1295 die(); 1177 1296 } … … 1180 1299 * Admin notice for manual instalment plan update error 1181 1300 */ 1182 function admin_notices_message($message,$type = 'error')1301 function leanpay_admin_notices_message($message,$type = 'error') 1183 1302 { 1184 1303 global $current_screen; … … 1193 1312 return; 1194 1313 1195 class WC_Leanpay_Blocksextends AbstractPaymentMethodType1314 class Leanpay_Blocks_Integration extends AbstractPaymentMethodType 1196 1315 { 1197 1316 private $gateway; … … 1200 1319 public function initialize() 1201 1320 { 1202 $this->gateway = new WC_Leanpay();1321 $this->gateway = new Leanpay_Gateway(); 1203 1322 } 1204 1323 … … 1220 1339 'wp-i18n', 1221 1340 ], 1222 null,1341 LEANPAY_VERSION, 1223 1342 true 1224 1343 ); 1344 1345 wp_localize_script( 'leanpay-blocks-integration', 'leanpayBlocksData', [ 1346 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 1347 ] ); 1225 1348 1226 1349 if( function_exists( 'wp_set_script_translations' ) ) … … 1240 1363 1241 1364 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 ); 1243 1366 } ); 1244 1367 }
Note: See TracChangeset
for help on using the changeset viewer.