From 9c0c7b09a02fc1d79f83dc9125cdbd9daef9fd9e Mon Sep 17 00:00:00 2001
From: TheJoeCoder <joe@radialbog9.uk>
Date: Sat, 27 Apr 2024 22:02:34 +0100
Subject: [PATCH] Add WooPayments and major refactor

---
 includes/class-mmawpg-admin-options.php | 430 +++++++++++++-----------
 includes/class-mmawpg-functions.php     | 392 +++++++++++----------
 2 files changed, 419 insertions(+), 403 deletions(-)

diff --git a/includes/class-mmawpg-admin-options.php b/includes/class-mmawpg-admin-options.php
index 521367c..f73cec5 100644
--- a/includes/class-mmawpg-admin-options.php
+++ b/includes/class-mmawpg-admin-options.php
@@ -1,200 +1,232 @@
-<?php
-// If this file is called directly, abort.
-if ( ! defined( 'ABSPATH' ) )
-     exit;
-
-class MMAWPG_Lite_Settings_Tab {
-
-    public static function init() {
-        add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
-        add_action( 'woocommerce_settings_tabs_mmawpg_settings_tab', __CLASS__ . '::settings_tab' );
-        add_action( 'woocommerce_update_options_mmawpg_settings_tab', __CLASS__ . '::update_settings' );
-    }
-    
-    /**
-     * @return array $settings_tabs Array of WooCommerce setting tabs
-     */
-    public static function add_settings_tab( $settings_tabs ) {
-        $settings_tabs['mmawpg_settings_tab'] = esc_html__( 'Min/Max Order Amount', 'mmawpg' );
-        return $settings_tabs;
-    }
-
-    /**
-     * @uses woocommerce_admin_fields()
-     * @uses self::get_settings()
-     */
-    public static function settings_tab() {
-        woocommerce_admin_fields( self::get_settings() );
-    }
-
-    /**
-     * @uses woocommerce_update_options()
-     * @uses self::get_settings()
-     */
-    public static function update_settings() {
-        woocommerce_update_options( self::get_settings() );
-    }
-
-    /**
-     * @return array Array of settings for @see woocommerce_admin_fields() function.
-     */
-    public static function get_settings() {
-        $mmawpg_settings_array = array(
-            'mmawpg_section_title' => array(
-                'name'     => esc_html__( 'Settings', 'mmawpg' ),
-                'type'     => 'title',
-                'id'       => 'mmawpg_section_title_settings'
-            ),
-            'mmawpg_enable' => array(
-                'name' => esc_html__( 'Enable/Disable', 'mmawpg' ),
-                'type' => 'checkbox',
-                'desc' => esc_html__( 'Enable min & max order amount for woocommerce payment gateways.', 'mmawpg' ),
-                'id'   => 'mmawpg_enable_setting',
-                'default' => 'yes',
-            ),
-            'mmawpg_error_notice_min' => array(
-                'name' => esc_html__( 'Min amount notice', 'mmawpg' ),
-                'type' => 'text',
-                'desc' => esc_html__( 'Available shortcode: [mmawpg_amount], [mmawpg_method]', 'mmawpg' ),
-                'id'   => 'mmawpg_error_notice_min',
-                'default' => esc_html__('You must spend [mmawpg_amount] to order via [mmawpg_method].', 'mmawpg' ),
-                'placeholder' => esc_html__('You must spend [mmawpg_amount] to order via [mmawpg_method]', 'mmawpg' ),
-                'desc_tip' =>  true
-            ),
-            'mmawpg_error_notice_max' => array(
-                'name' => esc_html__( 'Max amount notice', 'mmawpg' ),
-                'type' => 'text',
-                'desc' => esc_html__( 'Available shortcode: [mmawpg_amount], [mmawpg_method]', 'mmawpg' ),
-                'id'   => 'mmawpg_error_notice_max',
-                'default' => esc_html__('Maximum limit [mmawpg_amount] to order via [mmawpg_method].', 'mmawpg' ),
-                'placeholder' => esc_html__('Maximum limit [mmawpg_amount] to order via [mmawpg_method]', 'mmawpg' ),
-                'desc_tip' =>  true
-            ),
-            'mmawpg_exc_shipping' => array(
-                'name' => esc_html__( 'Exclude shipping charge', 'mmawpg' ),
-                'type' => 'checkbox',
-                'desc' => esc_html__( 'Exclude shipping charges from the total cart sum.', 'mmawpg' ),
-                'id'   => 'mmawpg_exc_shipping_crg'
-            ),
-            'mmawpg_calc_cart' => array(
-                'name' => esc_html__( 'Calculate cart amount', 'mmawpg' ),
-                'type' => 'checkbox',
-                'desc' => esc_html__( 'Enable to display the last required order amount. Example: (Min amount - Cart total).', 'mmawpg' ),
-                'id'   => 'mmawpg_calc_cart'
-            ),
-            'mmawpg_cod_min' => array(
-                'name' => esc_html__( 'Cash on delivery', 'mmawpg' ),
-                'type' => 'number',
-                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
-                'id'   => 'mmawpg_cod_min',
-                'custom_attributes'	=> array(
-					'min'	=> '0'
-				),
-                'default' => '0',
-                'placeholder' => '0'
-            ),
-            'mmawpg_cod_max' => array(
-                'type' => 'number',
-                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
-                'id'   => 'mmawpg_cod_max',
-                'custom_attributes'	=> array(
-					'min'	=> '0'
-				),
-                'default' => '0',
-                'placeholder' => '0',
-            ),
-            'mmawpg_cheque_min' => array(
-                'name' => esc_html__( 'Check payment', 'mmawpg' ),
-                'type' => 'number',
-                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
-                'id'   => 'mmawpg_cheque_min',
-                'custom_attributes'	=> array(
-					'min'	=> '0'
-				),
-                'default' => '0',
-                'placeholder' => '0'
-            ),
-            'mmawpg_cheque_max' => array(
-                'type' => 'number',
-                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
-                'id'   => 'mmawpg_cheque_max',
-                'custom_attributes'	=> array(
-					'min'	=> '0'
-				),
-                'default' => '0',
-                'placeholder' => '0',
-            ),
-            'mmawpg_bank_min' => array(
-                'name' => esc_html__( 'Direct bank transfer', 'mmawpg' ),
-                'type' => 'number',
-                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
-                'id'   => 'mmawpg_bank_min',
-                'custom_attributes'	=> array(
-					'min'	=> '0'
-				),
-                'default' => '0',
-                'placeholder' => '0',
-            ),
-            'mmawpg_bank_max' => array(
-                'type' => 'number',
-                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
-                'id'   => 'mmawpg_bank_max',
-                'custom_attributes'	=> array(
-					'min'	=> '0'
-				),
-                'default' => '0',
-                'placeholder' => '0',
-            ),
-            'mmawpg_paypal_min' => array(
-                'name' => esc_html__( 'Paypal', 'mmawpg' ),
-                'type' => 'number',
-                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
-                'id'   => 'mmawpg_paypal_min',
-                'custom_attributes'	=> array(
-					'min'	=> '0'
-				),
-                'default' => '0',
-                'placeholder' => '0',
-            ),
-            'mmawpg_paypal_max' => array(
-                'type' => 'number',
-                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
-                'id'   => 'mmawpg_paypal_max',
-                'custom_attributes'	=> array(
-					'min'	=> '0'
-				),
-                'default' => '0',
-                'placeholder' => '0',
-            ),
-            'mmawpg_stripe_min' => array(
-                'name' => esc_html__( 'Stripe(Pro feature)', 'mmawpg' ),
-                'type' => 'number',
-                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
-                'custom_attributes'	=> array(
-					'min'	=> '0',
-                    'disabled'=> 'disabled'
-				),
-                'default' => '0',
-                'placeholder' => '0',
-            ),
-            'mmawpg_stripe_max' => array(
-                'type' => 'number',
-                'desc' => 'Max amount <br> <a style="color:red" href="https://codecanyon.net/item/minimum-and-maximum-amounts-for-woocommerce-payment-gateways/25130217" target="_blank">Upgrade to pro</a>',
-                'custom_attributes'	=> array(
-					'min'	=> '0',
-                    'disabled'=> 'disabled'
-				),
-                'default' => '0',
-                'placeholder' => '0',
-            ),
-            'mmawpg_section_end' => array(
-                 'type' => 'sectionend',
-                 'id' => 'mmawpg_section_end_settings'
-            )
-        );
-
-        return apply_filters( 'mmawpg_wc_settings_tab', $mmawpg_settings_array );
-    }
-}
-
+<?php
+// If this file is called directly, abort.
+if ( ! defined( 'ABSPATH' ) )
+     exit;
+
+class MMAWPG_Lite_Settings_Tab {
+
+    public static function init() {
+        add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
+        add_action( 'woocommerce_settings_tabs_mmawpg_settings_tab', __CLASS__ . '::settings_tab' );
+        add_action( 'woocommerce_update_options_mmawpg_settings_tab', __CLASS__ . '::update_settings' );
+    }
+    
+    /**
+     * @return array $settings_tabs Array of WooCommerce setting tabs
+     */
+    public static function add_settings_tab( $settings_tabs ) {
+        $settings_tabs['mmawpg_settings_tab'] = esc_html__( 'Min/Max Order Amount', 'mmawpg' );
+        return $settings_tabs;
+    }
+
+    /**
+     * @uses woocommerce_admin_fields()
+     * @uses self::get_settings()
+     */
+    public static function settings_tab() {
+        woocommerce_admin_fields( self::get_settings() );
+    }
+
+    /**
+     * @uses woocommerce_update_options()
+     * @uses self::get_settings()
+     */
+    public static function update_settings() {
+        woocommerce_update_options( self::get_settings() );
+    }
+
+    /**
+     * @return array Array of settings for @see woocommerce_admin_fields() function.
+     */
+    public static function get_settings() {
+        $mmawpg_settings_array = array(
+            // Section title
+            'mmawpg_section_title' => array(
+                'name'     => esc_html__( 'Settings', 'mmawpg' ),
+                'type'     => 'title',
+                'id'       => 'mmawpg_section_title_settings'
+            ),
+            // Enable/Disable switch
+            'mmawpg_enable' => array(
+                'name' => esc_html__( 'Enable/Disable', 'mmawpg' ),
+                'type' => 'checkbox',
+                'desc' => esc_html__( 'Enable min & max order amount for woocommerce payment gateways.', 'mmawpg' ),
+                'id'   => 'mmawpg_enable_setting',
+                'default' => 'yes',
+            ),
+            // General Options
+            'mmawpg_error_notice_min' => array(
+                'name' => esc_html__( 'Min amount notice', 'mmawpg' ),
+                'type' => 'text',
+                'desc' => esc_html__( 'Available shortcode: [mmawpg_amount], [mmawpg_method]', 'mmawpg' ),
+                'id'   => 'mmawpg_error_notice_min',
+                'default' => esc_html__('You must spend [mmawpg_amount] to order via [mmawpg_method].', 'mmawpg' ),
+                'placeholder' => esc_html__('You must spend [mmawpg_amount] to order via [mmawpg_method]', 'mmawpg' ),
+                'desc_tip' =>  true
+            ),
+            'mmawpg_error_notice_max' => array(
+                'name' => esc_html__( 'Max amount notice', 'mmawpg' ),
+                'type' => 'text',
+                'desc' => esc_html__( 'Available shortcode: [mmawpg_amount], [mmawpg_method]', 'mmawpg' ),
+                'id'   => 'mmawpg_error_notice_max',
+                'default' => esc_html__('Maximum limit [mmawpg_amount] to order via [mmawpg_method].', 'mmawpg' ),
+                'placeholder' => esc_html__('Maximum limit [mmawpg_amount] to order via [mmawpg_method]', 'mmawpg' ),
+                'desc_tip' =>  true
+            ),
+            'mmawpg_exc_shipping' => array(
+                'name' => esc_html__( 'Exclude shipping charge', 'mmawpg' ),
+                'type' => 'checkbox',
+                'desc' => esc_html__( 'Exclude shipping charges from the total cart sum.', 'mmawpg' ),
+                'id'   => 'mmawpg_exc_shipping_crg'
+            ),
+            'mmawpg_calc_cart' => array(
+                'name' => esc_html__( 'Calculate cart amount', 'mmawpg' ),
+                'type' => 'checkbox',
+                'desc' => esc_html__( 'Enable to display the last required order amount. Example: (Min amount - Cart total).', 'mmawpg' ),
+                'id'   => 'mmawpg_calc_cart'
+            ),
+            // Payment gateways
+            // Cash On Delivery (cod)
+            'mmawpg_cod_min' => array(
+                'name' => esc_html__( 'Cash on delivery', 'mmawpg' ),
+                'type' => 'number',
+                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
+                'id'   => 'mmawpg_cod_min',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0'
+            ),
+            'mmawpg_cod_max' => array(
+                'type' => 'number',
+                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
+                'id'   => 'mmawpg_cod_max',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            // Cheque (cheque)
+            'mmawpg_cheque_min' => array(
+                'name' => esc_html__( 'Check payment', 'mmawpg' ),
+                'type' => 'number',
+                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
+                'id'   => 'mmawpg_cheque_min',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0'
+            ),
+            'mmawpg_cheque_max' => array(
+                'type' => 'number',
+                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
+                'id'   => 'mmawpg_cheque_max',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            // Direct BACS transfer (bacs)
+            'mmawpg_bacs_min' => array(
+                'name' => esc_html__( 'Direct bank transfer', 'mmawpg' ),
+                'type' => 'number',
+                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
+                'id'   => 'mmawpg_bacs_min',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            'mmawpg_bacs_max' => array(
+                'type' => 'number',
+                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
+                'id'   => 'mmawpg_bacs_max',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            // PayPal (paypal)
+            'mmawpg_paypal_min' => array(
+                'name' => esc_html__( 'Paypal', 'mmawpg' ),
+                'type' => 'number',
+                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
+                'id'   => 'mmawpg_paypal_min',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            'mmawpg_paypal_max' => array(
+                'type' => 'number',
+                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
+                'id'   => 'mmawpg_paypal_max',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            // Stripe (stripe)
+            'mmawpg_stripe_min' => array(
+                'name' => esc_html__( 'Stripe', 'mmawpg' ),
+                'type' => 'number',
+                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
+                'id'   => 'mmawpg_stripe_min',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            'mmawpg_stripe_max' => array(
+                'type' => 'number',
+                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
+                'id'   => 'mmawpg_stripe_max',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            // WooPayments (woocommerce_payments)
+            'mmawpg_woocommerce_payments_min' => array(
+                'name' => esc_html__( 'Woocommerce Payments', 'mmawpg' ),
+                'type' => 'number',
+                'desc' => esc_html__( 'Min amount', 'mmawpg' ),
+                'id'   => 'mmawpg_woocommerce_payments_min',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            'mmawpg_woocommerce_payments_max' => array(
+                'type' => 'number',
+                'desc' => esc_html__( 'Max amount', 'mmawpg' ),
+                'id'   => 'mmawpg_woocommerce_payments_max',
+                'custom_attributes'	=> array(
+                    'min'	=> '0'
+                ),
+                'default' => '0',
+                'placeholder' => '0',
+            ),
+            // end section
+            'mmawpg_section_end' => array(
+                 'type' => 'sectionend',
+                 'id' => 'mmawpg_section_end_settings'
+            )
+        );
+
+        return apply_filters( 'mmawpg_wc_settings_tab', $mmawpg_settings_array );
+    }
+}
+
 MMAWPG_Lite_Settings_Tab::init();
\ No newline at end of file
diff --git a/includes/class-mmawpg-functions.php b/includes/class-mmawpg-functions.php
index d0c6cc2..f350016 100644
--- a/includes/class-mmawpg-functions.php
+++ b/includes/class-mmawpg-functions.php
@@ -1,205 +1,189 @@
-<?php
-// If this file is called directly, abort.
-if ( ! defined( 'ABSPATH' ) )
-     exit;
-
-class MMAWPG_Lite_Functions {
-    public function __construct(){
-        // Filtering the place order button
-        add_filter( 'woocommerce_order_button_html', array($this, 'mmawpg_woo_place_order_btn_html'), 10, 1 );
-        //Ajax action
-        add_action('wp_ajax_mmawpg_ajax_action', array($this, 'mmawpg_ajax_action_callback'));
-        add_action('wp_ajax_nopriv_mmawpg_ajax_action', array($this, 'mmawpg_ajax_action_callback'));
-        //Add the error notice
-        add_action('woocommerce_review_order_before_submit', array($this, 'mmawpg_before_submit_btn'));
-    }
-    
-    // Add the custom order button.
-    public function mmawpg_woo_place_order_btn_html($place_order ) {
-        $button_text = apply_filters( 'mmawpg_order_button_text', esc_html__( 'Place order', 'mmawpg' ) );
-        
-        return '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="'.$button_text.'" data-value="'.$button_text.'" disabled="disabled">'.$button_text.'</button>'; 
-    }
-    
-    //Ajax action callback
-    public function mmawpg_ajax_action_callback(){
-        $mmawpg_payment_method = sanitize_text_field($_POST['payment_type']);
-        
-        //Get payment method title
-        switch ($mmawpg_payment_method) {
-            case 'cod':
-                $mmawpg_gateway_obj = new WC_Gateway_COD();
-                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
-                break;
-            case 'cheque':
-                $mmawpg_gateway_obj = new WC_Gateway_Cheque();
-                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
-                break;
-            case 'paypal':
-                $mmawpg_gateway_obj = new WC_Gateway_Paypal();
-                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
-                break;
-            case 'bacs':
-                $mmawpg_gateway_obj = new WC_Gateway_BACS();
-                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
-                break;
-        }
-        
-        $mmawpg_exc_shipping = get_option('mmawpg_exc_shipping_crg');
-        if($mmawpg_exc_shipping == 'yes'){
-            $GLOBALS['mmawpg_order_amount'] = WC()->cart->subtotal;
-        }else{
-            $GLOBALS['mmawpg_order_amount'] = WC()->cart->total;
-        }
-        
-        //Veriables for the minimum amount
-        $mmawpg_cod_min_amount = get_option('mmawpg_cod_min');
-        $mmawpg_cheque_min_amount = get_option('mmawpg_cheque_min');
-        $mmawpg_paypal_min_amount = get_option('mmawpg_paypal_min');
-        $mmawpg_bacs_min_amount = get_option('mmawpg_bank_min');
-        //Veriables for the maximum amount
-        $mmawpg_cod_max_amount = get_option('mmawpg_cod_max');
-        $mmawpg_cheque_max_amount = get_option('mmawpg_cheque_max');
-        $mmawpg_paypal_max_amount = get_option('mmawpg_paypal_max');
-        $mmawpg_bacs_max_amount = get_option('mmawpg_bank_max');
-        
-        switch ($mmawpg_payment_method) {
-            case 'cod':
-                if($mmawpg_cod_min_amount <= $mmawpg_cod_max_amount || $mmawpg_cod_max_amount == 0):
-                if($mmawpg_cod_min_amount != 0):
-                if($GLOBALS['mmawpg_order_amount'] < $mmawpg_cod_min_amount){
-
-                    $this->mmawpg_print_notice($mmawpg_cod_min_amount, 'min');
-                }
-                endif;
-                if($mmawpg_cod_max_amount != 0):
-                if($mmawpg_cod_max_amount < $GLOBALS['mmawpg_order_amount']){
-
-                    $this->mmawpg_print_notice($mmawpg_cod_max_amount, 'max');
-                }
-                endif;
-                endif;
-                break;
-            case 'cheque':
-                if($mmawpg_cheque_min_amount <= $mmawpg_cheque_max_amount || $mmawpg_cheque_max_amount == 0):
-                if($mmawpg_cheque_min_amount != 0):
-                if($GLOBALS['mmawpg_order_amount'] < $mmawpg_cheque_min_amount){
-
-                    $this->mmawpg_print_notice($mmawpg_cheque_min_amount, 'min');
-                }
-                endif;
-                if($mmawpg_cheque_max_amount != 0):
-                if($mmawpg_cheque_max_amount < $GLOBALS['mmawpg_order_amount']){
-
-                    $this->mmawpg_print_notice($mmawpg_cheque_max_amount, 'max');
-                }
-                endif;
-                endif;
-                break;
-            case 'paypal':
-                if($mmawpg_paypal_min_amount <= $mmawpg_paypal_max_amount || $mmawpg_paypal_max_amount == 0):
-                if($mmawpg_paypal_min_amount != 0):
-                if($GLOBALS['mmawpg_order_amount'] < $mmawpg_paypal_min_amount){
-
-                    $this->mmawpg_print_notice($mmawpg_paypal_min_amount, 'min');
-                }
-                endif;
-                if($mmawpg_paypal_max_amount != 0):
-                if($mmawpg_paypal_max_amount < $GLOBALS['mmawpg_order_amount']){
-
-                    $this->mmawpg_print_notice($mmawpg_paypal_max_amount, 'max');
-                }
-                endif;
-                endif;
-                break;
-            case 'bacs':
-                if($mmawpg_bacs_min_amount <= $mmawpg_bacs_max_amount || $mmawpg_bacs_max_amount == 0):
-                if($mmawpg_bacs_min_amount != 0):
-                if($GLOBALS['mmawpg_order_amount'] < $mmawpg_bacs_min_amount){
-                    
-                    $this->mmawpg_print_notice($mmawpg_bacs_min_amount, 'min');
-                }
-                endif;
-                if($mmawpg_bacs_max_amount != 0):
-                if($mmawpg_bacs_max_amount < $GLOBALS['mmawpg_order_amount']){
-
-                    $this->mmawpg_print_notice($mmawpg_bacs_max_amount, 'max');
-                }
-                endif;
-                endif;
-                break;
-        }
-        wp_die();
-    }
-    
-    //Display error notice
-    public function mmawpg_print_notice($mmawpg_gat_amount, $mmawpg_min_max){
-        
-        switch($mmawpg_min_max){
-            case 'min':
-                $mmawpg_calc_cart = get_option('mmawpg_calc_cart');
-                if($mmawpg_calc_cart == 'yes'){
-                    $GLOBALS['mmawpg_required_amount'] = $mmawpg_gat_amount - $GLOBALS['mmawpg_order_amount'];
-                }else{
-                    $GLOBALS['mmawpg_required_amount'] = $mmawpg_gat_amount;
-                }
-                
-                break;
-            case 'max':
-                $GLOBALS['mmawpg_required_amount'] = $mmawpg_gat_amount;
-                break;
-        }
-        //Add a shortcode to display the min/max amount.
-        add_shortcode('mmawpg_amount', 'mmawpg_amount_scode');
-        function mmawpg_amount_scode($atts, $content = null){
-            
-            ob_start();
-            $mmawpg_currency_symble = get_woocommerce_currency_symbol();
-            $mmawpg_currency_pos = get_option('woocommerce_currency_pos');
-            
-            switch($mmawpg_currency_pos){
-                case 'left':
-                    return $mmawpg_currency_symble.$GLOBALS['mmawpg_required_amount'];
-                    break;
-                case 'right':
-                    return $GLOBALS['mmawpg_required_amount'].$mmawpg_currency_symble;
-                    break;
-                case 'left_space':
-                    return $mmawpg_currency_symble.' '.$GLOBALS['mmawpg_required_amount'];
-                    break;
-                case 'right_space':
-                    return $GLOBALS['mmawpg_required_amount'].' '.$mmawpg_currency_symble;
-                    break;
-            }
-            
-            return ob_get_clean();
-        }
-        
-        //Add a shortcode to display payment method
-        add_shortcode('mmawpg_method', 'mmawpg_method_scode');
-        function mmawpg_method_scode($atts, $content = null){
-            
-            ob_start();
-            return $GLOBALS['mmawpg_payment_method_title'];
-            return ob_get_clean();
-        }
-
-        switch($mmawpg_min_max){
-            case 'min':
-            $mmawpg_notice = get_option('mmawpg_error_notice_min');
-                break;
-            case 'max':
-                $mmawpg_notice = get_option('mmawpg_error_notice_max');
-                break;
-        }
-        
-        $mmawpg_print_notice = do_shortcode("$mmawpg_notice");
-        wc_print_notice( esc_html__( $mmawpg_print_notice, 'mmawpg' ), 'error' );
-    }
-    
-    //Display error notice
-    public function mmawpg_before_submit_btn(){
-        echo '<div id="mmawpgnotice"></div>';
-    }
-}
+<?php
+// If this file is called directly, abort.
+if ( ! defined( 'ABSPATH' ) )
+     exit;
+
+class MMAWPG_Lite_Functions {
+    public function __construct(){
+        // Filtering the place order button
+        add_filter( 'woocommerce_order_button_html', array($this, 'mmawpg_woo_place_order_btn_html'), 10, 1 );
+        //Ajax action
+        add_action('wp_ajax_mmawpg_ajax_action', array($this, 'mmawpg_ajax_action_callback'));
+        add_action('wp_ajax_nopriv_mmawpg_ajax_action', array($this, 'mmawpg_ajax_action_callback'));
+        //Add the error notice
+        add_action('woocommerce_review_order_before_submit', array($this, 'mmawpg_before_submit_btn'));
+    }
+    
+    // Add the custom order button.
+    public function mmawpg_woo_place_order_btn_html($place_order ) {
+        $button_text = apply_filters( 'mmawpg_order_button_text', esc_html__( 'Place order', 'mmawpg' ) );
+        
+        return '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="'.$button_text.'" data-value="'.$button_text.'" disabled="disabled">'.$button_text.'</button>'; 
+    }
+    
+    //Ajax action callback
+    public function mmawpg_ajax_action_callback(){
+        $mmawpg_payment_method = sanitize_text_field($_POST['payment_type']);
+        
+        //Get payment method title
+        switch ($mmawpg_payment_method) {
+            case 'cod':
+                $mmawpg_gateway_obj = new WC_Gateway_COD();
+                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
+                break;
+            case 'cheque':
+                $mmawpg_gateway_obj = new WC_Gateway_Cheque();
+                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
+                break;
+            case 'paypal':
+                $mmawpg_gateway_obj = new WC_Gateway_Paypal();
+                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
+                break;
+            case 'bacs':
+                $mmawpg_gateway_obj = new WC_Gateway_BACS();
+                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
+                break;
+            case 'stripe':
+                $mmawpg_gateway_obj = new WC_Gateway_Stripe();
+                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
+                break;
+            case 'woocommerce_payments':
+                $mmawpg_gateway_obj = new WC_Payment_Gateway_WCPay();
+                $GLOBALS['mmawpg_payment_method_title'] = $mmawpg_gateway_obj->get_title();
+                break;
+        }
+        
+        $mmawpg_exc_shipping = get_option('mmawpg_exc_shipping_crg');
+        if($mmawpg_exc_shipping == 'yes'){
+            $GLOBALS['mmawpg_order_amount'] = WC()->cart->subtotal;
+        }else{
+            $GLOBALS['mmawpg_order_amount'] = WC()->cart->total;
+        }
+
+        // Variables for payment method selection
+        $mmawpg_selected_payment = false;
+        $mmawpg_selected_payment_min = 0;
+        $mmawpg_selected_payment_max = 0;
+        
+        switch ($mmawpg_payment_method) {
+            case 'cod':
+                $mmawpg_selected_payment = true;
+                $mmawpg_selected_payment_min = get_option('mmawpg_cod_min');
+                $mmawpg_selected_payment_max = get_option('mmawpg_cod_max');
+                break;
+            case 'cheque':
+                $mmawpg_selected_payment = true;
+                $mmawpg_selected_payment_min = get_option('mmawpg_cheque_min');
+                $mmawpg_selected_payment_max = get_option('mmawpg_cheque_max');
+                break;
+            case 'paypal':
+                $mmawpg_selected_payment = true;
+                $mmawpg_selected_payment_min = get_option('mmawpg_paypal_min');
+                $mmawpg_selected_payment_max = get_option('mmawpg_paypal_max');
+                break;
+            case 'bacs':
+                $mmawpg_selected_payment = true;
+                $mmawpg_selected_payment_min = get_option('mmawpg_bacs_min');
+                $mmawpg_selected_payment_max = get_option('mmawpg_bacs_max');
+                break;
+            case 'stripe':
+                $mmawpg_selected_payment = true;
+                $mmawpg_selected_payment_min = get_option('mmawpg_stripe_min');
+                $mmawpg_selected_payment_max = get_option('mmawpg_stripe_max');
+                break;
+            case 'woocommerce_payments':
+                $mmawpg_selected_payment = true;
+                $mmawpg_selected_payment_min = get_option('mmawpg_woocommerce_payments_min');
+                $mmawpg_selected_payment_max = get_option('mmawpg_woocommerce_payments_max');
+                break;
+        }
+
+        if($mmawpg_selected_payment === true) {
+            if($mmawpg_selected_payment_min <= $mmawpg_selected_payment_max || $mmawpg_selected_payment_max == 0) {
+                if ($mmawpg_selected_payment_min != 0) {
+                    if($GLOBALS['mmawpg_order_amount'] < $mmawpg_selected_payment_min){
+                        $this->mmawpg_print_notice($mmawpg_selected_payment_min, 'min');
+                    }
+                }
+                if ($mmawpg_selected_payment_max != 0) {
+                    if($mmawpg_selected_payment_max < $GLOBALS['mmawpg_order_amount']){
+                        $this->mmawpg_print_notice($mmawpg_selected_payment_max, 'max');
+                    }
+                }
+            }
+        }
+
+        wp_die();
+    }
+    
+    //Display error notice
+    public function mmawpg_print_notice($mmawpg_gat_amount, $mmawpg_min_max){
+        
+        switch($mmawpg_min_max){
+            case 'min':
+                $mmawpg_calc_cart = get_option('mmawpg_calc_cart');
+                if($mmawpg_calc_cart == 'yes'){
+                    $GLOBALS['mmawpg_required_amount'] = $mmawpg_gat_amount - $GLOBALS['mmawpg_order_amount'];
+                }else{
+                    $GLOBALS['mmawpg_required_amount'] = $mmawpg_gat_amount;
+                }
+                
+                break;
+            case 'max':
+                $GLOBALS['mmawpg_required_amount'] = $mmawpg_gat_amount;
+                break;
+        }
+        //Add a shortcode to display the min/max amount.
+        add_shortcode('mmawpg_amount', 'mmawpg_amount_scode');
+        function mmawpg_amount_scode($atts, $content = null){
+            
+            ob_start();
+            $mmawpg_currency_symble = get_woocommerce_currency_symbol();
+            $mmawpg_currency_pos = get_option('woocommerce_currency_pos');
+            
+            switch($mmawpg_currency_pos){
+                case 'left':
+                    return $mmawpg_currency_symble.$GLOBALS['mmawpg_required_amount'];
+                    break;
+                case 'right':
+                    return $GLOBALS['mmawpg_required_amount'].$mmawpg_currency_symble;
+                    break;
+                case 'left_space':
+                    return $mmawpg_currency_symble.' '.$GLOBALS['mmawpg_required_amount'];
+                    break;
+                case 'right_space':
+                    return $GLOBALS['mmawpg_required_amount'].' '.$mmawpg_currency_symble;
+                    break;
+            }
+            
+            return ob_get_clean();
+        }
+        
+        //Add a shortcode to display payment method
+        add_shortcode('mmawpg_method', 'mmawpg_method_scode');
+        function mmawpg_method_scode($atts, $content = null){
+            
+            ob_start();
+            return $GLOBALS['mmawpg_payment_method_title'];
+            return ob_get_clean();
+        }
+
+        switch($mmawpg_min_max){
+            case 'min':
+            $mmawpg_notice = get_option('mmawpg_error_notice_min');
+                break;
+            case 'max':
+                $mmawpg_notice = get_option('mmawpg_error_notice_max');
+                break;
+        }
+        
+        $mmawpg_print_notice = do_shortcode("$mmawpg_notice");
+        wc_print_notice( esc_html__( $mmawpg_print_notice, 'mmawpg' ), 'error' );
+    }
+    
+    //Display error notice
+    public function mmawpg_before_submit_btn(){
+        echo '<div id="mmawpgnotice"></div>';
+    }
+}
 new MMAWPG_Lite_Functions();
\ No newline at end of file
-- 
GitLab