Plugin Directory

Changeset 3272390


Ignore:
Timestamp:
04/14/2025 12:26:58 PM (11 months ago)
Author:
imoje
Message:

v4.8.2

Location:
imoje/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • imoje/trunk/assets/js/imoje-gateway.js

    r3205609 r3272390  
    11(function ($) {
    22
    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';
    1111
    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;
     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;
    1616
    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);
    2121
    22     $body.on('click', '.imoje-channels li.imoje-channel label', function () {
     22    $body.on('click', '.imoje-channels li.imoje-channel label', function () {
    2323
    24         var $that = $(this);
    25         $('.imoje-channels label').removeClass(imoje_active);
     24        var $that = $(this);
     25        $('.imoje-channels label').removeClass(imoje_active);
    2626
    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    });
    3434
    35     $body.on('click', '.imoje-channels .imoje-channel', function () {
     35    $body.on('click', '.imoje-channels .imoje-channel', function () {
    3636
    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        }
    4040
    41         $('.pbl-error').slideUp(imoje_ms_speed_animation);
    42     });
     41        $('.pbl-error').slideUp(imoje_ms_speed_animation);
     42    });
    4343
    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;
    4747
    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        }
    5151
    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        }
    5757
    58         return validate_result;
    59     });
     58        return validate_result;
     59    });
    6060
    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    });
    7373
    74     function validate_channels($payment_method) {
     74    function validate_channels($payment_method) {
    7575
    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);
    7878
    79             return true;
    80         } else {
     79            return true;
     80        } else {
    8181
    82             $('html, body').animate({
    83                 scrollTop: $payment_method.offset().top
    84             }, 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);
    8686
    87             return false;
    88         }
    89     }
     87            return false;
     88        }
     89    }
    9090
    91     function validate_blik() {
     91    function validate_blik() {
    9292
    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        }
    9696
    97         var $input_imoje_blik_code = $('input[name="imoje-blik-code"]');
     97        var $input_imoje_blik_code = $('input[name="imoje-blik-code"]');
    9898
    99         if ($input_imoje_blik_code.length < 1) {
    100             return false;
    101         }
     99        if ($input_imoje_blik_code.length < 1) {
     100            return false;
     101        }
    102102
    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        }
    107107
    108         return true;
     108        return true;
    109109
    110     }
     110    }
    111111
    112     function show_installments_widget() {
     112    function show_installments_widget() {
    113113
    114         if (imoje_is_rendered_installments) {
    115             return;
    116         }
     114        if (imoje_is_rendered_installments) {
     115            return;
     116        }
    117117
    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');
    120120
    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);
    129129
    130             return;
    131         }
     130            return;
     131        }
    132132
    133         var installmentsData = $wraper.data();
     133        var installmentsData = $wraper.data();
    134134
    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         )
     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        )
    143143
    144         imoje_is_rendered_installments = true;
     144        imoje_is_rendered_installments = true;
     145    }
    145146
    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    });
    155152
    156153})(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  
    7777     */
    7878    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
    7994        $installments = $this->get_installments_instance();
    8095
    8196        $installments_data = $installments->getData(
    82             WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax(),
     97            $total,
    8398            get_woocommerce_currency()
    8499        );
  • imoje/trunk/includes/gateway/WC_Gateway_Imoje_Api_Abstract.php

    r3268688 r3272390  
    217217        }
    218218
    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        }
    220238
    221239        $pm_blik = Util::getPaymentMethod( 'blik' );
     
    229247                     && ! $this->imoje_api->verifyTransactionLimits(
    230248                        $payment_method['transactionLimits'],
    231                         $cart_total ) ) {
     249                        $total ) ) {
    232250
    233251                    $this->render_unavailable_template(
    234252                        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 )
    236254                        ) );
    237255
     
    258276            }
    259277
    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 );
    264281
    265282                continue;
    266283            }
    267284
    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 );
    269286        }
    270287
     
    357374        }
    358375
    359         if($add_currency) {
     376        if ( $add_currency ) {
    360377            $array['currency'] = $payment_method['currency'];
    361378        }
     
    384401        $formSelectedChannel = $_POST['imoje-selected-channel'];
    385402
    386         if (static::PAYMENT_METHOD_NAME == WC_Gateway_ImojeInstallments::PAYMENT_METHOD_NAME){
     403        if ( static::PAYMENT_METHOD_NAME == WC_Gateway_ImojeInstallments::PAYMENT_METHOD_NAME ) {
    387404            $formSelectedChannel = $_POST['imoje-selected-channel-installments'];
    388 
    389405        }
    390406
     
    471487     * @return array
    472488     */
    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 );
    476491    }
    477492
     
    481496     * @return array
    482497     */
    483     protected function prepare_payment_methods_block_checkout( $payment_method_name ){
     498    protected function prepare_payment_methods_block_checkout( $payment_method_name ) {
    484499        $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 );
    494508        $imoje_service = $this->get_service_active();
    495509
    496         if (!isset($imoje_service['paymentMethods']) || !is_array($imoje_service['paymentMethods'])) {
     510        if ( ! isset( $imoje_service['paymentMethods'] ) || ! is_array( $imoje_service['paymentMethods'] ) ) {
    497511            return [];
    498512        }
    499513
    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_name
    503                 && 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        } );
    506520
    507521        $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 );
    510524        }
    511525
    512526        return $prepared_methods;
    513527    }
    514  }
     528}
  • imoje/trunk/readme.txt

    r3269477 r3272390  
    55Requires PHP: 5.6.0
    66License: GPLv2
    7 Stable tag: 4.8.1
     7Stable tag: 4.8.2
    88
    99Add payment via imoje to WooCommerce
     
    7373
    7474== Changelog ==
     75= 4.8.2 =
     76* fixed an issue with repayment of unpaid orders
    7577= 4.8.1 =
    7678* minor fixes for WooCommerce block checkout
  • imoje/trunk/woocommerce-imoje.php

    r3269477 r3272390  
    44Plugin URI: https://imoje.pl
    55Description: Add payment via imoje to WooCommerce
    6 Version: 4.8.1
     6Version: 4.8.2
    77Author: imoje <kontakt.tech@imoje.pl>
    88Author URI: https://imoje.pl
Note: See TracChangeset for help on using the changeset viewer.