Changeset 3272390
- Timestamp:
- 04/14/2025 12:26:58 PM (11 months ago)
- Location:
- imoje/trunk
- Files:
-
- 6 edited
-
assets/js/imoje-gateway.js (modified) (1 diff)
-
assets/js/imoje-gateway.min.js (modified) (1 diff)
-
includes/gateway/WC_Gateway_ImojeInstallments.php (modified) (1 diff)
-
includes/gateway/WC_Gateway_Imoje_Api_Abstract.php (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
-
woocommerce-imoje.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
imoje/trunk/assets/js/imoje-gateway.js
r3205609 r3272390 1 1 (function ($) { 2 2 3 var $form = $('form.checkout'),4 $body = $('body'),5 imoje_active = 'imoje-active',6 imoje_c_active = 'imoje-c-active',7 imoje_ms_speed_animation = 250,8 imoje_is_rendered_installments = false,9 imoje_is_passed_installments = false,10 imoje_installments_payment_method = 'imoje_installments';3 var $form = $('form.checkout'), 4 $body = $('body'), 5 imoje_active = 'imoje-active', 6 imoje_c_active = 'imoje-c-active', 7 imoje_ms_speed_animation = 250, 8 imoje_is_rendered_installments = false, 9 imoje_is_passed_installments = false, 10 imoje_installments_payment_method = 'imoje_installments'; 11 11 12 // catch an installment message13 window.addEventListener('message', function (data) {14 if (data.data?.channel && data.data.period) {15 imoje_is_passed_installments = true;12 // catch an installment message 13 window.addEventListener('message', function (data) { 14 if (data.data?.channel && data.data.period) { 15 imoje_is_passed_installments = true; 16 16 17 $('#imoje-selected-channel-installments').val(imoje_installments_payment_method + '-' + data.data.channel)18 $('#imoje-installments-period').val(data.data.period)19 }20 }, false);17 $('#imoje-selected-channel-installments').val(imoje_installments_payment_method + '-' + data.data.channel) 18 $('#imoje-installments-period').val(data.data.period) 19 } 20 }, false); 21 21 22 $body.on('click', '.imoje-channels li.imoje-channel label', function () {22 $body.on('click', '.imoje-channels li.imoje-channel label', function () { 23 23 24 var $that = $(this);25 $('.imoje-channels label').removeClass(imoje_active);24 var $that = $(this); 25 $('.imoje-channels label').removeClass(imoje_active); 26 26 27 if ($that.parent().attr('class').includes('imoje_twisto')) {28 $('.imoje-twisto-regulations').show();29 }30 if ($that.hasClass(imoje_c_active)) {31 $that.addClass(imoje_active);32 }33 });27 if ($that.parent().attr('class').includes('imoje_twisto')) { 28 $('.imoje-twisto-regulations').show(); 29 } 30 if ($that.hasClass(imoje_c_active)) { 31 $that.addClass(imoje_active); 32 } 33 }); 34 34 35 $body.on('click', '.imoje-channels .imoje-channel', function () {35 $body.on('click', '.imoje-channels .imoje-channel', function () { 36 36 37 if (!$(this).attr('class').includes('imoje_twisto') && !$(this).attr('class').includes('imoje-c-no-active')) {38 $('.imoje-twisto-regulations').hide();39 }37 if (!$(this).attr('class').includes('imoje_twisto') && !$(this).attr('class').includes('imoje-c-no-active')) { 38 $('.imoje-twisto-regulations').hide(); 39 } 40 40 41 $('.pbl-error').slideUp(imoje_ms_speed_animation);42 });41 $('.pbl-error').slideUp(imoje_ms_speed_animation); 42 }); 43 43 44 $('form#order_review').on('submit', function (e) {45 var payment_method = $(this).find('input[name="payment_method"]:checked').val(),46 validate_result = true;44 $('form#order_review').on('submit', function (e) { 45 var payment_method = $(this).find('input[name="payment_method"]:checked').val(), 46 validate_result = true; 47 47 48 if (['imoje_pbl', 'imoje_blik', 'imoje_paylater'].includes(payment_method)) {49 validate_result = validate_channels();50 }48 if (['imoje_pbl', 'imoje_blik', 'imoje_paylater'].includes(payment_method)) { 49 validate_result = validate_channels(); 50 } 51 51 52 if (!validate_result) {53 setTimeout(function () {54 $(e.target).unblock();55 }, 500);56 }52 if (!validate_result) { 53 setTimeout(function () { 54 $(e.target).unblock(); 55 }, 500); 56 } 57 57 58 return validate_result;59 });58 return validate_result; 59 }); 60 60 61 $form.on('checkout_place_order_imoje_pbl', function () {62 return validate_channels($('.payment_method_imoje_pbl'));63 });64 $form.on('checkout_place_order_imoje_paylater', function () {65 return validate_channels($('.payment_method_imoje_paylater'));66 });67 $form.on('checkout_place_order_imoje_blik', function () {68 return validate_blik();69 });70 $form.on('checkout_place_order_imoje_installments', function () {71 return imoje_is_rendered_installments && imoje_is_passed_installments;72 });61 $form.on('checkout_place_order_imoje_pbl', function () { 62 return validate_channels($('.payment_method_imoje_pbl')); 63 }); 64 $form.on('checkout_place_order_imoje_paylater', function () { 65 return validate_channels($('.payment_method_imoje_paylater')); 66 }); 67 $form.on('checkout_place_order_imoje_blik', function () { 68 return validate_blik(); 69 }); 70 $form.on('checkout_place_order_imoje_installments', function () { 71 return imoje_is_rendered_installments && imoje_is_passed_installments; 72 }); 73 73 74 function validate_channels($payment_method) {74 function validate_channels($payment_method) { 75 75 76 if ($payment_method.find('.imoje-channel .imoje-active').length) {77 $('.imoje-pbl-error').slideUp(imoje_ms_speed_animation);76 if ($payment_method.find('.imoje-channel .imoje-active').length) { 77 $('.imoje-pbl-error').slideUp(imoje_ms_speed_animation); 78 78 79 return true;80 } else {79 return true; 80 } else { 81 81 82 $('html, body').animate({83 scrollTop: $payment_method.offset().top84 }, 500);85 $('.imoje-pbl-error').slideDown(imoje_ms_speed_animation);82 $('html, body').animate({ 83 scrollTop: $payment_method.offset().top 84 }, 500); 85 $('.imoje-pbl-error').slideDown(imoje_ms_speed_animation); 86 86 87 return false;88 }89 }87 return false; 88 } 89 } 90 90 91 function validate_blik() {91 function validate_blik() { 92 92 93 if ($('.imoje-blik-code-container').length < 1) {94 return validate_channels($('.payment_method_imoje_blik'));95 }93 if ($('.imoje-blik-code-container').length < 1) { 94 return validate_channels($('.payment_method_imoje_blik')); 95 } 96 96 97 var $input_imoje_blik_code = $('input[name="imoje-blik-code"]');97 var $input_imoje_blik_code = $('input[name="imoje-blik-code"]'); 98 98 99 if ($input_imoje_blik_code.length < 1) {100 return false;101 }99 if ($input_imoje_blik_code.length < 1) { 100 return false; 101 } 102 102 103 if ($input_imoje_blik_code.val().length !== 6) {104 alert(imoje_js_object.imoje_blik_tooltip)105 return false;106 }103 if ($input_imoje_blik_code.val().length !== 6) { 104 alert(imoje_js_object.imoje_blik_tooltip) 105 return false; 106 } 107 107 108 return true;108 return true; 109 109 110 }110 } 111 111 112 function show_installments_widget() {112 function show_installments_widget() { 113 113 114 if (imoje_is_rendered_installments) {115 return;116 }114 if (imoje_is_rendered_installments) { 115 return; 116 } 117 117 118 var script = document.getElementById('imoje-installments__script'),119 $wraper = $('#imoje-installments__wrapper');118 var script = document.getElementById('imoje-installments__script'), 119 $wraper = $('#imoje-installments__wrapper'); 120 120 121 if (script == null) {122 script = document.createElement('script');123 script.id = 'imoje-installments__script';124 script.src = $wraper.data('installmentsUrl');125 script.onload = () => {126 show_installments_widget();127 };128 document.body.append(script);121 if (script == null) { 122 script = document.createElement('script'); 123 script.id = 'imoje-installments__script'; 124 script.src = $wraper.data('installmentsUrl'); 125 script.onload = () => { 126 show_installments_widget(); 127 }; 128 document.body.append(script); 129 129 130 return;131 }130 return; 131 } 132 132 133 var installmentsData = $wraper.data();133 var installmentsData = $wraper.data(); 134 134 135 document.getElementById('imoje-installments__wrapper').imojeInstallments({136 amount:installmentsData.installmentsAmount,137 currency:installmentsData.installmentsCurrency,138 serviceId:installmentsData.installmentsServiceId,139 merchantId: installmentsData.installmentsMerchantId,140 signature:installmentsData.installmentsSignature141 }142 )135 document.getElementById('imoje-installments__wrapper').imojeInstallments({ 136 amount: installmentsData.installmentsAmount, 137 currency: installmentsData.installmentsCurrency, 138 serviceId: installmentsData.installmentsServiceId, 139 merchantId: installmentsData.installmentsMerchantId, 140 signature: installmentsData.installmentsSignature 141 } 142 ) 143 143 144 imoje_is_rendered_installments = true; 144 imoje_is_rendered_installments = true; 145 } 145 146 146 } 147 148 $(document.body).on('updated_checkout', function () { 149 150 if (document.getElementById('payment_method_imoje_installments') !== null) { 151 show_installments_widget(); 152 } 153 154 }); 147 $('form.woocommerce-checkout, form#order_review').on('change', 'input[name="payment_method"]', function () { 148 if ($('#payment_method_imoje_installments').is(':checked')) { 149 show_installments_widget(); 150 } 151 }); 155 152 156 153 })(jQuery); -
imoje/trunk/assets/js/imoje-gateway.min.js
r3205609 r3272390 1 !function(i){var e=i("form.checkout"),t=i("body"),n="imoje-active",o=!1,l=!1;function a(e){return e.find(".imoje-channel .imoje-active").length?(i(".imoje-pbl-error").slideUp(250),!0):(i("html, body").animate({scrollTop:e.offset().top},500),i(".imoje-pbl-error").slideDown(250),!1)}window.addEventListener("message",function(e){e.data?.channel&&e.data.period&&(l=!0,i("#imoje-selected-channel-installments").val("imoje_installments-"+e.data.channel),i("#imoje-installments-period").val(e.data.period))},!1),t.on("click",".imoje-channels li.imoje-channel label",function(){var e=i(this);i(".imoje-channels label").removeClass(n),e.parent().attr("class").includes("imoje_twisto")&&i(".imoje-twisto-regulations").show(),e.hasClass("imoje-c-active")&&e.addClass(n)}),t.on("click",".imoje-channels .imoje-channel",function(){i(this).attr("class").includes("imoje_twisto")||i(this).attr("class").includes("imoje-c-no-active")||i(".imoje-twisto-regulations").hide(),i(".pbl-error").slideUp(250)}),i("form#order_review").on("submit",function(e){var t=i(this).find('input[name="payment_method"]:checked').val(),n=!0;return(n=["imoje_pbl","imoje_blik","imoje_paylater"].includes(t)?a():n)||setTimeout(function(){i(e.target).unblock()},500),n}),e.on("checkout_place_order_imoje_pbl",function(){return a(i(".payment_method_imoje_pbl"))}),e.on("checkout_place_order_imoje_paylater",function(){return a(i(".payment_method_imoje_paylater"))}),e.on("checkout_place_order_imoje_blik",function(){if(i(".imoje-blik-code-container").length<1)return a(i(".payment_method_imoje_blik"));var e=i('input[name="imoje-blik-code"]');if(!(e.length<1)){if(6===e.val().length)return!0;alert(imoje_js_object.imoje_blik_tooltip)}return!1}),e.on("checkout_place_order_imoje_installments",function(){return o&&l}),i( document.body).on("updated_checkout",function(){null!==document.getElementById("payment_method_imoje_installments")&&!function e(){var t,n;o||(n=document.getElementById("imoje-installments__script"),t=i("#imoje-installments__wrapper"),null==n?((n=document.createElement("script")).id="imoje-installments__script",n.src=t.data("installmentsUrl"),n.onload=()=>{e()},document.body.append(n)):(n=t.data(),document.getElementById("imoje-installments__wrapper").imojeInstallments({amount:n.installmentsAmount,currency:n.installmentsCurrency,serviceId:n.installmentsServiceId,merchantId:n.installmentsMerchantId,signature:n.installmentsSignature}),o=!0))}()})}(jQuery);1 !function(i){var e=i("form.checkout"),t=i("body"),n="imoje-active",o=!1,l=!1;function a(e){return e.find(".imoje-channel .imoje-active").length?(i(".imoje-pbl-error").slideUp(250),!0):(i("html, body").animate({scrollTop:e.offset().top},500),i(".imoje-pbl-error").slideDown(250),!1)}window.addEventListener("message",function(e){e.data?.channel&&e.data.period&&(l=!0,i("#imoje-selected-channel-installments").val("imoje_installments-"+e.data.channel),i("#imoje-installments-period").val(e.data.period))},!1),t.on("click",".imoje-channels li.imoje-channel label",function(){var e=i(this);i(".imoje-channels label").removeClass(n),e.parent().attr("class").includes("imoje_twisto")&&i(".imoje-twisto-regulations").show(),e.hasClass("imoje-c-active")&&e.addClass(n)}),t.on("click",".imoje-channels .imoje-channel",function(){i(this).attr("class").includes("imoje_twisto")||i(this).attr("class").includes("imoje-c-no-active")||i(".imoje-twisto-regulations").hide(),i(".pbl-error").slideUp(250)}),i("form#order_review").on("submit",function(e){var t=i(this).find('input[name="payment_method"]:checked').val(),n=!0;return(n=["imoje_pbl","imoje_blik","imoje_paylater"].includes(t)?a():n)||setTimeout(function(){i(e.target).unblock()},500),n}),e.on("checkout_place_order_imoje_pbl",function(){return a(i(".payment_method_imoje_pbl"))}),e.on("checkout_place_order_imoje_paylater",function(){return a(i(".payment_method_imoje_paylater"))}),e.on("checkout_place_order_imoje_blik",function(){if(i(".imoje-blik-code-container").length<1)return a(i(".payment_method_imoje_blik"));var e=i('input[name="imoje-blik-code"]');if(!(e.length<1)){if(6===e.val().length)return!0;alert(imoje_js_object.imoje_blik_tooltip)}return!1}),e.on("checkout_place_order_imoje_installments",function(){return o&&l}),i("form.woocommerce-checkout, form#order_review").on("change",'input[name="payment_method"]',function(){i("#payment_method_imoje_installments").is(":checked")&&!function e(){var t,n;o||(n=document.getElementById("imoje-installments__script"),t=i("#imoje-installments__wrapper"),null==n?((n=document.createElement("script")).id="imoje-installments__script",n.src=t.data("installmentsUrl"),n.onload=()=>{e()},document.body.append(n)):(n=t.data(),document.getElementById("imoje-installments__wrapper").imojeInstallments({amount:n.installmentsAmount,currency:n.installmentsCurrency,serviceId:n.installmentsServiceId,merchantId:n.installmentsMerchantId,signature:n.installmentsSignature}),o=!0))}()})}(jQuery); -
imoje/trunk/includes/gateway/WC_Gateway_ImojeInstallments.php
r3268688 r3272390 77 77 */ 78 78 private function fetch_installments_data() { 79 80 $total = WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax(); 81 82 if ( ! $total ) { 83 84 $order_key = isset( $_GET['key'] ) 85 ? wc_clean( wp_unslash( $_GET['key'] ) ) 86 : ''; 87 $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); 88 89 if ( $order && $order->get_order_key() === $order_key ) { 90 $total = $order->get_total(); 91 } 92 } 93 79 94 $installments = $this->get_installments_instance(); 80 95 81 96 $installments_data = $installments->getData( 82 WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax(),97 $total, 83 98 get_woocommerce_currency() 84 99 ); -
imoje/trunk/includes/gateway/WC_Gateway_Imoje_Api_Abstract.php
r3268688 r3272390 217 217 } 218 218 219 $cart_total = WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax(); 219 $total = WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax(); 220 221 if ( ! $total ) { 222 223 $order_key = isset( $_GET['key'] ) 224 ? wc_clean( wp_unslash( $_GET['key'] ) ) 225 : ''; 226 $order = wc_get_order( absint( get_query_var( 'order-pay' ) ) ); 227 228 if ( $order && $order->get_order_key() === $order_key ) { 229 $total = $order->get_total(); 230 } else { 231 $this->render_unavailable_template( 232 __( 'No payment channel available. Choose another payment method.' ) 233 ); 234 235 return false; 236 } 237 } 220 238 221 239 $pm_blik = Util::getPaymentMethod( 'blik' ); … … 229 247 && ! $this->imoje_api->verifyTransactionLimits( 230 248 $payment_method['transactionLimits'], 231 $ cart_total ) ) {249 $total ) ) { 232 250 233 251 $this->render_unavailable_template( 234 252 Helper::get_tooltip_payment_channel( 235 $this->get_payment_channel_to_array( $payment_method, $ cart_total )253 $this->get_payment_channel_to_array( $payment_method, $total ) 236 254 ) ); 237 255 … … 258 276 } 259 277 260 if ( $this->imoje_api->verifyTransactionLimits( $payment_method['transactionLimits'], $cart_total ) ) { 261 262 263 $payment_method_list_online[] = $this->get_payment_channel_to_array( $payment_method, $cart_total ); 278 if ( $this->imoje_api->verifyTransactionLimits( $payment_method['transactionLimits'], $total ) ) { 279 280 $payment_method_list_online[] = $this->get_payment_channel_to_array( $payment_method, $total ); 264 281 265 282 continue; 266 283 } 267 284 268 $payment_method_list_no_online[] = $this->get_payment_channel_to_array( $payment_method, $ cart_total );285 $payment_method_list_no_online[] = $this->get_payment_channel_to_array( $payment_method, $total ); 269 286 } 270 287 … … 357 374 } 358 375 359 if ($add_currency) {376 if ( $add_currency ) { 360 377 $array['currency'] = $payment_method['currency']; 361 378 } … … 384 401 $formSelectedChannel = $_POST['imoje-selected-channel']; 385 402 386 if ( static::PAYMENT_METHOD_NAME == WC_Gateway_ImojeInstallments::PAYMENT_METHOD_NAME){403 if ( static::PAYMENT_METHOD_NAME == WC_Gateway_ImojeInstallments::PAYMENT_METHOD_NAME ) { 387 404 $formSelectedChannel = $_POST['imoje-selected-channel-installments']; 388 389 405 } 390 406 … … 471 487 * @return array 472 488 */ 473 public function get_payment_channels() 474 { 475 return $this->prepare_payment_methods_block_checkout(static::PAYMENT_METHOD_NAME); 489 public function get_payment_channels() { 490 return $this->prepare_payment_methods_block_checkout( static::PAYMENT_METHOD_NAME ); 476 491 } 477 492 … … 481 496 * @return array 482 497 */ 483 protected function prepare_payment_methods_block_checkout( $payment_method_name ) {498 protected function prepare_payment_methods_block_checkout( $payment_method_name ) { 484 499 $child_payment_method_name = static::PAYMENT_METHOD_NAME; 485 $currencies = get_option("woocommerce_{$child_payment_method_name}_settings", [])['currencies'] ?? []; 486 $cart_total = WC()->cart->get_cart_contents_total(); 487 488 if (!is_array($currencies)) { 489 $currencies = [$currencies]; 490 } 491 492 493 $currencies = array_map('strtolower', $currencies); 500 $currencies = get_option( "woocommerce_{$child_payment_method_name}_settings", [] )['currencies'] ?? []; 501 $cart_total = WC()->cart->get_cart_contents_total(); 502 503 if ( ! is_array( $currencies ) ) { 504 $currencies = [ $currencies ]; 505 } 506 507 $currencies = array_map( 'strtolower', $currencies ); 494 508 $imoje_service = $this->get_service_active(); 495 509 496 if ( !isset($imoje_service['paymentMethods']) || !is_array($imoje_service['paymentMethods'])) {510 if ( ! isset( $imoje_service['paymentMethods'] ) || ! is_array( $imoje_service['paymentMethods'] ) ) { 497 511 return []; 498 512 } 499 513 500 $filtered_methods = array_filter( $imoje_service['paymentMethods'], function ($method) use ($currencies, $payment_method_name) {501 return isset( $method['paymentMethod'])502 && $method['paymentMethod'] === $payment_method_name503 && in_array(strtolower($method['currency']), $currencies, true)504 && $method['isActive'];505 } );514 $filtered_methods = array_filter( $imoje_service['paymentMethods'], function ( $method ) use ( $currencies, $payment_method_name ) { 515 return isset( $method['paymentMethod'] ) 516 && $method['paymentMethod'] === $payment_method_name 517 && in_array( strtolower( $method['currency'] ), $currencies, true ) 518 && $method['isActive']; 519 } ); 506 520 507 521 $prepared_methods = []; 508 foreach ($filtered_methods as $key => $paymentMethod) {509 $prepared_methods[ $key] = $this->get_payment_channel_to_array($paymentMethod, $cart_total, true);522 foreach ( $filtered_methods as $key => $paymentMethod ) { 523 $prepared_methods[ $key ] = $this->get_payment_channel_to_array( $paymentMethod, $cart_total, true ); 510 524 } 511 525 512 526 return $prepared_methods; 513 527 } 514 }528 } -
imoje/trunk/readme.txt
r3269477 r3272390 5 5 Requires PHP: 5.6.0 6 6 License: GPLv2 7 Stable tag: 4.8. 17 Stable tag: 4.8.2 8 8 9 9 Add payment via imoje to WooCommerce … … 73 73 74 74 == Changelog == 75 = 4.8.2 = 76 * fixed an issue with repayment of unpaid orders 75 77 = 4.8.1 = 76 78 * minor fixes for WooCommerce block checkout -
imoje/trunk/woocommerce-imoje.php
r3269477 r3272390 4 4 Plugin URI: https://imoje.pl 5 5 Description: Add payment via imoje to WooCommerce 6 Version: 4.8. 16 Version: 4.8.2 7 7 Author: imoje <kontakt.tech@imoje.pl> 8 8 Author URI: https://imoje.pl
Note: See TracChangeset
for help on using the changeset viewer.