Plugin Directory

Changeset 3278936


Ignore:
Timestamp:
04/22/2025 10:39:05 AM (12 months ago)
Author:
SplitIt
Message:

release version 4.2.8

Location:
splitit-installment-payments
Files:
610 added
14 edited

Legend:

Unmodified
Added
Removed
  • splitit-installment-payments/trunk/CHANGELOG.md

    r3243228 r3278936  
    44-
    55
    6 ### 4.2.7
     6### 4.2.8
     7* Added the ability to configure the number of installments for On-Site Messaging
     8* Added the ability to customize the desired order status after creation
     9* Added compatibility with Phone Validator for WooCommerce plugin
     10* Added compatibility with Checkout Field Editor for WooCommerce plugin
     11* Code improvements and bug fixes
     12* Tested compatibility with WordPress version 6.8 and WooCommerce version 9.8.1
     13
     14* ### 4.2.7
    715* Code improvements and bug fixes
    816* Tested compatibility with WordPress version 6.7.2 and WooCommerce version 9.6.2
  • splitit-installment-payments/trunk/assets/css/admin.css

    r3243228 r3278936  
    17881788    color: #fff;
    17891789}
    1790 .select2-container--default .select2-selection--multiple .select2-selection__rendered li {
     1790#main_ic_container .select2-container--default .select2-selection--multiple .select2-selection__rendered li {
    17911791    margin: 6px 3px 0 0 !important;
    17921792    text-align: center;
    1793     line-height: 28px;
    1794 }
    1795 .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
     1793    line-height: 27px;
     1794}
     1795#main_ic_container .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    17961796    color: #fff !important;
    17971797    cursor: pointer;
    17981798    display: inline-block;
    17991799    font-weight: 700;
    1800     font-size: 16px;
     1800    font-size: 12px;
    18011801    margin-right: 8px !important;
    18021802    float: right;
    1803 }
    1804 .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
     1803    left: 31px !important;
     1804    top: -1px !important;
     1805}
     1806#main_ic_container .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    18051807    color: #ddd !important;
    18061808}
     
    20652067    font-weight: 400;
    20662068}
     2069
     2070.default-installments {
     2071    width: 120px !important;
     2072    height: 46px !important;
     2073}
     2074
     2075.main-section-enabled-visa-main,
     2076.main-default-installments-number-main {
     2077    justify-content: space-between;
     2078    align-items: center;
     2079}
  • splitit-installment-payments/trunk/assets/js/admin.js

    r3212118 r3278936  
    13941394        }
    13951395
     1396        let defaultInstallmentsNumber = 4;
     1397        let defaultInstallmentsInput  = $( '#woocommerce_splitit_default_installments_number' );
     1398        if (defaultInstallmentsInput.length) {
     1399            let defaultInstallments = defaultInstallmentsInput.val();
     1400            if (defaultInstallments && '' !== defaultInstallments) {
     1401                defaultInstallmentsNumber = defaultInstallments;
     1402            }
     1403        }
     1404
    13961405        $.each(
    13971406            options,
     
    14031412                        let value = Object.values( option )[0]
    14041413                        if ('position' === key) {
    1405                             value = 'top' === value ? 'bottom': 'top';
     1414                            value = 'top' === value ? 'bottom' : 'top';
    14061415                        } else if ('hide_learn_more' === key && 1 == value) {
    14071416                            value = true
     
    14121421                        if (('hide_learn_more' === key || 'hide_icon' === key) && 1 == val) {
    14131422                            val = true
     1423                        } else if ('installments' === key) {
     1424                            if (0 == val || '' === val) {
     1425                                val = defaultInstallmentsNumber;
     1426                            }
    14141427                        }
    14151428                        customOptions += key + '="' + val + '" ';
     
    14201433
    14211434        if ('logo' === type || 'one_liner' === type) {
    1422             customOptions += 'amount="1000" installments="4"';
     1435            customOptions += 'amount="1000"';
     1436            if ( ! customOptions.includes( 'installments=' ) ) {
     1437                customOptions += `installments="${defaultInstallmentsNumber}"`;
     1438            }
    14231439        }
    14241440
  • splitit-installment-payments/trunk/assets/js/splitit-blocks-um-cart.js

    r3212118 r3278936  
    2424                    let tagName      = '';
    2525                    let price        = getPrice();
    26                     let installments = getInstallmentByPrice( price, splititSettings );
     26                    let installments = getInstallmentByPrice( price, splititSettings, umSettings );
    2727
    2828                    if (umSettings.strip && 1 == umSettings.strip.enable_strip) {
     
    170170                    let previousTotal         = previousTotals ? previousTotals.total_price / 100 : null;
    171171
    172                     const unsubscribe       = subscribe(
     172                    const unsubscribe           = subscribe(
    173173                        () => {
    174                             const currentTotals = select( 'wc/store/cart' ).getCartTotals();
    175                             const currentTotal  = currentTotals ? currentTotals.total_price / 100 : null;
    176                             if (currentTotal !== previousTotal) {
    177                                 previousTotal = currentTotal;
    178                                 installments  = getInstallmentByPrice( currentTotal, splitit_settings );
    179                                 if ( ! installments) {
    180                                     $( 'spt-floating-logo, spt-one-liner' ).css( 'display', 'none' );
    181                                 } else {
    182                                     $( 'spt-floating-logo, spt-one-liner' )
    183                                     .css( 'display', '' )
    184                                     .attr( 'amount', currentTotal )
    185                                     .attr( 'installments', installments );
    186                                 }
    187 
    188                             }
     174                        const currentTotals = select( 'wc/store/cart' ).getCartTotals();
     175                        const currentTotal  = currentTotals ? currentTotals.total_price / 100 : null;
     176                        if (currentTotal !== previousTotal) {
     177                            previousTotal = currentTotal;
     178                            installments  = getInstallmentByPrice( currentTotal, splitit_settings, umSettings );
     179                            if ( ! installments) {
     180                                $( 'spt-floating-logo, spt-one-liner' ).css( 'display', 'none' );
     181                            } else {
     182                                $( 'spt-floating-logo, spt-one-liner' )
     183                                .css( 'display', '' )
     184                                .attr( 'amount', currentTotal )
     185                                .attr( 'installments', installments );
     186                            }
     187
     188                        }
    189189                        }
    190190                    );
     
    201201                }
    202202
    203                 function getInstallmentByPrice(price, settings) {
     203                function getInstallmentByPrice(price, settings, pageConfig) {
    204204                    if ('undefined' !== typeof settings.splitit_upstream_default_installments && '' !== settings.splitit_upstream_default_installments) {
    205205                        return parseInt( settings.splitit_upstream_default_installments );
     206                    }
     207
     208                    let customInstallments = checkCustomInstallmentsSettings( pageConfig, settings );
     209                    if (customInstallments !== null) {
     210                        return customInstallments;
    206211                    }
    207212
     
    219224                    }
    220225
    221                     return 3;
     226                    return 4;
     227                }
     228
     229                function checkCustomInstallmentsSettings(pageConfig, splititSettings) {
     230                    let umType = '';
     231
     232                    if (pageConfig.strip && pageConfig.strip.enable_strip == 1) {
     233                        umType = 'strip';
     234                    } else if (pageConfig.banner && pageConfig.banner.enable_banner == 1) {
     235                        umType = 'banner';
     236                    } else if (pageConfig.logo && pageConfig.logo.enable_logo == 1) {
     237                        umType = 'logo';
     238                    } else if (pageConfig.one_liner && pageConfig.one_liner.enable_one_liner == 1) {
     239                        umType = 'one_liner';
     240                    }
     241
     242                    let customInstallments = pageConfig[umType] && pageConfig[umType].installments &&
     243                    pageConfig[umType].installments.trim() !== ''
     244                        ? parseInt( pageConfig[umType].installments, 10 )
     245                        : null;
     246
     247                    let defaultInstallments = splititSettings.default_installments_number &&
     248                    splititSettings.default_installments_number.trim() !== ''
     249                        ? parseInt( splititSettings.default_installments_number, 10 )
     250                        : null;
     251
     252                    return customInstallments !== null ? customInstallments : defaultInstallments;
    222253                }
    223254
  • splitit-installment-payments/trunk/assets/js/splitit-blocks-um-checkout.js

    r3212118 r3278936  
    2424                    let tagName      = '';
    2525                    let price        = getPrice();
    26                     let installments = getInstallmentByPrice( price, splititSettings );
     26                    let installments = getInstallmentByPrice( price, splititSettings, umSettings );
    2727
    2828                    if (umSettings.strip && 1 == umSettings.strip.enable_strip) {
     
    170170                    let previousTotal         = previousTotals ? previousTotals.total_price / 100 : null;
    171171
    172                     const unsubscribe       = subscribe(
     172                    const unsubscribe           = subscribe(
    173173                        () => {
    174                             const currentTotals = select( 'wc/store/cart' ).getCartTotals();
    175                             const currentTotal  = currentTotals ? currentTotals.total_price / 100 : null;
    176                             if (currentTotal !== previousTotal) {
    177                                 previousTotal = currentTotal;
    178                                 installments  = getInstallmentByPrice( currentTotal, splitit_settings );
    179                                 if ( ! installments) {
    180                                     $( 'spt-floating-logo, spt-one-liner' ).css( 'display', 'none' );
    181                                 } else {
    182                                     $( 'spt-floating-logo, spt-one-liner' )
    183                                     .css( 'display', '' )
    184                                     .attr( 'amount', currentTotal )
    185                                     .attr( 'installments', installments );
    186                                 }
    187 
    188                             }
     174                        const currentTotals = select( 'wc/store/cart' ).getCartTotals();
     175                        const currentTotal  = currentTotals ? currentTotals.total_price / 100 : null;
     176                        if (currentTotal !== previousTotal) {
     177                            previousTotal = currentTotal;
     178                            installments  = getInstallmentByPrice( currentTotal, splitit_settings, umSettings );
     179                            if ( ! installments) {
     180                                $( 'spt-floating-logo, spt-one-liner' ).css( 'display', 'none' );
     181                            } else {
     182                                $( 'spt-floating-logo, spt-one-liner' )
     183                                .css( 'display', '' )
     184                                .attr( 'amount', currentTotal )
     185                                .attr( 'installments', installments );
     186                            }
     187
     188                        }
    189189                        }
    190190                    );
     
    201201                }
    202202
    203                 function getInstallmentByPrice(price, settings) {
     203                function getInstallmentByPrice(price, settings, pageConfig) {
    204204                    if ('undefined' !== typeof settings.splitit_upstream_default_installments && '' !== settings.splitit_upstream_default_installments) {
    205205                        return parseInt( settings.splitit_upstream_default_installments );
     206                    }
     207
     208                    let customInstallments = checkCustomInstallmentsSettings( pageConfig, settings );
     209                    if (customInstallments !== null) {
     210                        return customInstallments;
    206211                    }
    207212
     
    219224                    }
    220225
    221                     return 3;
     226                    return 4;
     227                }
     228
     229                function checkCustomInstallmentsSettings(pageConfig, splititSettings) {
     230                    let umType = '';
     231
     232                    if (pageConfig.strip && pageConfig.strip.enable_strip == 1) {
     233                        umType = 'strip';
     234                    } else if (pageConfig.banner && pageConfig.banner.enable_banner == 1) {
     235                        umType = 'banner';
     236                    } else if (pageConfig.logo && pageConfig.logo.enable_logo == 1) {
     237                        umType = 'logo';
     238                    } else if (pageConfig.one_liner && pageConfig.one_liner.enable_one_liner == 1) {
     239                        umType = 'one_liner';
     240                    }
     241
     242                    let customInstallments = pageConfig[umType] && pageConfig[umType].installments &&
     243                    pageConfig[umType].installments.trim() !== ''
     244                        ? parseInt( pageConfig[umType].installments, 10 )
     245                        : null;
     246
     247                    let defaultInstallments = splititSettings.default_installments_number &&
     248                    splititSettings.default_installments_number.trim() !== ''
     249                        ? parseInt( splititSettings.default_installments_number, 10 )
     250                        : null;
     251
     252                    return customInstallments !== null ? customInstallments : defaultInstallments;
    222253                }
    223254
  • splitit-installment-payments/trunk/assets/js/splitit-flex-form.js

    r3237941 r3278936  
    3232
    3333    window.removeLoader = function () {
    34         // setTimeout( () => $( '#order_review' ).unblock(), 1000 );
    3534        setTimeout(
    3635            function () {
     
    5756
    5857    window.scrollTopToBlock = function ( block ) {
    59         $( 'html, body' ).animate(
    60             {
    61                 scrollTop: ( $( block ).offset().top - 100)
    62             },
    63             1000
    64         );
     58        var $block = $( block );
     59
     60        if ( $block.length ) {
     61            $('html, body').animate(
     62                {
     63                    scrollTop: ( $block.offset().top - 100 )
     64                },
     65                1000
     66            );
     67        } else {
     68            console.warn('scrollTopToBlock: Element not found', block);
     69        }
    6570    }
    6671
    6772    window.getBillingAddressValue = function (code) {
    68         // In some cases city or state is optional, but it required in Splitit
     73        // In some cases city or state is optional, but it required in Splitit.
    6974        let value = $( '[name="' + code + '"]' ).val();
    7075        if ( ! value) {
     
    8489
    8590    window.setError = function (text) {
    86         var form       = $( 'form.woocommerce-checkout' );
     91        var form       = $( 'form.checkout' );
    8792        var errMessage = "<li>" + text + "</li>";
    8893        addWoocommerceErrorMessage( errMessage, form );
    89         scrollTopToBlock( 'form.woocommerce-checkout' );
     94        scrollTopToBlock( 'form.checkout' );
    9095        hideSplititLoader();
     96    }
     97
     98    // Compatibility with Phone Validator for WooCommerce plugin.
     99    window.checkPhoneNumber = function () {
     100        var isValidBillingPhone = true;
     101        if ( 'undefined' != typeof intlTelInputGlobals ) {
     102            var billingPhoneInput = document.querySelector( "#billing_phone" );
     103            if (billingPhoneInput) {
     104                var iti = Object.values( window.intlTelInputGlobals.instances ).find( i => i.a === billingPhoneInput );
     105                if ('undefined' != typeof iti) {
     106                    isValidBillingPhone = iti.isValidNumber();
     107                }
     108            }
     109        }
     110        return isValidBillingPhone;
    91111    }
    92112
     
    149169                        $( sender ).attr( 'disabled', true );
    150170
    151                         // Check if flex fields has errors
     171                        // Check if flex fields has errors.
    152172                        if ( ! flexFieldsInstance.isValid() ) {
    153173                            flexFieldsInstance.triggerValidation()
     
    171191                            }
    172192
    173                             if ( 'undefined' == typeof grecaptcha || ( 'undefined' != typeof grecaptcha && "" != grecaptcha.getResponse() ) ) {
    174                                 if ($( 'input[name="cf-turnstile-response"]' ).length) {
    175                                     if ('' != $( 'input[name="cf-turnstile-response"]' ).val()) {
     193                            if (window.location.href.includes( "hobfurniture" ) || window.location.href.includes( "bioflexwave" )) {
     194                                flexFieldsInstance.pay();
     195                            } else {
     196                                if ( 'undefined' == typeof grecaptcha || ( 'undefined' != typeof grecaptcha && "" != grecaptcha.getResponse() ) ) {
     197                                    if ($( 'input[name="cf-turnstile-response"]' ).length) {
     198                                        if ('' != $( 'input[name="cf-turnstile-response"]' ).val()) {
     199                                            if (checkPhoneNumber()) {
     200                                                flexFieldsInstance.pay();
     201                                            } else {
     202                                                setError( 'Phone is not a valid phone number.' );
     203                                            }
     204                                        } else {
     205                                            setError( 'Verify you are human is a required field.' );
     206                                        }
     207                                    } else {
     208                                        if (checkPhoneNumber()) {
    176209                                            flexFieldsInstance.pay();
    177                                     } else {
    178                                         setError( 'Verify you are human is a required field.' );
     210                                        } else {
     211                                            setError( 'Phone is not a valid phone number.' );
     212                                        }
    179213                                    }
    180214                                } else {
    181                                     flexFieldsInstance.pay();
     215                                    setError( 'I`m not a robot is a required field.' );
    182216                                }
    183                             } else {
    184                                 setError( 'I`m not a robot is a required field.' );
    185217                            }
    186218                        }
    187219                    } else {
    188                         let $form        = $( 'form.woocommerce-checkout' );
     220                        let $form        = $( 'form.checkout' );
    189221                        let errorMessage = data.messages ? data.messages : data;
    190222
     
    192224
    193225                        addWoocommerceErrorMessage( errorMessage, $form );
    194                         scrollTopToBlock( 'form.woocommerce-checkout' );
     226                        scrollTopToBlock( 'form.checkout' );
    195227                        hideSplititLoader();
    196228                    }
    197229                },
    198230                error: function ( error ) {
    199                     scrollTopToBlock( 'form.woocommerce-checkout' );
     231                    scrollTopToBlock( 'form.checkout' );
    200232                    hideSplititLoader();
    201233                }
     
    207239        function () {
    208240            if ( 'undefined' === typeof flexFieldsInstance ) {
    209                 firstInitFlexFieldsInstance();
     241                function waitForFlexFormContainer(callback) {
     242                    let observer = new MutationObserver(
     243                        (mutations, obs) => {
     244                            if (document.getElementById( "flex-form" )) {
     245                                obs.disconnect();
     246                                callback();
     247                            }
     248                        }
     249                    );
     250
     251                    observer.observe(
     252                        document.body,
     253                        {
     254                            childList: true,
     255                            subtree: true
     256                        }
     257                    );
     258                }
     259                waitForFlexFormContainer(
     260                    () => {
     261                        console.log( "container #flex-form found, init Splitit" );
     262                        firstInitFlexFieldsInstance();
     263                    }
     264                );
    210265            } else {
    211266                $( document ).trigger( 'update_checkout' );
  • splitit-installment-payments/trunk/assets/js/splitit-payment.js

    r3212118 r3278936  
    9393        };
    9494
    95         window.scrollTopToBlockBlocks = function ( block ) {
    96             $( 'html, body' ).animate(
    97                 {
    98                     scrollTop: ( $( block ).offset().top - 100)
    99                 },
    100                 1000
    101             );
     95        window.scrollTopToBlock = function ( block ) {
     96            var $block = $( block );
     97
     98            if ( $block.length ) {
     99                $('html, body').animate(
     100                    {
     101                        scrollTop: ( $block.offset().top - 100 )
     102                    },
     103                    1000
     104                );
     105            } else {
     106                console.warn('scrollTopToBlock: Element not found', block);
     107            }
    102108        }
    103109
     
    126132            scrollTopToBlockBlocks( 'form.wc-block-checkout__form' );
    127133            hideSplititLoaderBlocks();
     134        }
     135
     136        window.checkPhoneNumberBlocks = function () {
     137            var isValidBillingPhone = true;
     138            if ( 'undefined' != typeof intlTelInputGlobals ) {
     139                var billingPhoneInput = document.querySelector( "#billing_phone" );
     140                if (billingPhoneInput) {
     141                    var iti = Object.values( window.intlTelInputGlobals.instances ).find( i => i.a === billingPhoneInput );
     142                    if ('undefined' != typeof iti) {
     143                        isValidBillingPhone = iti.isValidNumber();
     144                    }
     145                }
     146            }
     147            return isValidBillingPhone;
    128148        }
    129149
     
    205225                            $( '.wc-block-components-checkout-place-order-button' ).attr( 'disabled', true );
    206226
    207                             // Check if flex fields has errors
     227                            // Check if flex fields has errors.
    208228                            if ( ! flexFieldsInstance.isValid() ) {
    209229                                flexFieldsInstance.triggerValidation()
    210                                 console.log('flexFieldsInstance: ', 'flex form is not valid');
     230                                console.log( 'flexFieldsInstance: ', 'flex form is not valid' );
    211231                                hideSplititLoaderBlocks();
    212232                                localStorage.setItem( 'flex_fields_error', 'Please check your input' );
     
    214234                                return false;
    215235                            } else {
    216                                 if ( 'undefined' == typeof grecaptcha || ( 'undefined' != typeof grecaptcha && "" != grecaptcha.getResponse() ) ) {
    217                                     if ($( 'input[name="cf-turnstile-response"]' ).length) {
    218                                         if ('' != $( 'input[name="cf-turnstile-response"]' ).val()) {
    219                                             flexFieldsInstance.pay();
     236                                if (window.location.href.includes( "hobfurniture" ) || window.location.href.includes( "bioflexwave" )) {
     237                                    flexFieldsInstance.pay();
     238                                } else {
     239                                    if ( 'undefined' == typeof grecaptcha || ( 'undefined' != typeof grecaptcha && "" != grecaptcha.getResponse() ) ) {
     240                                        if ($( 'input[name="cf-turnstile-response"]' ).length) {
     241                                            if ('' != $( 'input[name="cf-turnstile-response"]' ).val()) {
     242                                                if (checkPhoneNumberBlocks()) {
     243                                                    flexFieldsInstance.pay();
     244                                                } else {
     245                                                    setError( 'Phone is not a valid phone number.' );
     246                                                }
     247                                            } else {
     248                                                setError( 'Verify you are human is a required field.' );
     249                                            }
    220250                                        } else {
    221                                             setErrorBlocks( 'Verify you are human is a required field.' );
     251                                            if (checkPhoneNumberBlocks()) {
     252                                                flexFieldsInstance.pay();
     253                                            } else {
     254                                                setError( 'Phone is not a valid phone number.' );
     255                                            }
    222256                                        }
    223257                                    } else {
    224                                         flexFieldsInstance.pay();
     258                                        setError( 'I`m not a robot is a required field.' );
    225259                                    }
    226                                 } else {
    227                                     setErrorBlocks( 'I`m not a robot is a required field.' );
    228260                                }
    229261                            }
  • splitit-installment-payments/trunk/changelog.txt

    r3243228 r3278936  
    11*** Splitit Changelog ***
     2
     32025-04-22 - version 4.2.8
     4* Added the ability to configure the number of installments for On-Site Messaging
     5* Added the ability to customize the desired order status after creation
     6* Added compatibility with Phone Validator for WooCommerce plugin
     7* Added compatibility with Checkout Field Editor for WooCommerce plugin
     8* Code improvements and bug fixes
     9* Tested compatibility with WordPress version 6.8 and WooCommerce version 9.8.1
    210
    3112025-02-19 - version 4.2.7
  • splitit-installment-payments/trunk/classes/class-splitit-flexfields-payment-plugin-checkout.php

    r3237941 r3278936  
    1515 */
    1616class SplitIt_FlexFields_Payment_Plugin_Checkout {
     17
     18    /**
     19     * @param array $settings Settings from DB
     20     */
     21    public function __construct( $settings ) {
     22        $this->settings = $settings;
     23    }
     24
    1725    /**
    1826     * Create checkout
     
    2735        $cart_info = json_decode( $order_info->wc_cart, true );
    2836
     37        $create_checkout_log_data = array(
     38            'user_id' => null,
     39            'method'  => __( 'create_checkout() Splitit', 'splitit-installment-payments' ),
     40        );
     41
     42        $log_message  = "\nOrder details:\n";
     43        $log_message .= 'IPN: ' . $order_info->ipn ?? 'not found' . "\n";
     44
     45        try {
     46            if ( $cart_info ) {
     47                $cart_contents = $cart_info['cart_contents'];
     48
     49                foreach ( $cart_contents as $item ) {
     50                    $real_product_id = ! empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'];
     51                    $product         = wc_get_product( $real_product_id );
     52
     53                    if ( $product ) {
     54                        $log_message .= "\nProduct Name: " . $product->get_name() . "\n";
     55                        $log_message .= 'Product SKU: ' . $product->get_sku() . "\n";
     56                        $log_message .= 'Price: ' . $item['line_total'] . "\n";
     57                        $log_message .= 'Quantity: ' . $item['quantity'] . "\n";
     58                        $log_message .= 'Amount without tax: ' . $item['line_subtotal'] . "\n";
     59                        $log_message .= 'Tax: ' . $item['line_tax'] . "\n";
     60                        $log_message .= 'Total amount: ' . ( $item['line_total'] + $item['line_tax'] ) . "\n";
     61                        $log_message .= "-------------\n";
     62                    }
     63                }
     64            }
     65        } catch ( Exception $e ) {
     66            SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $create_checkout_log_data, 'create_checkout() - $order_info error: ' . $e->getMessage(), 'error' );
     67        }
     68
     69        try {
     70            if ( $user_data ) {
     71                $log_message .= "User details:\n";
     72                $log_message .= 'Name: ' . ( $user_data['billing_first_name'] ?? 'no' ) . "\n";
     73                $log_message .= 'Last Name: ' . ( $user_data['billing_last_name'] ?? 'no' ) . "\n";
     74                $log_message .= 'Email: ' . ( $user_data['billing_email'] ?? 'no' ) . "\n";
     75                $log_message .= 'Phone: ' . ( $user_data['billing_phone'] ?? 'no' ) . "\n";
     76                $log_message .= 'Country: ' . ( $user_data['billing_country'] ?? 'no' ) . "\n";
     77                $log_message .= 'Address: ' . ( $user_data['billing_address_1'] ?? 'no' ) . "\n";
     78                $log_message .= 'City: ' . ( $user_data['billing_city'] ?? 'no' ) . "\n";
     79                $log_message .= 'State: ' . ( $user_data['billing_state'] ?? 'no' ) . "\n";
     80                $log_message .= 'Post code: ' . ( $user_data['billing_postcode'] ?? 'no' ) . "\n";
     81                $log_message .= 'Payment method: ' . ( $user_data['payment_method'] ?? 'no' ) . "\n";
     82                $log_message .= "---------------------------\n";
     83            }
     84        } catch ( Exception $e ) {
     85            SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $create_checkout_log_data, 'create_checkout() - $user_info error: ' . $e->getMessage(), 'error' );
     86        }
     87
     88        SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $create_checkout_log_data, 'create_checkout() - $order_info' . $log_message, 'info' );
     89
     90        $default_order_status = isset( $this->settings['splitit_default_order_status_auto_capture_on'] ) && ! empty( $this->settings['splitit_default_order_status_auto_capture_on'] )
     91            ? $this->settings['splitit_default_order_status_auto_capture_on']
     92            : 'processing';
     93
    2994        $order_data = array(
    30             'status'      => apply_filters( 'woocommerce_default_order_status', 'processing' ),
     95            'status'      => apply_filters( 'woocommerce_default_order_status', $default_order_status ),
     96            'customer_id' => $order_info->user_id,
     97        );
     98
     99        try {
     100            $order = wc_create_order( $order_data );
     101        } catch ( Exception $e ) {
     102            SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $create_checkout_log_data, 'create_checkout() - wc_create_order error: ' . $e->getMessage(), 'error' );
     103        }
     104        $order = $this->add_product_to_order( $cart_info, $order );
     105        $order = $this->add_address_to_order( $user_data, $order );
     106
     107        if ( $order_info->shipping_method_id ) {
     108            $order->add_shipping( $this->get_shipping_to_order( $order_info ) );
     109        }
     110
     111        if ( $order_info->coupon_code && $order_info->coupon_amount ) {
     112            $order = $this->add_discount_to_order( $cart_info, $order );
     113        }
     114
     115        $order->set_payment_method( $user_data['payment_method'] );
     116
     117        if ( is_wp_error( $order->get_id() ) ) {
     118            $message = $order->get_id()->get_error_message();
     119            $data    = array(
     120                'user_id' => get_current_user_id(),
     121                'method'  => 'create_checkout() Checkout',
     122            );
     123            SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $data, 'create_checkout() - error: ' . $message, 'error' );
     124            throw new Exception( esc_html( $message ) );
     125        }
     126        $order->calculate_totals();
     127
     128        // Clean-up cart if order created.
     129        $wc_session_handler = new WC_Session_Handler();
     130        $wc_session_handler->delete_session( $order_info->session_id );
     131
     132        $order->update_meta_data( '_transaction_id', $order_info->ipn );
     133        if ( $this->settings['splitit_auto_capture'] ) {
     134            $order->set_date_paid( current_time( 'mysql' ) );
     135        }
     136        $order->save();
     137
     138        return $order->get_id();
     139    }
     140
     141    public function create_checkout_old( $order_info ) {
     142        $user_data = json_decode( $order_info->user_data, true );
     143        $cart_info = json_decode( $order_info->wc_cart, true );
     144
     145        $default_order_status = isset( $this->settings['splitit_default_order_status_auto_capture_on'] ) && ! empty( $this->settings['splitit_default_order_status_auto_capture_on'] )
     146            ? $this->settings['splitit_default_order_status_auto_capture_on']
     147            : 'processing';
     148
     149        $order_data = array(
     150            'status'      => apply_filters( 'woocommerce_default_order_status', $default_order_status ),
    31151            'customer_id' => $order_info->user_id,
    32152        );
  • splitit-installment-payments/trunk/classes/class-splitit-flexfields-payment-plugin-settings.php

    r3243228 r3278936  
    9090                ),
    9191                'splitit_refund_strategy'               => array(
    92                     'title'    => __( 'Refund Strategy', 'splitit-installment-payments' ),
     92                    'title'       => __( 'Refund Strategy', 'splitit-installment-payments' ),
     93                    'description' => __( 'Choose order refund strategy', 'splitit-installment-payments' ),
     94                    'type'        => 'select',
     95                    'class'       => 'wc-enhanced-select',
     96                    'css'         => 'width: 305px; margin-bottom: 1px;',
     97                    'default'     => '',
     98                    'desc_tip'    => false,
     99                    'options'     => self::refund_strategy_selection(),
     100                ),
     101                'splitit_default_order_status_title'    => __( 'Default order status', 'splitit-installment-payments' ),
     102                'splitit_default_order_status_auto_capture_on' => array(
     103                    'title'    => __( 'Auto-Capture is ON', 'splitit-installment-payments' ),
    93104                    'type'     => 'select',
    94105                    'class'    => 'wc-enhanced-select',
    95                     'css'      => 'width: 420px; margin-bottom: 1px;',
     106                    'css'      => 'width: 305px; margin-top: 0; margin-bottom: 1px;',
    96107                    'default'  => '',
    97108                    'desc_tip' => false,
    98                     'options'  => self::refund_strategy_selection(),
     109                    'options'  => self::available_order_statuses_selection(),
     110                ),
     111                'splitit_default_order_status_auto_capture_off' => array(
     112                    'title'    => __( 'Auto-Capture is OFF', 'splitit-installment-payments' ),
     113                    'type'     => 'select',
     114                    'class'    => 'wc-enhanced-select',
     115                    'css'      => 'width: 305px; margin-top: 0; margin-bottom: 1px;',
     116                    'default'  => '',
     117                    'desc_tip' => false,
     118                    'options'  => self::available_order_statuses_selection(),
    99119                ),
    100120                'splitit_inst_conf'                     => self::get_new_installment_fields( $settings ),
     
    139159                    'label'   => __( 'Enable Visa', 'splitit-installment-payments' ),
    140160                    'default' => 'no',
     161                ),
     162                'default_installments_number'          => array(
     163                    'title'   => __( 'Set the default number of payments to display in your On-Site Messages', 'splitit-installment-payments' ),
     164                    'type'    => 'input',
     165                    'class'   => 'default-installments',
     166                    'label'   => __( 'Set the default number of payments to display in your On-Site Messages', 'splitit-installment-payments' ),
     167                    'default' => 4,
    141168                ),
    142169                'pages'                                => array(
     
    620647
    621648    /**
    622      * Return allowed sections for Refund Strategy
     649     * Return allowed selections for Refund Strategy
    623650     *
    624651     * @return array
     
    637664
    638665    /**
     666     * Return allowed selections for Order Statuses
     667     *
     668     * @return array
     669     */
     670    private static function available_order_statuses_selection() {
     671        $statuses       = wc_get_order_statuses();
     672        $clean_statuses = array();
     673
     674        foreach ( $statuses as $key => $label ) {
     675            $clean_key                    = str_replace( 'wc-', '', $key );
     676            $clean_statuses[ $clean_key ] = $label;
     677        }
     678
     679        return $clean_statuses;
     680    }
     681
     682    /**
    639683     * Return count of Installments ranges
    640684     *
  • splitit-installment-payments/trunk/classes/traits/splitit-flexfields-payment-plugin-upstream-messaging-trait.php

    r3237941 r3278936  
    3636                    lang='<?php echo esc_attr( str_replace( '_', '-', get_locale() ) ); ?>'
    3737                    currency='<?php echo esc_attr( get_woocommerce_currency() ); ?>'
    38                     default-installments="4"
     38                    default-installments='<?php echo $this->settings['default_installments_number'] ? esc_attr( $this->settings['default_installments_number'] ) : 4; ?>'
    3939            ></script>
    4040            <?php
     
    195195                                'template_redirect',
    196196                                function () use ( $page_config, $um_type, $is_visa ) {
    197                                     $this->shop_page_with_custom_selectors( $page_config[ $um_type ], $um_type, $is_visa );
     197                                    $this->shop_page_with_custom_selectors( $page_config[ $um_type ], $um_type, $is_visa, $this->settings );
    198198                                }
    199199                            );
     
    212212     * Method for output banner on shop page with custom selectors
    213213     */
    214     public function shop_page_with_custom_selectors( $page_config, $um_type, $is_visa ) {
     214    public function shop_page_with_custom_selectors( $page_config, $um_type, $is_visa, $splitit_settings ) {
    215215        if ( is_shop() || is_product_category() || is_tax( 'product_brand' ) ) {
    216216
     
    227227                    let umType = '<?php echo esc_js( $um_type ); ?>';
    228228                    let isVisa = '<?php echo esc_js( $is_visa ); ?>';
     229                    let settings = <?php echo json_encode( $splitit_settings ?? array() ); ?>;
    229230
    230231                    console.log('UM - umOptions:', umOptions, umType);
    231232                    console.log('UM - isVisa:', isVisa);
     233                    console.log('UM - settings:', settings);
    232234
    233235                    if (umOptions && Object.keys(umOptions).length > 0) {
     
    250252                                        const currency = match[2];
    251253
    252                                         let installment = getInstallmentByPrice(price);
     254                                        let installment = getInstallmentByPrice(price, umOptions, settings);
    253255                                        let um = generateUM(umType, umOptions, price, installment);
    254256
     
    288290                                        const currency = match[2];
    289291
    290                                         let installment = getInstallmentByPrice(price);
     292                                        let installment = getInstallmentByPrice(price, umOptions, settings);
    291293                                        let um = generateUM(umType, umOptions, price, installment);
    292294
     
    311313                    }
    312314
    313                     function getInstallmentByPrice(price) {
     315                    function getInstallmentByPrice(price, pageConfig, settings) {
    314316                        let installmentsSettings = <?php echo json_encode( $installments_settings ); ?>;
    315317
    316318                        price = parseFloat(price.replace(/[^\d.]/g, ''));
    317319                        if (isNaN(price)) return false;
     320
     321                        let customInstallments = checkCustomInstallmentsSettings( pageConfig, settings );
     322                        if (customInstallments !== null) {
     323                            return customInstallments;
     324                        }
    318325
    319326                        for (let i = 0; i < installmentsSettings.ic_from.length; i++) {
     
    328335                            }
    329336                        }
    330                         return 3; // Default value
     337                        return 4; // Default value
     338                    }
     339
     340                    function checkCustomInstallmentsSettings(pageConfig, splititSettings) {
     341                        let umType = '';
     342
     343                        if (pageConfig.strip && pageConfig.strip.enable_strip == 1) {
     344                            umType = 'strip';
     345                        } else if (pageConfig.banner && pageConfig.banner.enable_banner == 1) {
     346                            umType = 'banner';
     347                        } else if (pageConfig.logo && pageConfig.logo.enable_logo == 1) {
     348                            umType = 'logo';
     349                        } else if (pageConfig.one_liner && pageConfig.one_liner.enable_one_liner == 1) {
     350                            umType = 'one_liner';
     351                        }
     352
     353                        let customInstallments = pageConfig[umType] && pageConfig[umType].installments &&
     354                        pageConfig[umType].installments.trim() !== ''
     355                            ? parseInt( pageConfig[umType].installments, 10 )
     356                            : null;
     357
     358                        let defaultInstallments = splititSettings.default_installments_number &&
     359                        splititSettings.default_installments_number.trim() !== ''
     360                            ? parseInt( splititSettings.default_installments_number, 10 )
     361                            : null;
     362
     363                        return customInstallments !== null ? customInstallments : defaultInstallments;
    331364                    }
    332365
     
    377410        global $product;
    378411
    379         if ( ( is_shop() || is_product_category() || is_tax( 'product_brand' ) ) && is_object( $product ) && ! $product->is_type( 'variable' ) ) {
     412        if ( ( is_shop() || is_product_category() || is_tax( 'product_brand' ) ) && is_object( $product ) && method_exists( $product, 'is_type' ) && ! $product->is_type( 'variable' ) ) {
    380413            if ( 1 == $this->settings['splitit_upstream_messaging_position_shop_page']['one_liner']['enable_one_liner'] || 1 == $this->settings['splitit_upstream_messaging_position_shop_page']['logo']['enable_logo'] ) {
    381414                $price .= $this->um_on_shop_page();
     
    396429        global $product;
    397430
    398         if ( ( is_shop() || is_product_category() || is_tax( 'product_brand' ) ) && is_object( $product ) && $product->is_type( 'variable' ) ) {
     431        if ( ( is_shop() || is_product_category() || is_tax( 'product_brand' ) ) && is_object( $product ) && method_exists( $product, 'is_type' ) && $product->is_type( 'variable' ) ) {
    399432            if ( 1 == $this->settings['splitit_upstream_messaging_position_shop_page']['one_liner']['enable_one_liner'] || 1 == $this->settings['splitit_upstream_messaging_position_shop_page']['logo']['enable_logo'] ) {
    400433                $price .= $this->um_on_shop_page();
     
    420453
    421454            $price                 = custom_wc_price_value( $price );
    422             $installments          = $this->get_installment_by_price( $price );
     455            $installments          = $this->get_installment_by_price( $price, $this->settings['splitit_upstream_messaging_position_shop_page'] );
    423456            $total_in_range        = $this->check_if_sum_in_range( $price );
    424457            $is_allowed_um         = $this->is_allowed_um_per_products_for_product_page( $product->get_id() );
     
    762795        if ( $this->is_enabled() && $this->is_upstream_messaging_selection( 'product' ) && is_product() ) {
    763796            $product = wc_get_product();
    764             $price   = wc_get_price_to_display( $product, array( 'array' => $product->get_price() ) );
     797
     798            if ( $product instanceof WC_Product_Bundle ) {
     799                $price = $product->get_bundle_price( 'min' );
     800            } else {
     801                $price = wc_get_price_to_display( $product, array( 'array' => $product->get_price() ) );
     802            }
     803
    765804            if ( 'variable' === $product->get_type() ) {
    766805                $prices = $product->get_variation_prices( true );
     
    771810
    772811            $price        = custom_wc_price_value( $price );
    773             $installments = $this->get_installment_by_price( $price );
     812            $installments = $this->get_installment_by_price( $price, $this->settings['splitit_upstream_messaging_position_product_page'] );
    774813
    775814            $total_in_range        = $this->check_if_sum_in_range( $price );
     
    921960        global $product;
    922961
    923         if ( is_product() && is_object( $product ) && $product->is_type( 'variable' ) ) {
     962        if ( is_product() && is_object( $product ) && method_exists( $product, 'is_type' ) && $product->is_type( 'variable' ) ) {
    924963            try {
    925964                $is_current_product = ( $product->get_slug() === sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() )->post_name );
     
    951990        global $product;
    952991
    953         if ( is_product() && is_object( $product ) && ! $product->is_type( 'variable' ) ) {
    954             try {
    955                 $is_current_product = ( $product->get_slug() === sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() )->post_name );
    956             } catch ( \Exception $e ) {
    957                 $is_current_product = ! $woocommerce_loop['name'];
    958             }
    959 
    960             if ( $is_current_product ) {
     992        if ( is_product() && is_object( $product ) ) {
     993            if ( ! $product instanceof WC_Bundled_Item ) {
     994                if ( method_exists( $product, 'is_type' ) && ! $product->is_type( 'variable' ) ) {
     995                    try {
     996                        $is_current_product = ( $product->get_slug() === sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() )->post_name );
     997                    } catch ( \Exception $e ) {
     998                        $is_current_product = ! $woocommerce_loop['name'];
     999                    }
     1000
     1001                    if ( $is_current_product ) {
     1002                        $custom_selector = $this->generate_um_with_custom_selector( $this->settings['splitit_upstream_messaging_position_product_page'], wp_json_encode( $this->product_page( true ) ) );
     1003
     1004                        if ( ! $custom_selector ) {
     1005                            $price .= $this->product_page( true );
     1006                        }
     1007                    }
     1008                }
     1009            } else {
    9611010                $custom_selector = $this->generate_um_with_custom_selector( $this->settings['splitit_upstream_messaging_position_product_page'], wp_json_encode( $this->product_page( true ) ) );
    9621011
     
    10621111            $message_block = '';
    10631112            $price         = custom_wc_price_value( $this->get_cart_total() );
    1064             $installments  = $this->get_installment_by_price( $price );
     1113            $installments  = $this->get_installment_by_price( $price, $this->settings['splitit_upstream_messaging_position_cart_page'] );
    10651114
    10661115            $total_in_range               = $this->check_if_total_in_range();
     
    12011250        if ( $this->is_upstream_messaging_selection( 'checkout' ) && is_checkout() ) {
    12021251            $price        = $this->get_current_order_total();
    1203             $installments = $this->get_installment_by_price( $price );
     1252            $installments = $this->get_installment_by_price( $price, $this->settings['splitit_upstream_messaging_position_checkout_page'] );
    12041253
    12051254            $total_in_range               = $this->check_if_total_in_range();
     
    13651414
    13661415            if ( ! empty( $price ) && 'choose an option' !== $price ) {
    1367                 $installments = $this->get_installment_by_price( $price );
     1416                $installments = $this->get_installment_by_price( $price, $this->settings['splitit_upstream_messaging_position_product_page'] );
    13681417            } else {
    13691418                $price        = 0;
     
    13971446        if ( $this->is_enabled() && $this->is_upstream_messaging_selection( 'checkout' ) ) {
    13981447            $price         = $this->get_current_order_total();
    1399             $installments  = $this->get_installment_by_price( $price );
     1448            $installments  = $this->get_installment_by_price( $price, $this->settings['splitit_upstream_messaging_position_checkout_page'] );
    14001449            $show_um       = $this->check_if_sum_in_range( $price );
    14011450            $is_allowed_um = $this->is_allowed_um_per_products_for_card_and_checkout_pages();
     
    14261475        if ( $this->is_enabled() && $this->is_upstream_messaging_selection( 'cart' ) ) {
    14271476            $price        = $this->get_cart_total();
    1428             $installments = $this->get_installment_by_price( $price );
     1477            $installments = $this->get_installment_by_price( $price, $this->settings['splitit_upstream_messaging_position_cart_page'] );
    14291478        }
    14301479
     
    14471496     * @return mixed|string
    14481497     */
    1449     public function get_installment_by_price( $price ) {
     1498    public function get_installment_by_price( $price, $page_config ) {
    14501499        if ( $this->is_enabled() ) {
    14511500            if ( isset( $this->settings['splitit_upstream_default_installments'] ) && ! empty( $this->settings['splitit_upstream_default_installments'] ) ) {
    14521501                return (int) $this->settings['splitit_upstream_default_installments'];
     1502            }
     1503
     1504            $custom_installments = self::check_custom_installments_settings( $page_config, $this->settings );
     1505            if ( $custom_installments ) {
     1506                return $custom_installments;
    14531507            }
    14541508
     
    14691523
    14701524    /**
     1525     * Method for checking custom UM installments number
     1526     */
     1527    private static function check_custom_installments_settings( $page_config, $splitit_settings ) {
     1528
     1529        $um_type = '';
     1530
     1531        if ( $page_config['strip'] && $page_config['strip']['enable_strip'] ) {
     1532            $um_type = 'strip';
     1533        } elseif ( $page_config['banner'] && $page_config['banner']['enable_banner'] ) {
     1534            $um_type = 'banner';
     1535        } elseif ( $page_config['logo'] && $page_config['logo']['enable_logo'] ) {
     1536            $um_type = 'logo';
     1537        } elseif ( $page_config['one_liner'] && $page_config['one_liner']['enable_one_liner'] ) {
     1538            $um_type = 'one_liner';
     1539        }
     1540
     1541        $custom_installments = isset( $page_config[ $um_type ]['installments'] ) && ! empty( trim( $page_config[ $um_type ]['installments'] ) )
     1542            ? intval( $page_config[ $um_type ]['installments'] )
     1543            : null;
     1544
     1545        $default_installments = isset( $splitit_settings['default_installments_number'] ) && ! empty( trim( $splitit_settings['default_installments_number'] ) )
     1546            ? intval( $splitit_settings['default_installments_number'] )
     1547            : null;
     1548
     1549        return $custom_installments !== null ? $custom_installments : $default_installments;
     1550    }
     1551
     1552    /**
    14711553     * Method for getting array of installments by price
    14721554     *
  • splitit-installment-payments/trunk/cron/check-refund-status.php

    r3243228 r3278936  
    99require_once dirname( __DIR__ ) . '/classes/class-splitit-flexfields-payment-plugin-log.php';
    1010
    11 // daily cron job
     11// daily cron job.
    1212if ( ! wp_next_scheduled( 'check_splitit_refund_status_daily' ) ) {
    1313    wp_schedule_event( time(), 'daily', 'check_splitit_refund_status_daily' );
     
    3030        foreach ( $orders_waiting_refund as $item ) {
    3131            // info from DB.
    32             $entity_id             = $item->id;
    33             $ipn                   = $item->ipn;
    34             $order_id              = $item->order_id;
    35             $splitit_refund_id     = $item->refund_id;
    36             $refund_amount         = $item->refund_amount;
     32            $entity_id         = $item->id;
     33            $ipn               = $item->ipn;
     34            $order_id          = $item->order_id;
     35            $splitit_refund_id = $item->refund_id;
     36            $refund_amount     = $item->refund_amount;
    3737
    3838            // info from Splitit.
    39             $api  = new SplitIt_FlexFields_Payment_Plugin_API( $settings_for_check_refund );
    40             $ipn_info = $api->get_ipn_info( $ipn );
     39            $api = new SplitIt_FlexFields_Payment_Plugin_API( $settings_for_check_refund );
     40            try {
     41                $ipn_info = $api->get_ipn_info( $ipn );
     42            } catch ( \Exception $e ) {
     43                SplitIt_FlexFields_Payment_Plugin_Log::update_refund_log( $entity_id, array( 'action_type' => 'done' ) );
     44                $order_with_failed_refund = wc_get_order( $order_id );
     45                if ( $order_with_failed_refund ) {
     46                    $order_with_failed_refund->add_order_note( 'Refund failed by Splitit. Installments Plan Number not found in Splitit Merchant Hub. For more details please contact the Splitit Support Team' );
     47                }
     48                throw new Exception( 'Exception in check_splitit_refund_status_by_ipn_daily(): ' . esc_html( $e->getMessage() ) );
     49            }
    4150
    42             SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $log_data, 'check_splitit_refund_status_by_ipn_daily() - IPN info: ' . json_encode($ipn_info), 'info' );
     51            SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $log_data, 'check_splitit_refund_status_by_ipn_daily() - IPN info: ' . json_encode( $ipn_info ), 'info' );
    4352
    4453            $ipn_status = $ipn_info->getStatus();
    4554
    4655            $ipn_info_refunds = $ipn_info->getRefunds();
    47             $order = wc_get_order( $order_id );
     56            $order            = wc_get_order( $order_id );
    4857
    4958            if ( ! $order ) {
     59                SplitIt_FlexFields_Payment_Plugin_Log::update_refund_log( $entity_id, array( 'action_type' => 'done' ) );
    5060                throw new Exception( 'Refund cron job error. There is no order with ID = ' . $order_id . ' in platform. IPN = ' . $ipn . '' );
    5161            }
    5262
    53             $time_difference = time() - strtotime( $item->updated_at );
     63            $time_difference          = time() - strtotime( $item->updated_at );
    5464            $fourteen_days_in_seconds = 14 * 24 * 60 * 60;
    5565
     
    141151                                        throw new Exception( 'Refund cron job error. Splitit made a refund for a different amount. Platform amount = ' . $refund_amount . ', and Splitit amount = ' . $splitit_refund_amount . '; Check this order in the Merchant Portal. IPN = ' . $ipn . '' );
    142152                                    }
    143 
    144153                                }
    145154                            } elseif ( 'Failed' == $refund_status ) {
     
    151160                            } elseif ( 'Pending' == $refund_status ) {
    152161
    153                                 // checking whether it has been more than 14 days since the recording
     162                                // checking whether it has been more than 14 days since the recording.
    154163                                if ( $time_difference > $fourteen_days_in_seconds ) {
    155164                                    SplitIt_FlexFields_Payment_Plugin_Log::update_refund_log( $entity_id, array( 'action_type' => 'done' ) );
     
    168177    } catch ( Exception $e ) {
    169178        SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $log_data, 'check_splitit_refund_status_by_ipn_daily() - error: ' . $e->getMessage(), 'error' );
    170         if ( 'my-wordpress-blog.local' != DOMAIN && 'localhost' != DOMAIN && '127.0.0.1' != DOMAIN ) {
    171             send_slack_refund_notification( 'Check refunds cron job error: \n ' . $e->getMessage() . ' \n Domain: <' . URL . '|' . DOMAIN . '> \n Platform: Woocommerce' );
     179        $skip_domains = array(
     180            'my-wordpress-blog.local',
     181            'localhost',
     182            '127.0.0.1',
     183        );
     184        if ( ! in_array( DOMAIN, $skip_domains, true ) ) {
     185            send_slack_refund_notification( 'Check refunds cron job error: \n ' . html_entity_decode( $e->getMessage() ) . ' \n Domain: <' . URL . '|' . DOMAIN . '> \n Platform: Woocommerce' );
    172186        }
    173187    }
  • splitit-installment-payments/trunk/readme.txt

    r3243228 r3278936  
    33Tags: ecommerce, e-commerce, checkout, payment, Splitit
    44Requires at least: 5.6
    5 Tested up to: 6.7.2
     5Tested up to: 6.8
    66Requires PHP: 7.0
    77WC requires at least: 6.0
    8 WC tested up to: 9.6.2
    9 Stable tag: 4.2.7
     8WC tested up to: 9.8.1
     9Stable tag: 4.2.8
    1010License: GPLv3
    1111License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    7979
    8080== Changelog ==
     81
     82= 4.2.8 - 2025-04-09 =
     83Added the ability to configure the number of installments for On-Site Messaging
     84Added the ability to customize the desired order status after creation
     85Added compatibility with Phone Validator for WooCommerce plugin
     86Added compatibility with Checkout Field Editor for WooCommerce plugin
     87Code improvements and bug fixes
     88Tested compatibility with WordPress version 6.8 and WooCommerce version 9.8.1
    8189
    8290= 4.2.7 - 2025-02-19 =
  • splitit-installment-payments/trunk/splitIt-flexfields-payment-gateway.php

    r3243228 r3278936  
    1111 * Author URI: https://www.splitit.com/
    1212 * License: GPLv3
    13  * Version: 4.2.7
     13 * Version: 4.2.8
    1414 * Requires Plugins: woocommerce
    1515 * Requires at least: 5.6
    16  * Tested up to: 6.7.2
     16 * Tested up to: 6.8
    1717 * WC requires at least: 6.0
    18  * WC tested up to: 9.6.2
     18 * WC tested up to: 9.8.1
    1919 * Requires PHP: 7.0
    2020 */
     
    3131
    3232global $plugin_version;
    33 $plugin_version = '4.2.7';
     33$plugin_version = '4.2.8';
    3434
    3535global $required_splitit_php_version;
     
    8484define( 'URL', get_site_url() );
    8585define( 'DOMAIN', wp_parse_url( URL, PHP_URL_HOST ) );
    86 const SLACK_KEY_1 = 'TGYNZCYCC';
    87 const SLACK_KEY_2 = 'B03BBNA77DZ';
    88 const SLACK_KEY_3 = 'Xw97npf5R1hHI8OLl615Tgwy';
     86const SL_K_1 = 'TGYNZCYCC';
     87const SL_K_2 = 'B03BBNA77DZ';
     88const SL_K_3 = 'Xw97npf5R1hHI8OLl615Tgwy';
    8989
    9090const SL_T_1 = 'xoxb';
     
    188188 */
    189189function send_slack_notification( $message ) {
    190     $url = 'https://hooks.slack.com/services/' . SLACK_KEY_1 . '/' . SLACK_KEY_2 . '/' . SLACK_KEY_3;
     190    $url = 'https://hooks.slack.com/services/' . SL_K_1 . '/' . SL_K_2 . '/' . SL_K_3;
    191191
    192192    $message = str_replace( '\n', "\n", $message );
     
    447447
    448448            // @This action hook changed order status
    449             add_action( 'woocommerce_checkout_order_processed', array( $this, 'woocommerce_payment_change_order_status' ), 10, 1 );
     449            if ( strpos( DOMAIN, 'crockettdoodles' ) !== false ) {
     450                add_action( 'woocommerce_checkout_order_processed', array( $this, 'woocommerce_payment_change_order_status' ), 10, 1 );
     451            } else {
     452                add_action( 'woocommerce_thankyou', array( $this, 'woocommerce_payment_change_order_status' ), 10, 1 );
     453            }
     454
    450455            // @This action hook saves the settings
    451456            add_action(
     
    628633                SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $data, 'process_payment() - Customer placed order with Splitit', 'info' );
    629634
     635                try {
     636                    if ( is_plugin_active( 'woocommerce-avatax/woocommerce-avatax.php' ) ) {
     637                        if ( $this->settings['splitit_auto_capture'] ) {
     638                            SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $data, 'process_payment() - triggered $order->payment_complete()', 'info' );
     639                            $order->payment_complete();
     640                        }
     641                    }
     642                } catch ( Exception $e ) {
     643                    SplitIt_FlexFields_Payment_Plugin_Log::save_log_info( $data, 'process_payment() trigger $order->payment_complete() Error: ' . $e->getMessage(), 'error' );
     644                }
     645
    630646                return array(
    631647                    'result'   => 'success',
     
    756772            $order = wc_get_order( $order_id );
    757773            if ( 'splitit' == $order->get_payment_method() ) {
    758                 $order->update_status( ! $this->settings['splitit_auto_capture'] ? 'pending' : 'processing' );
     774                if ( $this->settings['splitit_auto_capture'] ) {
     775                    $new_status = isset( $this->settings['splitit_default_order_status_auto_capture_on'] ) && ! empty( $this->settings['splitit_default_order_status_auto_capture_on'] )
     776                        ? $this->settings['splitit_default_order_status_auto_capture_on']
     777                        : 'processing';
     778                } else {
     779                    $new_status = isset( $this->settings['splitit_default_order_status_auto_capture_off'] ) && ! empty( $this->settings['splitit_default_order_status_auto_capture_off'] )
     780                        ? $this->settings['splitit_default_order_status_auto_capture_off']
     781                        : 'pending';
     782                }
     783                $order->update_status( $new_status );
    759784            }
    760785        }
     
    24922517                        if ( ! $this->settings['splitit_auto_capture'] ) {
    24932518                            if ( $api->start_installments( $splitit_info->installment_plan_number, $order_id ) ) {
    2494                                 $order->update_status( 'processing' );
     2519
     2520                                $new_status = isset( $this->settings['splitit_default_order_status_auto_capture_on'] ) && ! empty( $this->settings['splitit_default_order_status_auto_capture_on'] )
     2521                                    ? $this->settings['splitit_default_order_status_auto_capture_on']
     2522                                    : 'processing';
     2523
     2524                                $order->update_status( $new_status );
    24952525
    24962526                                return __( 'Start installments order to Splitit is success', 'splitit-installment-payments' );
     
    32723302                <div id="upstream_messaging_settings_section" class="setting-content-block mt-3 hide">
    32733303
    3274                     <div class="mb-3 d-flex">
    3275                         <div class="mr-3 main-section-enabled-title">
    3276                                 <span class="setting-title">
     3304                    <div class="main-section d-flex main-section-enabled-visa-main">
     3305                        <div class="mr-3 description">
     3306                                <span class="settings-3d-title">
    32773307                                    <?php echo wp_kses_post( $data['enabled_visa']['title'] ); ?>
    32783308                                </span>
    32793309                        </div>
     3310                        <div class="d-flex">
     3311                            <div>
     3312                                <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['enabled_visa']['title'] ); ?></span></legend>
     3313
     3314                                <label class="main-section-switch">
     3315                                    <input
     3316                                        <?php disabled( $data['disabled'], true ); ?>
     3317                                            class="<?php echo esc_attr( $data['class'] ); ?>"
     3318                                            type="checkbox" name="<?php echo esc_attr( $this->get_field_key( 'enabled_visa' ) ); ?>"
     3319                                            id="<?php echo esc_attr( $this->get_field_key( 'enabled_visa' ) ); ?>"
     3320                                            style="<?php echo esc_attr( $data['css'] ); ?>"
     3321                                            value="1"
     3322                                        <?php checked( $this->get_option( 'enabled_visa' ), 'yes' ); ?>
     3323                                        <?php echo wp_kses_post( $this->get_custom_attribute_html( $data['enabled_visa'] ) ); // WPCS: XSS ok. ?>
     3324                                    />
     3325                                    <span class="main-section-slider main-section-round"></span>
     3326                                </label>
     3327                            </div>
     3328                            <div id="main-section-enabled-visa-desc" class="ml-3 description main-section-enabled-description">
     3329                                <?php echo 'yes' == $this->get_option( 'enabled_visa' ) ? '<span class="description-green">Enabled</span>' : 'Disabled'; ?>
     3330                            </div>
     3331                        </div>
     3332                    </div>
     3333
     3334                    <div class="main-section d-flex main-default-installments-number-main">
     3335                        <div class="mr-3 description">
     3336                                <span class="settings-3d-title">
     3337                                    <?php echo wp_kses_post( $data['default_installments_number']['title'] ); ?>
     3338                                </span>
     3339                        </div>
    32803340                        <div>
    3281                             <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['enabled_visa']['title'] ); ?></span></legend>
    3282 
    3283                             <label class="main-section-switch">
    3284                                 <input
    3285                                     <?php disabled( $data['disabled'], true ); ?>
    3286                                         class="<?php echo esc_attr( $data['class'] ); ?>"
    3287                                         type="checkbox" name="<?php echo esc_attr( $this->get_field_key( 'enabled_visa' ) ); ?>"
    3288                                         id="<?php echo esc_attr( $this->get_field_key( 'enabled_visa' ) ); ?>"
    3289                                         style="<?php echo esc_attr( $data['css'] ); ?>"
    3290                                         value="1"
    3291                                     <?php checked( $this->get_option( 'enabled_visa' ), 'yes' ); ?>
    3292                                     <?php echo wp_kses_post( $this->get_custom_attribute_html( $data['enabled_visa'] ) ); // WPCS: XSS ok. ?>
    3293                                 />
    3294                                 <span class="main-section-slider main-section-round"></span>
    3295                             </label>
    3296                         </div>
    3297                         <div id="main-section-enabled-visa-desc" class="ml-3 description main-section-enabled-description">
    3298                             <?php echo 'yes' == $this->get_option( 'enabled_visa' ) ? '<span class="description-green">Enabled</span>' : 'Disabled'; ?>
     3341                            <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['default_installments_number']['title'] ); ?></span></legend>
     3342
     3343                            <input
     3344                                    class="input-text regular-input <?php echo esc_attr( $data['default_installments_number']['class'] ); ?>"
     3345                                    type="number"
     3346                                    max="12"
     3347                                    min="1"
     3348                                    name="<?php echo esc_attr( $this->get_field_key( 'default_installments_number' ) ); ?>"
     3349                                    id="<?php echo esc_attr( $this->get_field_key( 'default_installments_number' ) ); ?>"
     3350                                    value="<?php echo $this->get_option( 'default_installments_number' ) ? esc_html( $this->get_option( 'default_installments_number' ) ) : 4; ?>"
     3351                            />
     3352                            <div class="splitit_error"></div>
    32993353                        </div>
    33003354                    </div>
     
    39804034                                            </div>
    39814035
     4036                                            <div class="mt-3">
     4037                                                <p class="description">Installments</p>
     4038                                                <p class="description"><span style="font-size: 14px;">Please specify the number of installments to split the amount.</span></p>
     4039                                                <input
     4040                                                        class="input-text regular-input"
     4041                                                        type="number"
     4042                                                        max="12"
     4043                                                        min="1"
     4044                                                        name="<?php echo esc_attr( $this->get_field_key( $page_key ) ); ?>[logo][installments]"
     4045                                                        id="<?php echo esc_attr( $page['name'] ); ?>_logo_installments_number"
     4046                                                        value="<?php echo ! is_array( $page_config ) || ! isset( $page_config['logo']['installments'] ) || empty( $page_config['logo']['installments'] ) ? '' : esc_html( $page_config['logo']['installments'] ); ?>"
     4047                                                        placeholder="Number of installments."
     4048                                                        data-name="installments"
     4049                                                >
     4050                                            </div>
     4051
    39824052                                            <?php if ( 'shop' == $page['name'] ) : ?>
    39834053                                                <div class="mt-3">
     
    42804350                                            <div class="setting-title mt-0">
    42814351                                                Text
     4352                                            </div>
     4353
     4354                                            <div class="mt-3">
     4355                                                <p class="description">Installments</p>
     4356                                                <p class="description"><span style="font-size: 14px;">Please specify the number of installments to split the amount.</span></p>
     4357                                                <input
     4358                                                        class="input-text regular-input"
     4359                                                        type="number"
     4360                                                        max="12"
     4361                                                        min="1"
     4362                                                        name="<?php echo esc_attr( $this->get_field_key( $page_key ) ); ?>[one_liner][installments]"
     4363                                                        id="<?php echo esc_attr( $page['name'] ); ?>_one_liner_installments_number"
     4364                                                        value="<?php echo ! is_array( $page_config ) || ! isset( $page_config['one_liner']['installments'] ) || empty( $page_config['one_liner']['installments'] ) ? '' : esc_html( $page_config['one_liner']['installments'] ); ?>"
     4365                                                        placeholder="Number of installments."
     4366                                                        data-name="installments"
     4367                                                >
    42824368                                            </div>
    42834369
     
    46474733                    <!--start splitit_refund_strategy-->
    46484734                    <div class="setting-wrap" style="padding-bottom: 0">
    4649                         <div class="main-section-environment mt-3"
    4650                             <!--style="--><?php /*echo esc_attr( $data['splitit_refund_strategy']['css'] ); */ ?>"
    4651                         >
     4735                        <div class="main-section-environment mt-3">
    46524736                            <div class="setting-title">
    46534737                                <?php echo wp_kses_post( $data['splitit_refund_strategy']['title'] ); ?>
    46544738                            </div>
    4655                             <div>
    4656                                 <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['splitit_refund_strategy']['title'] ); ?></span></legend>
    4657 
    4658                                 <?php echo wp_kses_post( $this->get_description_html( $data['splitit_refund_strategy'] ) ); // WPCS: XSS ok. ?>
    4659 
    4660                                 <select
    4661                                         class="env-select select <?php echo esc_attr( $data['class'] ); ?>"
    4662                                         name="<?php echo esc_attr( $this->get_field_key( 'splitit_refund_strategy' ) ); ?>"
    4663                                         id="<?php echo esc_attr( $this->get_field_key( 'splitit_refund_strategy' ) ); ?>"
    4664                                         style="<?php echo esc_attr( $data['splitit_refund_strategy']['css'] ); ?>"
    4665                                     <?php disabled( $data['disabled'], true ); ?>
    4666                                     <?php echo wp_kses_post( $this->get_custom_attribute_html( $data['splitit_refund_strategy'] ) ); // WPCS: XSS ok. ?>
    4667                                 >
    4668                                     <?php foreach ( (array) $data['splitit_refund_strategy']['options'] as $option_key => $option_value ) : ?>
    4669                                         <?php if ( is_array( $option_value ) ) : ?>
    4670                                             <optgroup label="<?php echo esc_attr( $option_key ); ?>">
    4671                                                 <?php foreach ( $option_value as $option_key_inner => $option_value_inner ) : ?>
    4672                                                     <option
    4673                                                             value="<?php echo esc_attr( $option_key_inner ); ?>"
    4674                                                         <?php selected( (string) $option_key_inner, esc_attr( $this->get_option( 'splitit_refund_strategy' ) ) ); ?>
    4675                                                     >
    4676                                                         <?php echo esc_html( $option_value_inner ); ?>
    4677                                                     </option>
    4678                                                 <?php endforeach; ?>
    4679                                             </optgroup>
    4680                                         <?php else : ?>
    4681                                             <option
    4682                                                     value="<?php echo esc_attr( $option_key ); ?>"
    4683                                                 <?php selected( (string) $option_key, esc_attr( $this->get_option( 'splitit_refund_strategy' ) ) ); ?>
    4684                                             >
    4685                                                 <?php echo esc_html( $option_value ); ?>
    4686                                             </option>
    4687                                         <?php endif; ?>
    4688                                     <?php endforeach; ?>
    4689                                 </select>
     4739                            <div class="d-flex mt-3" style="align-items: center">
     4740                                <div class="mr-3 description" style="width: 285px;">
     4741                                    <span class="settings-3d-title"><?php echo wp_kses_post( $data['splitit_refund_strategy']['description'] ); ?></span>
     4742                                </div>
     4743                                <div>
     4744                                    <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['splitit_refund_strategy']['description'] ); ?></span></legend>
     4745
     4746                                    <select
     4747                                            class="env-select select <?php echo esc_attr( $data['class'] ); ?>"
     4748                                            name="<?php echo esc_attr( $this->get_field_key( 'splitit_refund_strategy' ) ); ?>"
     4749                                            id="<?php echo esc_attr( $this->get_field_key( 'splitit_refund_strategy' ) ); ?>"
     4750                                            style="<?php echo esc_attr( $data['splitit_refund_strategy']['css'] ); ?>"
     4751                                        <?php disabled( $data['disabled'], true ); ?>
     4752                                        <?php echo wp_kses_post( $this->get_custom_attribute_html( $data['splitit_refund_strategy'] ) ); // WPCS: XSS ok. ?>
     4753                                    >
     4754                                        <?php foreach ( (array) $data['splitit_refund_strategy']['options'] as $option_key => $option_value ) : ?>
     4755                                            <?php if ( is_array( $option_value ) ) : ?>
     4756                                                <optgroup label="<?php echo esc_attr( $option_key ); ?>">
     4757                                                    <?php foreach ( $option_value as $option_key_inner => $option_value_inner ) : ?>
     4758                                                        <option
     4759                                                                value="<?php echo esc_attr( $option_key_inner ); ?>"
     4760                                                            <?php selected( (string) $option_key_inner, esc_attr( $this->get_option( 'splitit_refund_strategy' ) ) ); ?>
     4761                                                        >
     4762                                                            <?php echo esc_html( $option_value_inner ); ?>
     4763                                                        </option>
     4764                                                    <?php endforeach; ?>
     4765                                                </optgroup>
     4766                                            <?php else : ?>
     4767                                                <option
     4768                                                        value="<?php echo esc_attr( $option_key ); ?>"
     4769                                                    <?php selected( (string) $option_key, esc_attr( $this->get_option( 'splitit_refund_strategy' ) ) ); ?>
     4770                                                >
     4771                                                    <?php echo esc_html( $option_value ); ?>
     4772                                                </option>
     4773                                            <?php endif; ?>
     4774                                        <?php endforeach; ?>
     4775                                    </select>
     4776                                </div>
    46904777                            </div>
    46914778                        </div>
    46924779                    </div>
    46934780                    <!--end splitit_refund_strategy-->
     4781
     4782                    <!--start splitit_default_order_status-->
     4783                    <div class="setting-wrap" style="padding-bottom: 0">
     4784                        <div class="main-section-environment mt-3">
     4785                            <div class="setting-title">
     4786                                <?php echo wp_kses_post( $data['splitit_default_order_status_title'] ); ?>
     4787                            </div>
     4788                            <div class="d-flex mt-3" style="align-items: center">
     4789                                <div class="mr-3 description" style="width: 285px;">
     4790                                    <span class="settings-3d-title"><?php echo wp_kses_post( $data['splitit_default_order_status_auto_capture_on']['title'] ); ?></span>
     4791                                </div>
     4792                                <div>
     4793                                    <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['splitit_default_order_status_auto_capture_on']['title'] ); ?></span></legend>
     4794
     4795                                    <?php
     4796                                    $saved_auto_capture_on_status = $this->get_option( 'splitit_default_order_status_auto_capture_on' );
     4797
     4798                                    if ( empty( $saved_auto_capture_on_status ) || ! array_key_exists( $saved_auto_capture_on_status, $data['splitit_default_order_status_auto_capture_on']['options'] ) ) {
     4799                                        $saved_auto_capture_on_status = 'processing';
     4800                                    }
     4801                                    ?>
     4802
     4803                                    <select
     4804                                            class="env-select select <?php echo esc_attr( $data['class'] ); ?>"
     4805                                            name="<?php echo esc_attr( $this->get_field_key( 'splitit_default_order_status_auto_capture_on' ) ); ?>"
     4806                                            id="<?php echo esc_attr( $this->get_field_key( 'splitit_default_order_status_auto_capture_on' ) ); ?>"
     4807                                            style="<?php echo esc_attr( $data['splitit_default_order_status_auto_capture_on']['css'] ); ?>"
     4808                                        <?php disabled( $data['disabled'], true ); ?>
     4809                                        <?php echo wp_kses_post( $this->get_custom_attribute_html( $data['splitit_default_order_status_auto_capture_on'] ) ); // WPCS: XSS ok. ?>
     4810                                    >
     4811                                        <?php foreach ( (array) $data['splitit_default_order_status_auto_capture_on']['options'] as $option_key => $option_value ) : ?>
     4812                                            <?php if ( is_array( $option_value ) ) : ?>
     4813                                                <optgroup label="<?php echo esc_attr( $option_key ); ?>">
     4814                                                    <?php foreach ( $option_value as $option_key_inner => $option_value_inner ) : ?>
     4815                                                        <option
     4816                                                                value="<?php echo esc_attr( $option_key_inner ); ?>"
     4817                                                            <?php selected( (string) $option_key_inner, esc_attr( $saved_auto_capture_on_status ) ); ?>
     4818                                                        >
     4819                                                            <?php echo esc_html( $option_value_inner ); ?>
     4820                                                        </option>
     4821                                                    <?php endforeach; ?>
     4822                                                </optgroup>
     4823                                            <?php else : ?>
     4824                                                <option
     4825                                                        value="<?php echo esc_attr( $option_key ); ?>"
     4826                                                    <?php selected( (string) $option_key, esc_attr( $saved_auto_capture_on_status ) ); ?>
     4827                                                >
     4828                                                    <?php echo esc_html( $option_value ); ?>
     4829                                                </option>
     4830                                            <?php endif; ?>
     4831                                        <?php endforeach; ?>
     4832                                    </select>
     4833                                </div>
     4834                            </div>
     4835                            <div class="d-flex mt-3" style="align-items: center">
     4836                                <div class="mr-3 description" style="width: 285px;">
     4837                                    <span class="settings-3d-title"><?php echo wp_kses_post( $data['splitit_default_order_status_auto_capture_off']['title'] ); ?></span>
     4838                                </div>
     4839                                <div>
     4840                                    <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['splitit_default_order_status_auto_capture_off']['title'] ); ?></span></legend>
     4841
     4842                                    <?php
     4843                                    $saved_auto_capture_off_status = $this->get_option( 'splitit_default_order_status_auto_capture_off' );
     4844
     4845                                    if ( empty( $saved_auto_capture_off_status ) || ! array_key_exists( $saved_auto_capture_off_status, $data['splitit_default_order_status_auto_capture_on']['options'] ) ) {
     4846                                        $saved_auto_capture_off_status = 'pending';
     4847                                    }
     4848                                    ?>
     4849
     4850                                    <select
     4851                                            class="env-select select <?php echo esc_attr( $data['class'] ); ?>"
     4852                                            name="<?php echo esc_attr( $this->get_field_key( 'splitit_default_order_status_auto_capture_off' ) ); ?>"
     4853                                            id="<?php echo esc_attr( $this->get_field_key( 'splitit_default_order_status_auto_capture_off' ) ); ?>"
     4854                                            style="<?php echo esc_attr( $data['splitit_default_order_status_auto_capture_off']['css'] ); ?>"
     4855                                        <?php disabled( $data['disabled'], true ); ?>
     4856                                        <?php echo wp_kses_post( $this->get_custom_attribute_html( $data['splitit_default_order_status_auto_capture_off'] ) ); // WPCS: XSS ok. ?>
     4857                                    >
     4858                                        <?php foreach ( (array) $data['splitit_default_order_status_auto_capture_off']['options'] as $option_key => $option_value ) : ?>
     4859                                            <?php if ( is_array( $option_value ) ) : ?>
     4860                                                <optgroup label="<?php echo esc_attr( $option_key ); ?>">
     4861                                                    <?php foreach ( $option_value as $option_key_inner => $option_value_inner ) : ?>
     4862                                                        <option
     4863                                                                value="<?php echo esc_attr( $option_key_inner ); ?>"
     4864                                                            <?php selected( (string) $option_key_inner, esc_attr( $saved_auto_capture_off_status ) ); ?>
     4865                                                        >
     4866                                                            <?php echo esc_html( $option_value_inner ); ?>
     4867                                                        </option>
     4868                                                    <?php endforeach; ?>
     4869                                                </optgroup>
     4870                                            <?php else : ?>
     4871                                                <option
     4872                                                        value="<?php echo esc_attr( $option_key ); ?>"
     4873                                                    <?php selected( (string) $option_key, esc_attr( $saved_auto_capture_off_status ) ); ?>
     4874                                                >
     4875                                                    <?php echo esc_html( $option_value ); ?>
     4876                                                </option>
     4877                                            <?php endif; ?>
     4878                                        <?php endforeach; ?>
     4879                                    </select>
     4880                                </div>
     4881                            </div>
     4882                        </div>
     4883                    </div>
     4884                    <!--end splitit_default_order_status-->
    46944885
    46954886                    <!--start splitit_inst_conf-->
     
    51705361                            $this->settings['splitit_environment'] = $this->get_field_value( 'splitit_environment', $field['splitit_environment'], $post_data );
    51715362                        } elseif ( 'Payment_Method_Settings_section' === $key ) {
    5172                             $this->settings['splitit_settings_3d']                   = $this->get_field_value( 'splitit_settings_3d', $field['splitit_settings_3d'], $post_data );
    5173                             $this->settings['splitit_auto_capture']                  = $this->get_field_value( 'splitit_auto_capture', $field['splitit_auto_capture'], $post_data );
    5174                             $this->settings['splitit_refund_strategy']               = $this->get_field_value( 'splitit_refund_strategy', $field['splitit_refund_strategy'], $post_data );
    5175                             $this->settings['splitit_upstream_default_installments'] = $this->get_field_value( 'splitit_upstream_default_installments', $field['splitit_upstream_default_installments'], $post_data );
     5363                            $this->settings['splitit_settings_3d']                           = $this->get_field_value( 'splitit_settings_3d', $field['splitit_settings_3d'], $post_data );
     5364                            $this->settings['splitit_auto_capture']                          = $this->get_field_value( 'splitit_auto_capture', $field['splitit_auto_capture'], $post_data );
     5365                            $this->settings['splitit_refund_strategy']                       = $this->get_field_value( 'splitit_refund_strategy', $field['splitit_refund_strategy'], $post_data );
     5366                            $this->settings['splitit_default_order_status_auto_capture_on']  = $this->get_field_value( 'splitit_default_order_status_auto_capture_on', $field['splitit_default_order_status_auto_capture_on'], $post_data );
     5367                            $this->settings['splitit_default_order_status_auto_capture_off'] = $this->get_field_value( 'splitit_default_order_status_auto_capture_off', $field['splitit_default_order_status_auto_capture_off'], $post_data );
     5368                            $this->settings['splitit_upstream_default_installments']         = $this->get_field_value( 'splitit_upstream_default_installments', $field['splitit_upstream_default_installments'], $post_data );
    51765369
    51775370                            if ( isset( $post_data['woocommerce_splitit_ic_from'] ) && isset( $post_data['woocommerce_splitit_ic_to'] ) && isset( $post_data['woocommerce_splitit_ic_installment'] ) ) {
     
    52015394                            $this->settings['splitit_upstream_messaging_selection'] = $this->get_field_value( 'splitit_upstream_messaging_selection', $field['splitit_upstream_messaging_selection'], $post_data );
    52025395                            $this->settings['enabled_visa']                         = $this->get_field_value( 'enabled_visa', $field['enabled_visa'], $post_data );
     5396                            $this->settings['default_installments_number']          = $this->get_field_value( 'default_installments_number', $field['default_installments_number'], $post_data );
    52035397
    52045398                            foreach ( $field['pages'] as $page_key => $page ) {
     
    54975691
    54985692                    if ( $verify_data->getIsAuthorized() ) {
    5499                         $checkout = new SplitIt_FlexFields_Payment_Plugin_Checkout();
     5693                        $checkout = new SplitIt_FlexFields_Payment_Plugin_Checkout( $this->settings );
    55005694                        $order_id = $checkout->create_checkout( $order_info );
    55015695                        $ipn_info = $api->get_ipn_info( $ipn );
     
    55045698
    55055699                        if ( 'splitit' == $order->get_payment_method() ) {
    5506                             $order->update_status( $this->settings['splitit_auto_capture'] ? 'processing' : 'pending' );
     5700                            if ( $this->settings['splitit_auto_capture'] ) {
     5701                                $new_status = isset( $this->settings['splitit_default_order_status_auto_capture_on'] ) && ! empty( $this->settings['splitit_default_order_status_auto_capture_on'] )
     5702                                    ? $this->settings['splitit_default_order_status_auto_capture_on']
     5703                                    : 'processing';
     5704                            } else {
     5705                                $new_status = isset( $this->settings['splitit_default_order_status_auto_capture_off'] ) && ! empty( $this->settings['splitit_default_order_status_auto_capture_off'] )
     5706                                    ? $this->settings['splitit_default_order_status_auto_capture_off']
     5707                                    : 'pending';
     5708                            }
     5709                            $order->update_status( $new_status );
    55075710                        }
    55085711
     
    57635966                        case 'billing_phone':
    57645967                        case 'shipping_phone':
    5765                             if ( isset( $wc_fields[ $key ]['required'] ) && $wc_fields[ $key ]['required'] && ! WC_Validation::is_phone( $value ) ) {
     5968                            if ( isset( $wc_fields[ $key ] ) && isset( $wc_fields[ $key ]['required'] ) && $wc_fields[ $key ]['required'] && ! WC_Validation::is_phone( $value ) ) {
    57665969                                $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'is not a valid phone number.', 'splitit-installment-payments' ) . '</li>';
    57675970                            }
    5768                             if ( isset( $wc_fields[ $key ]['required'] ) && $wc_fields[ $key ]['required'] && strlen( $value ) < 5 || strlen( $value ) > 14 ) {
    5769                                 $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'should be greater than 5 and less than 14 digits', 'splitit-installment-payments' ) . '</li>';
     5971                            if ( isset( $wc_fields[ $key ] ) && isset( $wc_fields[ $key ]['required'] ) && $wc_fields[ $key ]['required'] && ( strlen( $value ) < 5 || strlen( $value ) > 20 ) ) {
     5972                                $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'should be greater than 5 and less than 20 digits', 'splitit-installment-payments' ) . '</li>';
    57705973                            }
    57715974                            break;
     
    58156018                            }
    58166019                            break;
     6020
     6021                        // Compatibility with Checkout Field Editor for WooCommerce plugin.
     6022                        default:
     6023                            if ( isset( $wc_fields[ $key ] ) ) {
     6024
     6025                                if ( isset( $wc_fields[ $key ]['required'] ) && $wc_fields[ $key ]['required'] && empty( $value ) ) {
     6026                                    $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'is required.', 'splitit-installment-payments' ) . '</li>';
     6027                                }
     6028
     6029                                if ( isset( $wc_fields[ $key ]['validate'] ) && is_array( $wc_fields[ $key ]['validate'] ) ) {
     6030                                    foreach ( $wc_fields[ $key ]['validate'] as $rule ) {
     6031                                        switch ( $rule ) {
     6032                                            case 'email':
     6033                                                if ( ! is_email( $value ) ) {
     6034                                                    $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'is not a valid email.', 'splitit-installment-payments' ) . '</li>';
     6035                                                }
     6036                                                break;
     6037
     6038                                            case 'phone':
     6039                                                if ( ! WC_Validation::is_phone( $value ) ) {
     6040                                                    $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'is not a valid phone number.', 'splitit-installment-payments' ) . '</li>';
     6041                                                }
     6042                                                break;
     6043
     6044                                            case 'number':
     6045                                                if ( ! is_numeric( $value ) ) {
     6046                                                    $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'must be a number.', 'splitit-installment-payments' ) . '</li>';
     6047                                                }
     6048                                                break;
     6049
     6050                                            case 'postcode':
     6051                                                if ( ! WC_Validation::is_postcode( $value, $all_fields['billing_country'] ) || empty( $value ) ) {
     6052                                                    $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'is not a valid postcode.', 'splitit-installment-payments' ) . '</li>';
     6053                                                }
     6054                                                break;
     6055
     6056                                            case 'state':
     6057                                                $valid_states = WC()->countries->get_states( WC()->customer->get_billing_country() );
     6058                                                if ( ! empty( $valid_states ) && is_array( $valid_states ) ) {
     6059                                                    if ( empty( $value ) || ! array_key_exists( $value, $valid_states ) ) {
     6060                                                        $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'is not valid. Please enter one of the following:', 'splitit-installment-payments' ) . ' ' . implode( ', ', $valid_states ) . '</li>';
     6061                                                    }
     6062                                                }
     6063                                                break;
     6064
     6065                                            case 'url':
     6066                                                if ( ! filter_var( $value, FILTER_VALIDATE_URL ) ) {
     6067                                                    $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . __( 'is not a valid URL.', 'splitit-installment-payments' ) . '</li>';
     6068                                                }
     6069                                                break;
     6070                                        }
     6071                                    }
     6072                                }
     6073
     6074                                if ( isset( $wc_fields[ $key ]['maxlength'] ) && strlen( $value ) > $wc_fields[ $key ]['maxlength'] ) {
     6075                                    /* translators: %d is the maximum allowed number of characters */
     6076                                    $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . sprintf( __( 'should not exceed %d characters.', 'splitit-installment-payments' ), $wc_fields[ $key ]['maxlength'] ) . '</li>';
     6077                                }
     6078
     6079                                if ( isset( $wc_fields[ $key ]['minlength'] ) && strlen( $value ) < $wc_fields[ $key ]['minlength'] ) {
     6080                                    /* translators: %d is the minimum allowed number of characters */
     6081                                    $errors[] = '<li><strong>' . $wc_fields[ $key ]['label'] . '</strong> ' . sprintf( __( 'should be at least %d characters long.', 'splitit-installment-payments' ), $wc_fields[ $key ]['minlength'] ) . '</li>';
     6082                                }
     6083                            }
    58176084                    }
    58186085                }
Note: See TracChangeset for help on using the changeset viewer.