Plugin Directory

Changeset 3241888


Ignore:
Timestamp:
02/17/2025 12:16:55 PM (13 months ago)
Author:
monobank
Message:

Version 1.9.0

Location:
mono-checkout
Files:
5 edited
22 copied

Legend:

Unmodified
Added
Removed
  • mono-checkout/tags/1.9.0/includes/class.gateway.php

    r3194907 r3241888  
    4040            add_action( 'woocommerce_process_shop_order_meta', [ $this, 'admin_process_shop_order_meta' ], 50, 2);
    4141            add_action( 'woocommerce_admin_order_data_after_payment_info', [ $this, 'admin_order_data_after_payment_info' ], 50, 2);
     42            add_filter( 'woocommerce_payment_complete_order_status', [ $this, 'payment_complete_order_status' ], 50, 3);
    4243
    4344            add_action( 'admin_enqueue_scripts', [$this, 'admin_scripts'] );
     
    153154    }
    154155
     156    public function update_order_status(\WC_Order $order) {
     157        $result = $this->get_api()->update_order( $this->get_order_ref( $order->get_id() ) );
     158        $orderObj = $order;
     159        $this->process_mono_order_information( $result, $orderObj, function ($error) use ($orderObj) {
     160            if (strpos($error, 'не знайдено')) {
     161                $orderObj->set_status('failed');
     162                $orderObj->save();
     163            }
     164        } );
     165    }
     166
    155167    public function admin_display_refresh_button( $order_id ) {
    156168        if ($this->is_mono_order( $order_id ) and !$this->has_final_state( $order_id )) {
     
    178190    }
    179191
     192    public function payment_complete_order_status( $status, $orderId, \WC_Order $order ) {
     193        if ($this->is_mono_order( $orderId )) {
     194            if ($this->get_option('auto_complete_mono_orders') === 'yes') {
     195                return 'completed';
     196            }
     197        }
     198        return $status;
     199    }
     200
    180201    protected static function get_mono_order_id( $order_id ) {
    181202        return get_post_meta( $order_id, 'mono_order_id', true );
     
    302323                'default' => '3',
    303324                'description' => __( 'Number of payments for Purchase in parts.', 'mono-checkout' ),
     325            ),
     326            'auto_complete_mono_orders' => array(
     327                'title' => __( 'Automatically complete paid monocheckout orders', 'mono-checkout' ),
     328                'type' => 'checkbox',
     329                'label' => ' ',
     330                'default' => '',
     331                'description' => __( 'Paid orders will automatically be transitioned to Completed status. However "Cash on delivery" orders will not be closed automatically.', 'mono-checkout' ),
     332            ),
     333            'auto_complete_mono_cod_orders' => array(
     334                'title' => __( 'Automatically complete "Cash on delivery" orders', 'mono-checkout' ),
     335                'type' => 'checkbox',
     336                'label' => ' ',
     337                'default' => '',
     338                'description' => __( 'Orders with payment type "Cash on delivery" will automatically be transitioned to Completed status.', 'mono-checkout' ),
    304339            ),
    305340            'base_url' => array(
     
    842877                $order->set_shipping_last_name(sanitize_text_field($data['deliveryRecipientInfo']['last_name']));
    843878            }
    844             if (@$data['deliveryRecipientInfo']['phoneNumber'] and !$order->get_shipping_phone()) {
    845                 $order->set_shipping_phone(sanitize_text_field($data['deliveryRecipientInfo']['phoneNumber']));
     879            if (version_compare(WC()->version, '5.6.0', '>=')) {
     880                if (@$data['deliveryRecipientInfo']['phoneNumber'] and !$order->get_shipping_phone()) {
     881                    $order->set_shipping_phone(sanitize_text_field($data['deliveryRecipientInfo']['phoneNumber']));
     882                }
    846883            }
    847884            if (@$data['delivery_branch_address']) {
     
    897934
    898935            case 'payment_on_delivery':
    899                 $order->set_status('cash_on_delivery');
     936                if ($this->get_option('auto_complete_mono_cod_orders') === 'yes') {
     937                    $order->set_status( 'completed' );
     938                } else {
     939                    $order->set_status( 'cash_on_delivery' );
     940                }
    900941                break;
    901942            case 'success':
  • mono-checkout/tags/1.9.0/includes/class.mono.php

    r3169137 r3241888  
    44
    55class Mono {
     6
     7    const CRON_HOOK = 'mono_auto_update';
    68
    79    public static $instance;
     
    1820    {
    1921        $instance = self::get_instance();
     22
     23        // get db-version (version which was last installed).
     24        $db_plugin_version = get_option( 'mono_plugin_version', '1.0.0' );
     25
     26        // compare version if we are not in development-mode.
     27        if ( version_compare( '1.8.7', $db_plugin_version, '>' ) ) {
     28            if (!wp_next_scheduled( self::CRON_HOOK )) {
     29                wp_schedule_event( time(), 'ten_minutes', self::CRON_HOOK );
     30            }
     31        }
     32        if ( version_compare( MONO_VERSION, $db_plugin_version, '>' ) ) {
     33            update_option( 'mono_plugin_version', MONO_VERSION );
     34        }
    2035    }
    2136
     
    6479        add_filter( 'woocommerce_valid_order_statuses_for_cancel', [ $this, 'cancel_statuses' ], 10, 2 );
    6580        add_filter( 'woocommerce_valid_order_statuses_for_payment_complete', [ $this, 'complete_statuses' ], 10, 2 );
     81
     82        add_action( self::CRON_HOOK, [ $this, 'update_order_statuses' ] );
    6683
    6784        $this->setup_notifications();
     
    470487    }
    471488
     489    public function update_order_statuses() {
     490        if (function_exists('wc_get_orders')) {
     491            $statuses = [ 'not_authorized', 'not_confirmed', 'pending' ];
     492            $args     = array( 'status' => $statuses, 'limit' => - 1, 'type' => 'shop_order' );
     493            $orders   = wc_get_orders( $args );
     494            foreach ( $orders as $order ) {
     495                if (Mono_Gateway::is_mono_order_by_id($order->get_id())) {
     496                    $orig_status = $order->get_status();
     497                    $this->get_gateway()->update_order_status($order);
     498                    if ($orig_status == $order->get_status()) {
     499                        // fail order that hasn't been updated in the last 30 minutes
     500                        if (time() - $order->get_date_created()->getTimestamp() >= 1800) {
     501                            $order->set_status('failed');
     502                            $order->save();
     503                        }
     504                    }
     505                }
     506            }
     507        }
     508    }
     509
    472510    protected function render($file, $params = [])
    473511    {
     
    480518            //die('Plugin requires Woocommerce to be activated.');
    481519        }
     520
     521        if (!wp_next_scheduled( self::CRON_HOOK )) {
     522            wp_schedule_event( time(), 'ten_minutes', self::CRON_HOOK );
     523        }
     524    }
     525
     526    public static function plugin_deactivation() {
     527        $timestamp = wp_next_scheduled( self::CRON_HOOK );
     528        wp_unschedule_event( $timestamp, self::CRON_HOOK );
    482529    }
    483530
  • mono-checkout/tags/1.9.0/mono.php

    r3194907 r3241888  
    77Plugin URI: https://checkout.mono.bank/woocomerce
    88Description: модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті. Доступний функціонал: предзаповнення даних отримувача, рекомендації по доставці та оплаті, всі доступні способи оплати від monobank: еквайринг, Покупка частинами та оплата при отриманні. Має бути підключений інтернет-еквайринг від monobank
    9 Version: 1.8.6
     9Version: 1.9.0
    1010Requires at least: 5.8
    1111Requires PHP: 7.4
     
    1818if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    1919
    20 define( 'MONO_VERSION', '1.8.6' );
     20define( 'MONO_VERSION', '1.9.0' );
    2121define( 'MONO__MINIMUM_WP_VERSION', '5.8' );
    2222define( 'MONO__PLUGIN_FILE', __FILE__ );
     
    2828
    2929register_activation_hook( __FILE__, array( \mono\Mono::class, 'plugin_activation' ) );
     30register_deactivation_hook( __FILE__, array( \mono\Mono::class, 'plugin_deactivation' ) );
    3031
    3132add_filter( 'woocommerce_register_shop_order_post_statuses', function ( $order_statuses ) {
     
    4849
    4950add_action( 'plugins_loaded', [\mono\Mono::class, 'init']);
     51
     52add_filter( 'cron_schedules', function ( $schedules ) {
     53    $schedules['ten_minutes'] = array(
     54        'interval' => 600,
     55        'display'  => esc_html__( 'Every ten minutes' ), );
     56    return $schedules;
     57} );
  • mono-checkout/tags/1.9.0/readme.txt

    r3194907 r3241888  
    33Tags: mono, monobank, checkout, payment, woocommerce
    44Requires at least: 5.8
    5 Tested up to: 6.4
    6 Stable tag: 1.8.6
     5Tested up to: 6.7.2
     6Stable tag: 1.9.0
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    5454
    5555== Changelog ==
     56
     57= 1.9.0 =
     58* Періодичне оновлення статусу замовлення
     59* Автоматичне скасування замовлення в разі, якщо клієнт не завершив чекаут
     60* Виправлення сумісності з версіями WooCommerce, старшими за 5.6.0
     61* Виправлення помилки в кошику через вплив сторонніх плагінів
     62* Можливість переводити замовлення одразу у статус "Виконано" після завершення моно-чекауту
     63* Сумісність з версією WordPress 6.7.2
    5664
    5765= 1.8.6 =
  • mono-checkout/tags/1.9.0/templates/base_button.php

    r3045127 r3241888  
    1717    $attrStr.= ' height="' . intval($mono_btn_height) . '" ';
    1818}
    19 if (!$mono_product_id and $product) {
     19if (!$mono_product_id and is_object($product)) {
    2020    $mono_product_id = $product->get_id();
    2121}
  • mono-checkout/trunk/includes/class.gateway.php

    r3194907 r3241888  
    4040            add_action( 'woocommerce_process_shop_order_meta', [ $this, 'admin_process_shop_order_meta' ], 50, 2);
    4141            add_action( 'woocommerce_admin_order_data_after_payment_info', [ $this, 'admin_order_data_after_payment_info' ], 50, 2);
     42            add_filter( 'woocommerce_payment_complete_order_status', [ $this, 'payment_complete_order_status' ], 50, 3);
    4243
    4344            add_action( 'admin_enqueue_scripts', [$this, 'admin_scripts'] );
     
    153154    }
    154155
     156    public function update_order_status(\WC_Order $order) {
     157        $result = $this->get_api()->update_order( $this->get_order_ref( $order->get_id() ) );
     158        $orderObj = $order;
     159        $this->process_mono_order_information( $result, $orderObj, function ($error) use ($orderObj) {
     160            if (strpos($error, 'не знайдено')) {
     161                $orderObj->set_status('failed');
     162                $orderObj->save();
     163            }
     164        } );
     165    }
     166
    155167    public function admin_display_refresh_button( $order_id ) {
    156168        if ($this->is_mono_order( $order_id ) and !$this->has_final_state( $order_id )) {
     
    178190    }
    179191
     192    public function payment_complete_order_status( $status, $orderId, \WC_Order $order ) {
     193        if ($this->is_mono_order( $orderId )) {
     194            if ($this->get_option('auto_complete_mono_orders') === 'yes') {
     195                return 'completed';
     196            }
     197        }
     198        return $status;
     199    }
     200
    180201    protected static function get_mono_order_id( $order_id ) {
    181202        return get_post_meta( $order_id, 'mono_order_id', true );
     
    302323                'default' => '3',
    303324                'description' => __( 'Number of payments for Purchase in parts.', 'mono-checkout' ),
     325            ),
     326            'auto_complete_mono_orders' => array(
     327                'title' => __( 'Automatically complete paid monocheckout orders', 'mono-checkout' ),
     328                'type' => 'checkbox',
     329                'label' => ' ',
     330                'default' => '',
     331                'description' => __( 'Paid orders will automatically be transitioned to Completed status. However "Cash on delivery" orders will not be closed automatically.', 'mono-checkout' ),
     332            ),
     333            'auto_complete_mono_cod_orders' => array(
     334                'title' => __( 'Automatically complete "Cash on delivery" orders', 'mono-checkout' ),
     335                'type' => 'checkbox',
     336                'label' => ' ',
     337                'default' => '',
     338                'description' => __( 'Orders with payment type "Cash on delivery" will automatically be transitioned to Completed status.', 'mono-checkout' ),
    304339            ),
    305340            'base_url' => array(
     
    842877                $order->set_shipping_last_name(sanitize_text_field($data['deliveryRecipientInfo']['last_name']));
    843878            }
    844             if (@$data['deliveryRecipientInfo']['phoneNumber'] and !$order->get_shipping_phone()) {
    845                 $order->set_shipping_phone(sanitize_text_field($data['deliveryRecipientInfo']['phoneNumber']));
     879            if (version_compare(WC()->version, '5.6.0', '>=')) {
     880                if (@$data['deliveryRecipientInfo']['phoneNumber'] and !$order->get_shipping_phone()) {
     881                    $order->set_shipping_phone(sanitize_text_field($data['deliveryRecipientInfo']['phoneNumber']));
     882                }
    846883            }
    847884            if (@$data['delivery_branch_address']) {
     
    897934
    898935            case 'payment_on_delivery':
    899                 $order->set_status('cash_on_delivery');
     936                if ($this->get_option('auto_complete_mono_cod_orders') === 'yes') {
     937                    $order->set_status( 'completed' );
     938                } else {
     939                    $order->set_status( 'cash_on_delivery' );
     940                }
    900941                break;
    901942            case 'success':
  • mono-checkout/trunk/includes/class.mono.php

    r3169137 r3241888  
    44
    55class Mono {
     6
     7    const CRON_HOOK = 'mono_auto_update';
    68
    79    public static $instance;
     
    1820    {
    1921        $instance = self::get_instance();
     22
     23        // get db-version (version which was last installed).
     24        $db_plugin_version = get_option( 'mono_plugin_version', '1.0.0' );
     25
     26        // compare version if we are not in development-mode.
     27        if ( version_compare( '1.8.7', $db_plugin_version, '>' ) ) {
     28            if (!wp_next_scheduled( self::CRON_HOOK )) {
     29                wp_schedule_event( time(), 'ten_minutes', self::CRON_HOOK );
     30            }
     31        }
     32        if ( version_compare( MONO_VERSION, $db_plugin_version, '>' ) ) {
     33            update_option( 'mono_plugin_version', MONO_VERSION );
     34        }
    2035    }
    2136
     
    6479        add_filter( 'woocommerce_valid_order_statuses_for_cancel', [ $this, 'cancel_statuses' ], 10, 2 );
    6580        add_filter( 'woocommerce_valid_order_statuses_for_payment_complete', [ $this, 'complete_statuses' ], 10, 2 );
     81
     82        add_action( self::CRON_HOOK, [ $this, 'update_order_statuses' ] );
    6683
    6784        $this->setup_notifications();
     
    470487    }
    471488
     489    public function update_order_statuses() {
     490        if (function_exists('wc_get_orders')) {
     491            $statuses = [ 'not_authorized', 'not_confirmed', 'pending' ];
     492            $args     = array( 'status' => $statuses, 'limit' => - 1, 'type' => 'shop_order' );
     493            $orders   = wc_get_orders( $args );
     494            foreach ( $orders as $order ) {
     495                if (Mono_Gateway::is_mono_order_by_id($order->get_id())) {
     496                    $orig_status = $order->get_status();
     497                    $this->get_gateway()->update_order_status($order);
     498                    if ($orig_status == $order->get_status()) {
     499                        // fail order that hasn't been updated in the last 30 minutes
     500                        if (time() - $order->get_date_created()->getTimestamp() >= 1800) {
     501                            $order->set_status('failed');
     502                            $order->save();
     503                        }
     504                    }
     505                }
     506            }
     507        }
     508    }
     509
    472510    protected function render($file, $params = [])
    473511    {
     
    480518            //die('Plugin requires Woocommerce to be activated.');
    481519        }
     520
     521        if (!wp_next_scheduled( self::CRON_HOOK )) {
     522            wp_schedule_event( time(), 'ten_minutes', self::CRON_HOOK );
     523        }
     524    }
     525
     526    public static function plugin_deactivation() {
     527        $timestamp = wp_next_scheduled( self::CRON_HOOK );
     528        wp_unschedule_event( $timestamp, self::CRON_HOOK );
    482529    }
    483530
  • mono-checkout/trunk/mono.php

    r3194907 r3241888  
    77Plugin URI: https://checkout.mono.bank/woocomerce
    88Description: модуль Чекауту від monobank це спосіб автоматизувати процес оформлення покупки на вашому сайті. Доступний функціонал: предзаповнення даних отримувача, рекомендації по доставці та оплаті, всі доступні способи оплати від monobank: еквайринг, Покупка частинами та оплата при отриманні. Має бути підключений інтернет-еквайринг від monobank
    9 Version: 1.8.6
     9Version: 1.9.0
    1010Requires at least: 5.8
    1111Requires PHP: 7.4
     
    1818if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    1919
    20 define( 'MONO_VERSION', '1.8.6' );
     20define( 'MONO_VERSION', '1.9.0' );
    2121define( 'MONO__MINIMUM_WP_VERSION', '5.8' );
    2222define( 'MONO__PLUGIN_FILE', __FILE__ );
     
    2828
    2929register_activation_hook( __FILE__, array( \mono\Mono::class, 'plugin_activation' ) );
     30register_deactivation_hook( __FILE__, array( \mono\Mono::class, 'plugin_deactivation' ) );
    3031
    3132add_filter( 'woocommerce_register_shop_order_post_statuses', function ( $order_statuses ) {
     
    4849
    4950add_action( 'plugins_loaded', [\mono\Mono::class, 'init']);
     51
     52add_filter( 'cron_schedules', function ( $schedules ) {
     53    $schedules['ten_minutes'] = array(
     54        'interval' => 600,
     55        'display'  => esc_html__( 'Every ten minutes' ), );
     56    return $schedules;
     57} );
  • mono-checkout/trunk/readme.txt

    r3194907 r3241888  
    33Tags: mono, monobank, checkout, payment, woocommerce
    44Requires at least: 5.8
    5 Tested up to: 6.4
    6 Stable tag: 1.8.6
     5Tested up to: 6.7.2
     6Stable tag: 1.9.0
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    5454
    5555== Changelog ==
     56
     57= 1.9.0 =
     58* Періодичне оновлення статусу замовлення
     59* Автоматичне скасування замовлення в разі, якщо клієнт не завершив чекаут
     60* Виправлення сумісності з версіями WooCommerce, старшими за 5.6.0
     61* Виправлення помилки в кошику через вплив сторонніх плагінів
     62* Можливість переводити замовлення одразу у статус "Виконано" після завершення моно-чекауту
     63* Сумісність з версією WordPress 6.7.2
    5664
    5765= 1.8.6 =
  • mono-checkout/trunk/templates/base_button.php

    r3045127 r3241888  
    1717    $attrStr.= ' height="' . intval($mono_btn_height) . '" ';
    1818}
    19 if (!$mono_product_id and $product) {
     19if (!$mono_product_id and is_object($product)) {
    2020    $mono_product_id = $product->get_id();
    2121}
Note: See TracChangeset for help on using the changeset viewer.