<?php
if (!class_exists('ARM_membership_setup')) {

    class ARM_membership_setup {

        function __construct() {
            global $wpdb, $ARMember, $arm_slugs, $arm_global_settings;
            add_action('wp_ajax_arm_delete_single_setup', array(&$this, 'arm_delete_single_setup'));
            add_action('wp_ajax_arm_refresh_setup_items', array(&$this, 'arm_refresh_setup_items'));
            add_action('wp_ajax_arm_update_plan_form_gateway_selection', array(&$this, 'arm_update_plan_form_gateway_selection'));
            add_action('wp_ajax_arm_setup_shortcode_preview', array(&$this, 'arm_setup_shortcode_preview_func'));
            /* Membership Setup Wizard Form Shortcode Ajax Action */
            add_action('wp_ajax_arm_membership_setup_form_ajax_action', array(&$this, 'arm_membership_setup_form_ajax_action'));
            add_action('wp_ajax_nopriv_arm_membership_setup_form_ajax_action', array(&$this, 'arm_membership_setup_form_ajax_action'));
            add_action('arm_save_membership_setups', array(&$this, 'arm_save_membership_setups_func'));
            add_shortcode('arm_setup', array(&$this, 'arm_setup_shortcode_func'));
            add_shortcode('arm_setup_internal', array(&$this, 'arm_setup_shortcode_func_internal'));

            add_action('arm_before_render_membership_setup_form', array(&$this, 'arm_check_include_js_css'), 10, 2);
            add_action('wp_ajax_arm_renew_plan_action', array(&$this, 'arm_renew_update_plan_action_func'));
            add_action('wp_ajax_nopriv_arm_renew_plan_action', array(&$this, 'arm_renew_update_plan_action_func'));
            add_action('wp_ajax_arm_update_plan_action', array(&$this, 'arm_renew_update_plan_action_func'));
            add_action('wp_ajax_nopriv_arm_update_plan_action', array(&$this, 'arm_renew_update_plan_action_func'));
            add_action('wp_ajax_arm_update_card_action', array(&$this, 'arm_update_card_action_func'));
            add_action('wp_ajax_arm_membership_update_card_form_ajax_action', array(&$this, 'arm_membership_update_card_form_ajax_action'));
            
            add_action('wp', array(&$this, 'arm_membership_setup_preview_func'));
            add_action('arm_cancel_subscription_gateway_action', array(&$this, 'arm_cancel_bank_transfer_subscription'), 10, 2);
        } 

       /* function arm_after_setup_form_submit($return_script){
            $return_script = "<script type='text/javascript' data-cfasync='false'>console.log('Repute log Test after setup'); </script>";
            return $return_script;
        }*/

        function arm_renew_update_plan_action_func() {
            $plan_id = $_POST['plan_id'];
            $setup_id = $_POST['setup_id'];
            if(is_user_logged_in()) {
              echo do_shortcode('[arm_setup_internal id="' . $setup_id . '" hide_plans="1" subscription_plan="' . $plan_id . '"]');
            } else {
              global $arm_member_forms, $ARMember;
              $default_login_form_id = $arm_member_forms->arm_get_default_form_id('login');
              echo do_shortcode("[arm_form id='$default_login_form_id' is_referer='1']");
              $ARMember->enqueue_angular_script(true);
            }
            die;
        }

        function arm_cancel_bank_transfer_subscription($user_id, $plan_id) {
            global $wpdb, $ARMember, $arm_global_settings, $arm_subscription_plans, $arm_transaction, $arm_payment_gateways, $arm_manage_communication;
            if (!empty($user_id) && $user_id != 0 && !empty($plan_id) && $plan_id != 0) {
                $defaultPlanData = $arm_subscription_plans->arm_default_plan_array();
                $userPlanDatameta = get_user_meta($user_id, 'arm_user_plan_' . $plan_id, true);
                $userPlanDatameta = !empty($userPlanDatameta) ? $userPlanDatameta : array();
                $planData = shortcode_atts($defaultPlanData, $userPlanDatameta);

                $user_payment_gateway = $planData['arm_user_gateway'];

                $user_detail = get_userdata($user_id);
                $payer_email = $user_detail->user_email;

                if (in_array(strtolower($user_payment_gateway), array('bank_transfer', 'manual'))) {
                    $arm_manage_communication->arm_user_plan_status_action_mail(array('plan_id' => $plan_id, 'user_id' => $user_id, 'action' => 'on_cancel_subscription'));
                }
            }
        }

        function arm_membership_setup_preview_func() {
            global $wpdb, $ARMember;
            if (isset($_REQUEST['arm_setup_preview']) && $_REQUEST['arm_setup_preview'] == '1') {
                if (file_exists(MEMBERSHIP_VIEWS_DIR . '/arm_membership_setup_preview.php')) {
                    include(MEMBERSHIP_VIEWS_DIR . '/arm_membership_setup_preview.php');
                }
                exit;
            }
        }

        function arm_membership_setup_form_ajax_action($setup_id = 0, $post_data = array()) {

            global $wp, $wpdb, $current_user, $arm_slugs, $arm_errors, $ARMember, $arm_member_forms, $arm_global_settings, $arm_payment_gateways, $arm_manage_coupons, $arm_subscription_plans, $payment_done, $authorize_net_auth, $arm_manage_communication, $arm_transaction, $is_multiple_membership_feature;
            $authorize_net_auth = array();
            $post_data = (!empty($_POST)) ? $_POST : $post_data;

            $setup_id = (!empty($post_data['setup_id']) && $post_data['setup_id'] != 0) ? $post_data['setup_id'] : $setup_id;
            $err_msg = $arm_global_settings->common_message['arm_general_msg'];
            $err_msg = (!empty($err_msg)) ? $err_msg : __('Sorry, Something went wrong. Please try again.', 'ARMember');
            $response = array('status' => 'error', 'type' => 'message', 'message' => $err_msg);
            $validate = true;
            $validate_msgs = array();
            if (!empty($setup_id) && $setup_id != 0 && !empty($post_data) && $post_data['setup_action'] == 'membership_setup') {
                do_action('arm_before_setup_form_action', $setup_id, $post_data);
                /* Unset unused variables. */
                unset($post_data['ARMSETUPNEXT']);
                unset($post_data['ARMSETUPSUBMIT']);
                unset($post_data['setup_action']);
                $setup_data = $this->arm_get_membership_setup($setup_id);
                if (!empty($setup_data) && !empty($setup_data['setup_modules']['modules'])) {
                    $form_slug = isset($post_data['arm_action']) ? $post_data['arm_action'] : '';
                    $form = new ARM_Form('slug', $form_slug);
                    $form_id = 0;

                    $plan_id = isset($post_data['subscription_plan']) ? $post_data['subscription_plan'] : 0;
                    if ($plan_id == 0) {
                        $plan_id = isset($post_data['_subscription_plan']) ? $post_data['_subscription_plan'] : 0;
                    }

                    $plan = new ARM_Plan($plan_id);
                    $plan_type = $plan->type;
                    $payment_gateway = isset($post_data['payment_gateway']) ? $post_data['payment_gateway'] : '';
                    if ($payment_gateway == '') {
                        $payment_gateway = isset($post_data['_payment_gateway']) ? $post_data['_payment_gateway'] : '';
                    }

                    if($plan->is_recurring()){
                        $payment_mode_ = !empty($post_data['arm_selected_payment_mode']) ? $post_data['arm_selected_payment_mode'] : 'manual_subscription';
                        if(isset($post_data['arm_payment_mode'][$payment_gateway])){
                            $payment_mode_ = !empty($post_data['arm_payment_mode'][$payment_gateway]) ? $post_data['arm_payment_mode'][$payment_gateway] : 'manual_subscription';
                        }
                        else{
                            $setup_data = $this->arm_get_membership_setup($setup_id);
                            if (!empty($setup_data) && !empty($setup_data['setup_modules']['modules'])) {
                                $setup_modules = $setup_data['setup_modules'];
                                $modules = $setup_modules['modules'];
                                $payment_mode_ = $modules['payment_mode'][$payment_gateway];
                            }
                        }

                        $payment_mode = 'manual_subscription';
                        if ($payment_mode_ == 'both') {
                            $payment_mode = !empty($post_data['arm_selected_payment_mode']) ? $post_data['arm_selected_payment_mode'] : 'manual_subscription';
                        } else {
                            $payment_mode = $payment_mode_;
                        }
                    }
                    else{
                        $payment_mode = '';
                    }

                    if ($payment_gateway == 'bank_transfer' && $plan->is_recurring()) {
                        $payment_mode = 'manual_subscription';
                    }
                    $post_data['arm_selected_payment_mode'] = $payment_mode;

                    $payment_cycle = 0;
                    if ($plan->is_recurring()) {
                        $payment_cycle = isset($post_data['payment_cycle_' . $plan_id]) ? $post_data['payment_cycle_' . $plan_id] : 0;
                    }
                    $post_data['arm_selected_payment_cycle'] = $payment_cycle;

                    $user_info = wp_get_current_user();
                    $current_user_plan = array();
                    $user_id = $user_info->ID;
                    if (!empty($user_info->ID)) {
                        $entry_email = $user_info->user_email;
                        $current_user_plan = get_user_meta($user_id, 'arm_user_plan_ids', true);
                        $current_user_plan = !empty($current_user_plan) ? $current_user_plan : array();
                    } else {
                        $entry_email = $post_data['user_email'];
                    }
                    $setup_redirect = ARM_HOME_URL;
                    
                    
                    $redirection_settings = get_option('arm_redirection_settings');
                    $redirection_settings = maybe_unserialize($redirection_settings);
                    $arm_default_setup_url = (isset($redirection_settings['setup']['default']) && !empty($redirection_settings['setup']['default'])) ? $redirection_settings['setup']['default'] : ARM_HOME_URL;
                    
                    if (is_user_logged_in()) {
                        // IF same plan already exists in arm_user_plan_ids
                        if (in_array($plan_id, $current_user_plan)) {
                            
                            //renew or recurring
                            $PlanData = get_user_meta($user_id, 'arm_user_plan_' . $plan_id, true);
                            if (!empty($PlanData)) {
                                $PlanDetail = isset($PlanData['arm_current_plan_detail']) ? $PlanData['arm_current_plan_detail'] : array();
                                if (!empty($PlanData)) {
                                    $same_old_plan = new ARM_Plan(0);
                                    $same_old_plan->init((object) $PlanDetail);
                                } else {
                                    $same_old_plan = new ARM_Plan($plan_id);
                                }

                                if ($same_old_plan->is_recurring()) {
                                    $oldPaymentMode = $PlanData['arm_payment_mode'];
                                    if ($oldPaymentMode == 'manual_subscription') {

                                        $oldPaymentCycle = $PlanData['arm_payment_cycle'];
                                        $completed_recurrence = $PlanData['arm_completed_recurring'];

                                        $same_plan_data = $same_old_plan->prepare_recurring_data($oldPaymentCycle);
                                        $oldPlanTotalRecurring = $same_plan_data['rec_time'];

                                        if ($oldPlanTotalRecurring == 'infinite' || ($completed_recurrence !== '' && $completed_recurrence < $oldPlanTotalRecurring)) {
                                            $payment_cycle = $oldPaymentCycle;
                                            $post_data['arm_selected_payment_cycle'] = $oldPaymentCycle;

                                            $payment_mode = $oldPaymentMode;
                                            $post_data['arm_selected_payment_mode'] = $oldPaymentMode;

                                            $plan = $same_old_plan;
                                        }
                                    }
                                }
                            }
                            
                            $arm_redirection_setup_change_type = (isset($redirection_settings['setup_renew']['type']) && !empty($redirection_settings['setup_renew']['type'])) ? $redirection_settings['setup_renew']['type'] : 'page';
                            if($arm_redirection_setup_change_type == 'page'){
                               $arm_redirection_setup_signup_page_id = (isset($redirection_settings['setup_renew']['page_id']) && !empty($redirection_settings['setup_renew']['page_id'])) ? $redirection_settings['setup_renew']['page_id'] : 0;
                               if(!empty($arm_redirection_setup_signup_page_id)){
                                   $setup_redirect = $arm_global_settings->arm_get_permalink('', $arm_redirection_setup_signup_page_id);
                               }
                               else{
                                   $setup_redirect = $arm_default_setup_url;
                               }
                            }
                            else if($arm_redirection_setup_change_type == 'url'){
                                $setup_redirect = (isset($redirection_settings['setup_renew']['url']) && !empty($redirection_settings['setup_renew']['url'])) ? $redirection_settings['setup_renew']['url'] : $arm_default_setup_url;
                            }
                            
                        }
                        else{
                           //change
                            $arm_redirection_setup_change_type = (isset($redirection_settings['setup_change']['type']) && !empty($redirection_settings['setup_change']['type'])) ? $redirection_settings['setup_change']['type'] : 'page';
                            if($arm_redirection_setup_change_type == 'page'){
                               $arm_redirection_setup_signup_page_id = (isset($redirection_settings['setup_change']['page_id']) && !empty($redirection_settings['setup_change']['page_id'])) ? $redirection_settings['setup_change']['page_id'] : 0;
                               if(!empty($arm_redirection_setup_signup_page_id)){
                                   $setup_redirect = $arm_global_settings->arm_get_permalink('', $arm_redirection_setup_signup_page_id);
                               }
                               else{
                                   $setup_redirect = $arm_default_setup_url;
                               }
                            }
                            else if($arm_redirection_setup_change_type == 'url'){
                                $setup_redirect = (isset($redirection_settings['setup_change']['url']) && !empty($redirection_settings['setup_change']['url'])) ? $redirection_settings['setup_change']['url'] : $arm_default_setup_url;
                            }
                        }
                    }
                    else{
                        $arm_redirection_setup_signup_type = (isset($redirection_settings['setup_signup']['type']) && !empty($redirection_settings['setup_signup']['type'])) ? $redirection_settings['setup_signup']['type'] : 'page';
                        if($arm_redirection_setup_signup_type == 'page'){
                           $arm_redirection_setup_signup_page_id = (isset($redirection_settings['setup_signup']['page_id']) && !empty($redirection_settings['setup_signup']['page_id'])) ? $redirection_settings['setup_signup']['page_id'] : 0;
                           if(!empty($arm_redirection_setup_signup_page_id)){
                               $setup_redirect = $arm_global_settings->arm_get_permalink('', $arm_redirection_setup_signup_page_id);
                           }
                           else{
                               $setup_redirect = $arm_default_setup_url;
                           }
                        }
                        else if($arm_redirection_setup_signup_type == 'url'){
                            $setup_redirect = (isset($redirection_settings['setup_signup']['url']) && !empty($redirection_settings['setup_signup']['url'])) ? $redirection_settings['setup_signup']['url'] : $arm_default_setup_url;
                        }
                        else{
                            $signup_redirection_conditions = (isset($redirection_settings['setup_signup']['conditional_redirect']) && !empty($redirection_settings['setup_signup']['conditional_redirect'])) ? $redirection_settings['setup_signup']['conditional_redirect'] : array();
                            $arm_signup_condition_array = array();
                            if (!empty($signup_redirection_conditions)) {
                                foreach ($signup_redirection_conditions as $signup_conditions_key => $signup_conditions) {
                                    if (is_array($signup_conditions)) {
                                        $arm_signup_condition_array[$signup_conditions_key] = isset($signup_conditions['plan_id']) ? $signup_conditions['plan_id'] : 0;
                                    }
                                }
                            }

                            $arm_intersect_form_ids = array_intersect($arm_signup_condition_array, array($plan_id, -3));

                            if(!empty($arm_intersect_form_ids)){
                                foreach($arm_intersect_form_ids as $arm_signup_condition_key => $arm_signup_condition_val){
                                    $arm_setup_redirection_page_id = isset($signup_redirection_conditions[$arm_signup_condition_key]['url']) ? $signup_redirection_conditions[$arm_signup_condition_key]['url'] : 0;
                                    $setup_redirect = $arm_global_settings->arm_get_permalink('', $arm_setup_redirection_page_id);
                                    if($arm_signup_condition_val == $plan_id){
                                        break;
                                    }
                                }
                            }
                            else{
                                $setup_redirect = $arm_default_setup_url;
                            }
                        }
                    }

                    $all_global_settings = $arm_global_settings->arm_get_all_global_settings();
                    $general_settings = $all_global_settings['general_settings'];
                    $enable_tax= isset($general_settings['enable_tax']) ? $general_settings['enable_tax'] : 0;

                    if ($plan->is_recurring()) {
                        $planData = $plan->prepare_recurring_data($payment_cycle);
                        $amount = !empty($planData['amount']) ? $planData['amount'] : 0;
                    } else {
                        $amount = !empty($plan->amount) ? $plan->amount : 0;
                    }
                    $amount = str_replace(',', '', $amount);
                    $tax_percentage = 0 ;
                    $tax_values = '';
                    if($enable_tax == 1){
                        //$tax_percentage = isset($general_settings['tax_amount']) ? $general_settings['tax_amount'] : 0;
                        $tax_values = $this->arm_get_sales_tax($general_settings, $post_data, $user_id, $form->ID);
                        $tax_percentage = !empty($tax_values["tax_percentage"]) ? $tax_values["tax_percentage"] : '0';
                    }

                    $planOptions = $plan->options;

                    if ($plan_type == 'paid_finite') {
                        $plan_expiry_type = (isset($planOptions['expiry_type']) && $planOptions['expiry_type'] != '') ? $planOptions['expiry_type'] : 'joined_date_expiry';
                        $plan_expiry_date = (isset($planOptions['expiry_date']) && $planOptions['expiry_date'] != '') ? $planOptions['expiry_date'] : date('Y-m-d 23:59:59');
                    }

                    $now = current_time('timestamp');

                    $setup_name = $setup_data['setup_name'];
                    $modules = $setup_data['setup_modules']['modules'];
                   
                    $module_order = array(
                        'plans' => 1,
                        'forms' => 2,
                        'gateways' => 3,
                        'coupons' => 4,
                    );
                    $all_payment_gateways = $arm_payment_gateways->arm_get_active_payment_gateways();
                    /* ====================/.Begin Module section validation./==================== */
                    foreach ($module_order as $module => $order) {
                        if (!empty($modules[$module])) {
                            if ($module == 'forms' && !empty($form_slug)) {
                                $form_id = $form->ID;
                                $arm_form_fields = $form->fields;
                                $field_options = array();

                                foreach ($arm_form_fields as $fields) {
                                    if ($fields['arm_form_field_slug'] == 'user_login') {
                                        $field_options = $fields['arm_form_field_option'];
                                        if (isset($field_options['hide_username']) && $field_options['hide_username'] == 1) {
                                            $post_data['user_login'] = $post_data['user_email'];
                                        }
                                    }
                                }

                                $all_errors = $arm_member_forms->arm_member_validate_meta_details($form, $post_data);

                                if ($all_errors !== TRUE) {
                                    $validate = false;
                                    $validate_msgs += $all_errors;
                                }
                            }
                            if ($module == 'plans') {
                                if ($plan->exists() && $plan->is_active()) {
                                    if ($plan->is_paid() && empty($payment_gateway)) {

                                        if ($plan->is_recurring() && $plan->has_trial_period() && $payment_mode == 'manual_subscription' && $planOptions['trial']['amount'] < 1) {
                                            
                                        } else {

                                            $validate = false;
                                            $err_msg = $arm_global_settings->common_message['arm_no_select_payment_geteway'];
                                            $validate_msgs['subscription_plan'] = (!empty($err_msg)) ? $err_msg : __('Your selected plan is paid, please select payment method.', 'ARMember');
                                        }
                                    }

                                    if ($plan_type == 'paid_finite' && $plan_expiry_type == 'fixed_date_expiry') {
                                        if (strtotime($plan_expiry_date) <= $now) {
                                            $validate = false;
                                            $err_msg = $arm_global_settings->common_message['arm_invalid_plan_select'];
                                            $validate_msgs['subscription_plan'] = (!empty($err_msg)) ? $err_msg : __('Selected plan is not valid.', 'ARMember');
                                        }
                                    }
                                } else {
                                    $validate = false;
                                    $err_msg = $arm_global_settings->common_message['arm_invalid_plan_select'];
                                    $validate_msgs['subscription_plan'] = (!empty($err_msg)) ? $err_msg : __('Selected plan is not valid.', 'ARMember');
                                }
                            }
                            if ($module == 'gateways' && $plan->is_paid() && !empty($payment_gateway)) {
                                $gateway_options = $all_payment_gateways[$payment_gateway];

                                $payment_mode_bt = "";
                                if ($plan->is_recurring()) {
                                    $payment_mode_bt = 'manual_subscription';
                                } else {
                                    $payment_mode_bt = 'auto_debit_subscription';
                                }
                                if ($payment_gateway == 'bank_transfer' && $payment_mode_bt == '') {
                                    $validate = false;
                                    $validate_msgs['bank_transfer'] = __('Selected plan is not valid for bank transfer.', 'ARMember');
                                } else {
                                    $pgHasCCFields = apply_filters('arm_payment_gateway_has_ccfields', false, $payment_gateway, $gateway_options);
                                    if (in_array($payment_gateway, array('stripe', 'authorize_net')) || $pgHasCCFields) {
                                        $cc_error = array();
                                        if (empty($post_data[$payment_gateway]['card_number'])) {
                                            $err_msg = $arm_global_settings->common_message['arm_blank_credit_card_number'];
                                        }
                                        if (empty($post_data[$payment_gateway]['exp_month'])) {
                                            $err_msg = $arm_global_settings->common_message['arm_blank_expire_month'];
                                        }
                                        if (empty($post_data[$payment_gateway]['exp_year'])) {
                                            $err_msg = $arm_global_settings->common_message['arm_blank_expire_year'];
                                        }
                                        if (empty($post_data[$payment_gateway]['cvc'])) {
                                            $err_msg = $arm_global_settings->common_message['arm_blank_cvc_number'];
                                        }
                                        if (!empty($cc_error)) {
                                            $validate = false;
                                            $validate_msgs['card_number'] = implode('<br/>', $cc_error);
                                        }
                                    }
                                    if ($validate && empty($validate_msgs) && $payment_gateway == 'authorize_net' && !$plan->is_recurring() && $amount > 0) {
                                        $autho_options = $all_payment_gateways['authorize_net'];
                                        $arm_authorise_enable_debug_mode = isset($autho_options['enable_debug_mode']) ? $autho_options['enable_debug_mode'] : 0;
                                        $arm_help_link = '<a href="https://developer.authorize.net/api/reference/features/errorandresponsecodes.html" target="_blank">'.__('Click Here', 'ARMember').'</a>';
                                        global $arm_authorize_net;
                                        $arm_authorize_net->arm_LoadAuthorizeNetLibrary($autho_options);
                                        $auth = new AuthorizeNetAIM;
                                        $card_number = trim($post_data[$payment_gateway]['card_number']);
                                        $exp_month = $post_data[$payment_gateway]['exp_month'];
                                        $exp_year = $post_data[$payment_gateway]['exp_year'];
                                        $cvc = $post_data[$payment_gateway]['cvc'];
                                        
                                        if (is_user_logged_in()) { 
                                          $user_id = get_current_user_id();
                                          $user_info = get_userdata($user_id);
                                          $user_firstname = $user_info->first_name;
                                          $user_lastname = $user_info->last_name;
                                        } else {
                                          $user_firstname = isset($post_data['first_name']) ? trim($post_data['first_name']) : ( isset($post_data['user_email']) ? sanitize_user($post_data['user_email']) : '');
                                          $user_lastname = isset($post_data['last_name']) ? trim($post_data['last_name']) : ( isset($post_data['user_email']) ? sanitize_user($post_data['user_email']) : '');
                                        }

                                        if($tax_percentage > 0){
                                            $tax_amount = ($tax_percentage * $amount)/100;
                                            $tax_amount = number_format((float)$tax_amount, 2, '.', '');
                                            $amount = $amount+$tax_amount;                                           
                                        }

                                        if (strlen(trim($exp_year)) == 4) {
                                            $exp_year = substr(trim($exp_year), 2);
                                        }
                                        try {
                                            $authFields = array(
                                                'amount' => $amount,
                                                'card_num' => $card_number,
                                                'exp_date' => $exp_month . $exp_year,
                                                'card_code' => $cvc,
                                                'first_name' => $user_firstname,
                                                'last_name' => $user_lastname
                                            );
                                            if (!is_null($cvc)) {
                                                $authFields['card_code'] = $cvc;
                                            }
                                            $auth->setFields($authFields);
                                            $auth_response = $auth->authorizeOnly($amount, $card_number, $exp_month . $exp_year);
                                     
                                            if ($auth_response->approved) {
                                                /* Card is valid */
                                                $authorize_net_auth['authorization_code'] = $auth_response->authorization_code;
                                                $authorize_net_auth['transaction_id'] = $auth_response->transaction_id;
                                            } else {
                                                /* Card is Invalid */
                                                $validate = false;
                                                $actual_error = isset($auth_response->response_reason_text) ? $auth_response->response_reason_text : '';
                                                $actual_error = !empty($actual_error) ? $actual_error.' '.$arm_help_link : '';
                                                
                                                $err_msg = $arm_global_settings->common_message['arm_invalid_credit_card'];
                                                $actualmsg = ($arm_authorise_enable_debug_mode == '1') ? $actual_error : $err_msg;
                                                $validate_msgs['card_number'] = (!empty($err_msg)) ? $err_msg : __('Please enter correct card details.', 'ARMember');
                                                $validate_msgs['card_number'] = (!empty($actualmsg)) ? $actualmsg : $validate_msgs['card_number'];
                                            }
                                        } catch (Exception $e) {
                                            $validate = false;

                                            $err_msg = $arm_global_settings->common_message['arm_unauthorized_credit_card'];

                                            $error_msg = $e->getJsonBody();
                                            $actual_error = isset($error_msg['error']['message']) ? $error_msg['error']['message'] : '';
                                            $actual_error = !empty($actual_error) ? $actual_error.' '.$arm_help_link : '';
						                    
						                    $actualmsg = ($arm_authorise_enable_debug_mode == '1') ? $actual_error : $err_msg;

                                            $validate_msgs['card_number'] = (!empty($err_msg)) ? $err_msg : __('Card details could not be authorized, please use other card detail.', 'ARMember');
                                            $validate_msgs['card_number'] = (!empty($actualmsg)) ? $actualmsg : $validate_msgs['card_number'];
                                        }
                                    }
                                    $pg_errors = apply_filters('arm_validate_payment_gateway_fields', true, $post_data, $payment_gateway, $gateway_options);
                                    if ($pg_errors !== true) {
                                        $validate = false;
                                        $validate_msgs[$payment_gateway] = $pg_errors;
                                    }
                                }
                            }
                            if ($module == 'coupons' && !empty($post_data['arm_coupon_code'])) {
                                if ($arm_manage_coupons->isCouponFeature) {
                                    $check_coupon = $arm_manage_coupons->arm_apply_coupon_code($post_data['arm_coupon_code'], $plan_id, $setup_id, $payment_cycle, $current_user_plan);
                                    if ($check_coupon['status'] == 'error') {
                                        $validate = false;
                                        $validate_msgs['coupon_code'] = $check_coupon['message'];
                                    }
                                } else {
                                    $post_data['arm_coupon_code'] = $_REQUEST['arm_coupon_code'] = $_POST['arm_coupon_code'] = '';
                                }
                            }
                        }
                    }
                    /* ====================/.End Module section validation./==================== */
                    if ($validate && empty($validate_msgs)) {
                        do_action('arm_after_setup_form_validate_action', $setup_id, $post_data);
                        $entry_id = 0;
                        $ip_address = $ARMember->arm_get_ip_address();
                        $description = maybe_serialize(array('browser' => $_SERVER['HTTP_USER_AGENT'], 'http_referrer' => @$_SERVER['HTTP_REFERER']));

                        $entry_post_data = $post_data;
                        if (is_user_logged_in()) {
                            $user_information = wp_get_current_user();
                            $user_id_info = $user_information->ID;
                            $username_info = $user_information->user_login;

                            $setup_redirect = str_replace('{ARMCURRENTUSERNAME}', $username_info, $setup_redirect);
                            $setup_redirect = str_replace('{ARMCURRENTUSERID}', $user_id_info, $setup_redirect);
                        }
                        
                        $entry_post_data['setup_redirect'] = $setup_redirect;
                        foreach ($all_payment_gateways as $k => $data) {
                            if (isset($entry_post_data[$k]) && isset($entry_post_data[$k]['card_number'])) {
                                $cc_no = $entry_post_data[$k]['card_number'];
                                unset($entry_post_data[$k]);
                                if (!empty($cc_no)) {
                                    $entry_post_data[$k]['card_number'] = $arm_transaction->arm_mask_credit_card_number($cc_no);
                                }
                            }
                        }
                        
                        $entry_post_data['tax_percentage'] = $tax_percentage;
                        $entry_post_data = apply_filters('arm_add_arm_entries_value', $entry_post_data);
                        $new_entry = array(
                            'arm_entry_email' => $entry_email,
                            'arm_name' => $setup_name,
                            'arm_description' => $description,
                            'arm_ip_address' => $ip_address,
                            'arm_browser_info' => $_SERVER['HTTP_USER_AGENT'],
                            'arm_entry_value' => maybe_serialize($entry_post_data),
                            'arm_form_id' => $form_id,
                            'arm_user_id' => $user_id,
                            'arm_plan_id' => $plan_id,
                            'arm_created_date' => date('Y-m-d H:i:s')
                        );

                        $new_entry_results = $wpdb->insert($ARMember->tbl_arm_entries, $new_entry);
                        $entry_id = $wpdb->insert_id;

                        if (!empty($entry_id) && $entry_id != 0) {
                            $post_data['arm_entry_id'] = $entry_id;
                            $payment_gateway_options = isset($all_payment_gateways[$payment_gateway]) ? $all_payment_gateways[$payment_gateway] : array();
                            if (is_user_logged_in()) {
                               
                                if (!empty($modules['plans'])) {

                                    $defaultPlanData = $arm_subscription_plans->arm_default_plan_array();
                                    $userPlanDatameta = get_user_meta($user_id, 'arm_user_plan_' . $plan_id, true);
                                    $userPlanDatameta = !empty($userPlanDatameta) ? $userPlanDatameta : array();
                                    $userPlanData = shortcode_atts($defaultPlanData, $userPlanDatameta);

                                    $post_data['old_plan_id'] = (isset($current_user_plan) && !empty($current_user_plan)) ? implode(",", $current_user_plan) : 0;
                                    $old_plan_id = isset($current_user_plan[0]) ? $current_user_plan[0] : 0;
                                    $oldPlanData = get_user_meta($user_id, 'arm_user_plan_' . $old_plan_id, true);
                                    $oldPlanData = !empty($oldPlanData) ? $oldPlanData : array();
                                    $oldPlanData = shortcode_atts($defaultPlanData, $oldPlanData);
                                    $oldPlanDetail = isset($oldPlanData['arm_current_plan_detail']) ? $oldPlanData['arm_current_plan_detail'] : array();
                                    if (!empty($oldPlanDetail)) {
                                        $old_plan = new ARM_Plan(0);
                                        $old_plan->init((object) $oldPlanDetail);
                                    } else {
                                        $old_plan = new ARM_Plan($old_plan_id);
                                    }

                                    $is_update_plan = true;
                                    
                                    $now = current_time('mysql');
                                    $arm_last_payment_status = $wpdb->get_var($wpdb->prepare("SELECT `arm_transaction_status` FROM `" . $ARMember->tbl_arm_payment_log . "` WHERE `arm_user_id`=%d AND `arm_plan_id`=%d AND `arm_created_date`<=%s ORDER BY `arm_log_id` DESC LIMIT 0,1", $user_id, $plan_id, $now)); 
                                    /* If plan is being renewd */
                                    if (in_array($plan_id, $current_user_plan)) {

                                        /* if plan is recurring and old payment mode is auto debit, then if payment is done using 2checkout, old plan need to be canceled and plan renew date will be today date
                                         * In other payment gateway, plan renew date will be old ecpiry date
                                         */

                                        if (!$is_multiple_membership_feature->isMultipleMembershipFeature) {
                                            if ($old_plan->is_recurring()) {
                                                if ($payment_mode == 'auto_debit_subscription') {
                                                    $need_to_cancel_payment_gateway_array = $arm_payment_gateways->arm_need_to_cancel_old_subscription_gateways();
                                                    $need_to_cancel_payment_gateway_array = !empty($need_to_cancel_payment_gateway_array) ? $need_to_cancel_payment_gateway_array : array();
                                                    if (in_array($payment_gateway, $need_to_cancel_payment_gateway_array)) {
                                                       
                                                        do_action('arm_cancel_subscription_gateway_action', $user_id, $plan_id);
                                                    }
                                                    
                                                }
                                            }
                                        } else {
                                            if ($plan->is_recurring()) {
                                                if ($payment_mode == 'auto_debit_subscription') {
                                                    $need_to_cancel_payment_gateway_array = $arm_payment_gateways->arm_need_to_cancel_old_subscription_gateways();
                                                    $need_to_cancel_payment_gateway_array = !empty($need_to_cancel_payment_gateway_array) ? $need_to_cancel_payment_gateway_array : array();
                                                    if (in_array($payment_gateway, $need_to_cancel_payment_gateway_array)) {
                                                        do_action('arm_cancel_subscription_gateway_action', $user_id, $plan_id);
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                      
                                        /* if plan is being changed. */
                                        /* check if upgrade downgrade action is applied
                                         * if it is immmediately then, cancel old subscription if plan is recurring immediately */

                                        if (!$is_multiple_membership_feature->isMultipleMembershipFeature) {
                                            if ($old_plan->exists()) {
                                                if ($old_plan->is_lifetime() || $old_plan->is_free() || ($old_plan->is_recurring() && $plan->is_recurring())) {
                                                    $is_update_plan = true;
                                                } else {
                                                    $change_act = 'immediate';
                                                    if ($old_plan->enable_upgrade_downgrade_action == 1) {
                                                        if (!empty($old_plan->downgrade_plans) && in_array($plan->ID, $old_plan->downgrade_plans)) {
                                                            $change_act = $old_plan->downgrade_action;
                                                        }
                                                        if (!empty($old_plan->upgrade_plans) && in_array($plan->ID, $old_plan->upgrade_plans)) {
                                                            $change_act = $old_plan->upgrade_action;
                                                        }
                                                    }
                                                    $subscr_effective = $oldPlanData['arm_expire_plan'];
                                                    if ($change_act == 'on_expire' && !empty($subscr_effective)) {
                                                        $is_update_plan = false;
                                                        $oldPlanData['arm_subscr_effective'] = $subscr_effective;
                                                        $oldPlanData['arm_change_plan_to'] = $plan_id;
                                                        update_user_meta($user_id, 'arm_user_plan_' . $old_plan_id, $oldPlanData);
                                                    }
                                                }
                                                if ($is_update_plan && $old_plan->is_recurring()) {
                                                  
                                                    do_action('arm_cancel_subscription_gateway_action', $user_id, $old_plan_id);
                                                }
                                            }
                                        }
                                    }

                                    if (!$plan->is_free()) {
                                        if (!empty($payment_gateway_options)) {
                                            if ($payment_gateway == 'bank_transfer') {
                                         

                                                $payment_mode_bt = '';
                                                if ($plan->is_recurring()) {
                                                    $payment_mode_bt = "manual_subscription";
                                                }
                                                
                                                $arm_user_old_plan_details = (isset($userPlanData['arm_current_plan_detail']) && !empty($userPlanData['arm_current_plan_detail'])) ? $userPlanData['arm_current_plan_detail'] : array(); 
                                                $arm_user_old_plan_details['arm_user_old_payment_mode'] = $userPlanData['arm_payment_mode'];
                                                $userPlanData['arm_current_plan_detail'] = $arm_user_old_plan_details;
                                          
                                                update_user_meta($user_id, 'arm_user_plan_' . $plan_id, $userPlanData);    
                                                update_user_meta($user_id, 'arm_entry_id', $entry_id);

                                                if (!$plan->is_recurring() || $payment_mode_bt == 'manual_subscription') {
                                                    $arm_payment_gateways->arm_bank_transfer_payment_gateway_action($payment_gateway, $payment_gateway_options, $post_data, $entry_id);
                                                    global $payment_done;
                                                    $response['status'] = 'success';
                                                    $response['type'] = 'redirect';
                                                    
                                                   
                                                    $response['message'] = '<script data-cfasync="false" type="text/javascript" language="javascript">window.location.href="' . $setup_redirect . '"</script>';
                                                } else {
                                                    $validate_msgs['payment_failed'] = __('Selected plan is not valid for bank transfer.', 'ARMember');
                                                }
                                            } else {
                                                
                                                
                                                $post_data = apply_filters('arm_change_posted_data_before_payment_outside', $post_data, $payment_gateway, $payment_gateway_options, $entry_id);

                                               
                                                do_action('arm_payment_gateway_validation_from_setup', $payment_gateway, $payment_gateway_options, $post_data, $entry_id);
                                                global $payment_done;
                                                if (isset($payment_done['status']) && $payment_done['status'] === FALSE) {
                                                    $validate_msgs['payment_failed'] = $payment_done['error'];
                                                } else {
                                                    
                                                    
                                                    $pgs_arrays = apply_filters('arm_update_new_subscr_gateway_outside', array('stripe', 'authorize_net', '2checkout'));
                                                    $log_id = $payment_done['log_id'];
                                                    $log_detail = $wpdb->get_row("SELECT `arm_log_id`, `arm_user_id`, `arm_token`, `arm_transaction_id`, `arm_extra_vars` FROM `" . $ARMember->tbl_arm_payment_log . "` WHERE `arm_log_id`='$log_id'");
                                                    update_user_meta($user_id, 'arm_entry_id', $entry_id);

                                                    $userPlanData['arm_user_gateway'] = $payment_gateway;
                                                    $arm_user_old_plan_details = (isset($userPlanData['arm_current_plan_detail']) && !empty($userPlanData['arm_current_plan_detail'])) ? $userPlanData['arm_current_plan_detail'] : array(); 
                                                    $arm_user_old_plan_details['arm_user_old_payment_mode'] = $userPlanData['arm_payment_mode'];
                                                    $userPlanData['arm_current_plan_detail'] = $arm_user_old_plan_details;
                                                    
                                                    if ($plan->is_recurring()) {
                                                        $userPlanData['arm_payment_mode'] = $payment_mode;
                                                        $userPlanData['arm_payment_cycle'] = $payment_cycle;
                                                    } else {
                                                        $userPlanData['arm_payment_mode'] = '';
                                                        $userPlanData['arm_payment_cycle'] = '';
                                                    }

                                                    if ($payment_gateway == 'authorize_net') {
                                                        $pg_subsc_data = array('subscription_id' => $log_detail->arm_token);
                                                        $userPlanData['arm_authorize_net'] = $pg_subsc_data;
                                                        $userPlanData['arm_stripe'] = '';
                                                        $userPlanData['arm_2checkout'] = '';
                                                    } elseif ($payment_gateway == 'stripe') {
                                                        $pg_subsc_data = array('customer_id' => $log_detail->arm_token, 'transaction_id' => $log_detail->arm_transaction_id);
                                                        $userPlanData['arm_stripe'] = $pg_subsc_data;
                                                        $userPlanData['arm_authorize_net'] = '';
                                                        $userPlanData['arm_2checkout'] = '';
                                                    } elseif ($payment_gateway == '2checkout') {
                                                        $pg_subsc_data = array('sale_id' => $log_detail->arm_token, 'transaction_id' => $log_detail->arm_transaction_id);
                                                        $userPlanData['arm_2checkout'] = $pg_subsc_data;
                                                        $userPlanData['arm_authorize_net'] = '';
                                                        $userPlanData['arm_stripe'] = '';
                                                    }
                                                    update_user_meta($user_id, 'arm_user_plan_' . $plan_id, $userPlanData);
                                                    do_action('arm_update_user_meta_after_renew_outside', $user_id, $log_detail, $plan_id, $payment_gateway);

                                                    if ($is_update_plan) {
                                                        
                                                        $arm_subscription_plans->arm_update_user_subscription($user_id, $plan_id, '', true, $arm_last_payment_status);
                                                    } else {
                                                        $arm_subscription_plans->arm_add_membership_history($user_id, $plan_id, 'change_subscription');
                                                    }

                                                    if($plan->is_recurring())
                                                    {
                                                        $arm_manage_coupons->arm_coupon_apply_to_subscription($user_id, $log_detail, $payment_gateway, $userPlanData);
                                                    }
                                                    $response['status'] = 'success';
                                                    $response['type'] = 'redirect';
                                                    $response['message'] = '<script data-cfasync="false" type="text/javascript" language="javascript">window.location.href="' . $setup_redirect . '"</script>';
                                                }
                                            }
                                        } else {
                                            $err_msg = $arm_global_settings->common_message['arm_inactive_payment_gateway'];
                                            $validate_msgs['payment_gateway'] = (!empty($err_msg)) ? $err_msg : __('Payment gateway is not active, please contact site administrator.', 'ARMember');
                                            $payment_done = array('status' => FALSE);
                                        }
                                    } else {
                                        if ($is_update_plan) {
                                            $arm_subscription_plans->arm_update_user_subscription($user_id, $plan_id);
                                        } else {
                                            $arm_subscription_plans->arm_add_membership_history($user_id, $plan_id, 'change_subscription');
                                        }
                                        $response['status'] = 'success';
                                        $response['type'] = 'redirect';
                                        $response['message'] = '<script data-cfasync="false" type="text/javascript" language="javascript">window.location.href="' . $setup_redirect . '"</script>';
                                    }
                                }
                            } else {
                                if (!empty($modules['plans']) && $plan->is_paid()) {
                                    if (!empty($payment_gateway_options)) {
                                        if ($payment_gateway == 'bank_transfer') {
                                            $payment_mode_bt = "manual_subscription";
                                            if ($plan->is_recurring()) {
                                                $payment_mode_bt = "manual_subscription";
                                            }
                                            if (!$plan->is_recurring() || $payment_mode == 'manual_subscription') {
                                                $arm_payment_gateways->arm_bank_transfer_payment_gateway_action($payment_gateway, $payment_gateway_options, $post_data, $entry_id);
                                                global $payment_done;
                                                $payment_log_id = '';
                                                if($payment_done['status']==1)
                                                {
                                                    $payment_log_id = $payment_done['log_id'];
                                                }
                                                
                                                $response['status'] = 'success';
                                                $response['type'] = 'redirect';
                                                $response['message'] = '<script data-cfasync="false" type="text/javascript" language="javascript">window.location.href="' . $setup_redirect . '"</script>';
                                            } else {
                                                $validate_msgs['payment_failed'] = __('Selected plan is not valid for bank transfer.', 'ARMember');
                                            }
                                        } else {
                                            $post_data = apply_filters('arm_change_posted_data_before_payment_outside', $post_data, $payment_gateway, $payment_gateway_options, $entry_id);

                                            do_action('arm_payment_gateway_validation_from_setup', $payment_gateway, $payment_gateway_options, $post_data, $entry_id);
                                            global $payment_done;
                                            if (isset($payment_done['status']) && $payment_done['status'] === FALSE) {
                                                $validate_msgs['payment_failed'] = $payment_done['error'];
                                            }
                                        }
                                    } else {
                                        if ($plan->is_recurring() && $plan->has_trial_period() && $payment_mode == 'manual_subscription' && $planOptions['trial']['amount'] == 0) {
                                            $payment_data = array(
                                                'arm_user_id' => '0',
                                                'arm_plan_id' => (!empty($plan_id) ? $plan_id : 0),
                                                'arm_payment_gateway' => 'paypal',
                                                'arm_payment_type' => $plan->payment_type,
                                                'arm_token' => '-',
                                                'arm_payer_email' => (isset($post_data['user_email'])) ? $post_data['user_email'] : '',
                                                'arm_receiver_email' => '',
                                                'arm_transaction_id' => '-',
                                                'arm_transaction_payment_type' => $plan->payment_type,
                                                'arm_transaction_status' => 'completed',
                                                'arm_payment_mode' => $payment_mode,
                                                'arm_payment_date' => date('Y-m-d H:i:s'),
                                                'arm_amount' => 0,
                                                'arm_currency' => 'USD',
                                                'arm_coupon_code' => '',
                                                'arm_response_text' => '',
                                                'arm_extra_vars' => '',
                                                'arm_created_date' => current_time('mysql')
                                            );
                                            $payment_log_id = $arm_payment_gateways->arm_save_payment_log($payment_data);
                                            $payment_done = array('status' => TRUE, 'log_id' => $payment_log_id, 'entry_id' => $entry_id);
                                        } else {
                                            $err_msg = $arm_global_settings->common_message['arm_inactive_payment_gateway'];
                                            $validate_msgs['payment_gateway'] = (!empty($err_msg)) ? $err_msg : __('Payment gateway is not active, please contact site administrator.', 'ARMember');
                                            $payment_done = array('status' => FALSE);
                                        }
                                    }
                                } else {
                                    $payment_done = array('status' => TRUE);
                                }
                                if (!empty($modules['forms']) && $payment_done['status'] == TRUE) {
                                    if (in_array($form->type, array('registration'))) {
                                        $post_data['arm_update_user_from_profile'] = 0;
                                        $user_id = $arm_member_forms->arm_register_new_member($post_data, $form);
                                        if (is_numeric($user_id) && !is_array($user_id)) {
                                            if(!empty($payment_log_id))
                                            {
                                                $armLogTable = $ARMember->tbl_arm_bank_transfer_log;
                                                $chk_log_detail = $wpdb->get_row("SELECT `arm_log_id`, `arm_amount` FROM `{$armLogTable}` WHERE `arm_log_id`='{$payment_log_id}'");
                                                if (!empty($chk_log_detail)) {
                                                    $user_register_verification = isset($arm_global_settings->global_settings['user_register_verification']) ? $arm_global_settings->global_settings['user_register_verification'] : 'auto';
                                                    if($chk_log_detail->arm_amount==0 && $user_register_verification == 'auto')
                                                    {
                                                        $arm_transaction->arm_change_bank_transfer_status($payment_log_id, '1');
                                                    }
                                                }
                                            }
                                            
                                            if(isset($payment_done["coupon_on_each"]) && $payment_done["coupon_on_each"] == TRUE && isset($payment_done["trans_log_id"]) && $payment_done["trans_log_id"] != 0)
                                            {
                                                $log_detail = $wpdb->get_row("SELECT `arm_log_id`, `arm_user_id`, `arm_token`, `arm_transaction_id`, `arm_extra_vars` FROM `" . $ARMember->tbl_arm_payment_log . "` WHERE `arm_log_id`='".$payment_done["trans_log_id"]."'");
                                                $planData = get_user_meta($user_id, 'arm_user_plan_' . $plan_id, true);
                                                $arm_manage_coupons->arm_coupon_apply_to_subscription($user_id, $log_detail, $payment_gateway, $planData);
                                            }
                                            else if(isset($payment_done["log_id"]) && !empty($payment_done["log_id"]))
                                            {
                                                $log_detail = $wpdb->get_row("SELECT `arm_log_id`, `arm_user_id`, `arm_token`, `arm_transaction_id`, `arm_extra_vars` FROM `" . $ARMember->tbl_arm_payment_log . "` WHERE `arm_log_id`='".$payment_done["log_id"]."'");
                                                $planData = get_user_meta($user_id, 'arm_user_plan_' . $plan_id, true);
                                                $arm_manage_coupons->arm_coupon_apply_to_subscription($user_id, $log_detail, $payment_gateway, $planData);
                                            }
                                            $response['status'] = 'success';
                                            $response['type'] = 'redirect';

                                            $user_info = get_userdata($user_id);
                                            $username = $user_info->user_login;

                                            $setup_redirect = str_replace('{ARMCURRENTUSERNAME}', $username, $setup_redirect);
                                            $setup_redirect = str_replace('{ARMCURRENTUSERID}', $user_id, $setup_redirect);

                                            $response['message'] = '<script data-cfasync="false" type="text/javascript" language="javascript">window.location.href="' . $setup_redirect . '"</script>';
                                        } else {
                                            $validate_msgs['register_error'] = $arm_errors->get_error_messages('arm_reg_error');
                                        }
                                    }
                                }
                            }
                        } else {
                            $err_msg = $arm_global_settings->common_message['arm_general_msg'];
                            $validate_msgs['entry_message'] = (!empty($err_msg)) ? $err_msg : __('Sorry, Something went wrong. Please contact to site administrator.', 'ARMember');
                        }
                    }
                    if (!empty($validate_msgs)) {
                        $response['status'] = 'error';
                        $response['type'] = 'message';
                        $response['message'] = '<div class="arm_error_msg"><ul>';
                        foreach ($validate_msgs as $err) {
                            if (is_array($err)) {
                                foreach ($err as $key => $err_msg) {
                                    $response['message'] .= '<li>' . $err_msg . '</li>';
                                }
                            } else {
                                $response['message'] .= '<li>' . $err . '</li>';
                            }
                        }
                        $response['message'] .= '</ul></div>';
                    } else {

                        $response['status'] = 'success';
                        if (isset($response['type']) && $response['type'] == 'redirect') {
                            $response['message'] = $response['message'];
                        } else {
                            $response['type'] = 'message';
                            $response['message'] = '<div class="arm_success_msg"><ul><li>' . $response['message'] . '</li></ul></div>';
                        }
                    }
                }
                do_action('arm_after_setup_form_action', $setup_id, $post_data);
            }

            $arm_return_script = '';
            $response['script'] = apply_filters('arm_after_setup_submit_sucess_outside',$arm_return_script);
            if ($post_data['action'] == 'arm_membership_setup_form_ajax_action') {

                echo json_encode($response);
                exit;
            } else {
                return $response;
            }
        }

        function arm_setup_shortcode_func_internal($atts, $content = "") {

            global $wp, $wpdb, $current_user, $ARMember, $arm_member_forms, $arm_global_settings, $arm_payment_gateways, $arm_manage_coupons, $arm_subscription_plans, $bpopup_loaded, $ARMSPAMFILEURL;
            /* ====================/.Begin Set Shortcode Attributes./==================== */
            $defaults = array(
                'id' => 0, /* Membership Setup Wizard ID */
                'hide_title' => false,
                'class' => '',
                'popup' => false, /* Form will be open in popup box when options is true */
                'link_type' => 'link',
                'link_class' => '', /* /* Possible Options:- `link`, `button` */
                'link_title' => __('Click here to open Set up form', 'ARMember'), /* Default to form name */
                'popup_height' => '',
                'popup_width' => '',
                'overlay' => '0.6',
                'modal_bgcolor' => '#000000',
                'redirect_to' => '',
                'link_css' => '',
                'link_hover_css' => '',
                'is_referer' => '0',
                'preview' => false,
                'setup_data' => '',
                'subscription_plan' => 0,
                'hide_plans' => 0,
            );


            /* Extract Shortcode Attributes */
            $args = shortcode_atts($defaults, $atts, 'arm_setup');
            extract($args);
            $args['hide_title'] = ($args['hide_title'] === 'true' || $args['hide_title'] == '1') ? true : false;
            $args['popup'] = ($args['popup'] === 'true' || $args['popup'] == '1') ? true : false;
            $isPreview = ($args['preview'] === 'true' || $args['preview'] == '1') ? true : false;
            if ($args['popup']) {
                $bpopup_loaded = 1;
            }
            $completed_recurrence = '';
            $total_recurring = '';
            if ((!empty($args['id']) && $args['id'] != 0) || ($isPreview && !empty($args['setup_data']))) {

                $setupID = $args['id'];
                if ($isPreview && !empty($args['setup_data'])) {
                    $setup_data = maybe_unserialize($args['setup_data']);
                    $setup_data['arm_setup_labels'] = $setup_data['setup_labels'];
                } else {
                    $setup_data = $this->arm_get_membership_setup($setupID);
                }
                $setup_data = apply_filters('arm_setup_data_before_setup_shortcode', $setup_data, $args);
                do_action('arm_before_render_membership_setup_form', $setup_data, $args);

                if (!empty($setup_data) && !empty($setup_data['setup_modules']['modules'])) {

                    $setupRandomID = $setupID . '_' . arm_generate_random_code();
                    $global_currency = $arm_payment_gateways->arm_get_global_currency();
                    $current_user_id = get_current_user_id();
                    $current_user_plan_ids = get_user_meta($current_user_id, 'arm_user_plan_ids', true);
                    $current_user_plan_ids = !empty($current_user_plan_ids) ? $current_user_plan_ids : array();
                    $current_user_plan = '';
                    $current_plan_data = array();
                    if (!empty($current_user_plan_ids)) {
                        $current_user_plan = $current_user_plan_ids[0];
                        $current_plan_data = get_user_meta($current_user_id, 'arm_user_plan_' . $current_user_plan, true);
                    }
                    $setup_name = (!empty($setup_data['setup_name'])) ? stripslashes($setup_data['setup_name']) : '';
                    $button_labels = $setup_data['setup_labels']['button_labels'];
                    $submit_btn = (!empty($button_labels['submit'])) ? $button_labels['submit'] : __('Submit', 'ARMember');
                    $setup_modules = $setup_data['setup_modules'];
                    $user_selected_plan = isset($setup_modules['selected_plan']) ? $setup_modules['selected_plan'] : "";
                    $modules = $setup_modules['modules'];
                    $setup_style = isset($setup_modules['style']) ? $setup_modules['style'] : array();
                    $formPosition = (isset($setup_style['form_position']) && !empty($setup_style['form_position'])) ? $setup_style['form_position'] : 'left';
                    $plan_selection_area = (isset($setup_style['plan_area_position']) && !empty($setup_style['plan_area_position'])) ? $setup_style['plan_area_position'] : 'before';
                    

                    $fieldPosition = 'left';
                    $custom_css = isset($setup_modules['custom_css']) ? $setup_modules['custom_css'] : '';
                    $modules['step'] = (!empty($modules['step'])) ? $modules['step'] : array(-1);

                    if ($plan_selection_area == 'before') {
                        $module_order = array(
                            'plans' => 1,
                            'forms' => 2,
                            'note' => 3,
                            'payment_cycle' => 4,
                            'gateways' => 5,
                            'order_detail' => 6,
                        );
                    } else {
                        $module_order = array(
                            'forms' => 1,
                            'plans' => 2,
                            'note' => 3,
                            'payment_cycle' => 4,
                            'gateways' => 5,
                            'order_detail' => 6,
                        );
                    }
                    $modules['forms'] = (!empty($modules['forms']) && $modules['forms'] != 0) ? $modules['forms'] : 0;
                    $step_one_modules = $step_two_modules = '';
                    /* Check `GET` or `POST` Data */
                    /* first check if user have selected any plan than select that plan otherwise set value from options of setup */
                    if ($current_user_plan != '') {
                        $selected_plan_id = $current_user_plan;
                    } else {
                        $selected_plan_id = $user_selected_plan;
                    }
                    if (!empty($_REQUEST['subscription_plan']) && $_REQUEST['subscription_plan'] != 0) {
                        $selected_plan_id = $_REQUEST['subscription_plan'];
                    }
                    if (!empty($args['subscription_plan']) && $args['subscription_plan'] != 0) {
                        $selected_plan_id = $args['subscription_plan'];
                    }
                    $isHidePlans = false;
                    if (!empty($selected_plan_id) && $selected_plan_id != 0) {
                        if (!empty($_REQUEST['hide_plans']) && $_REQUEST['hide_plans'] == 1) {
                            $isHidePlans = true;
                        }
                        if (!empty($args['hide_plans']) && $args['hide_plans'] == 1) {
                            $isHidePlans = true;
                        }
                    }

                    $is_hide_plan_selection_area = false;
                    if (isset($setup_style['hide_plans']) && $setup_style['hide_plans'] == 1) {
                        $is_hide_plan_selection_area = true;
                    }

                    if (is_user_logged_in()) {
                        global $current_user;
                        if (!empty($current_user->data->arm_primary_status)) {
                            $current_user_status = $current_user->data->arm_primary_status;
                        } else {
                            $current_user_status = arm_get_member_status($current_user_id);
                        }
                    }
                    $selected_plan_data = array();
                    $module_html = $formStyle = $setupGoogleFonts = '';
                    $errPosCCField = 'right';
                    if (is_rtl()) {
                        $is_form_class_rtl = 'arm_form_rtl';
                    } else {
                        $is_form_class_rtl = 'arm_form_ltr';
                    }
                    $form_style_class = ' arm_shortcode_form arm_form_0 arm_form_layout_writer armf_label_placeholder armf_alignment_left armf_layout_block armf_button_position_left ' . $is_form_class_rtl;
                    $btn_style_class = ' arm_btn_style_flat ';
                    if (!empty($modules['forms'])) {
                        $form_settings = $wpdb->get_var("SELECT `arm_form_settings` FROM `" . $ARMember->tbl_arm_forms . "` WHERE `arm_form_id`='" . $modules['forms'] . "'");
                        $form_settings = (!empty($form_settings)) ? maybe_unserialize($form_settings) : array();
                    }
                    $plan_payment_cycles = array();
                    $all_global_settings = $arm_global_settings->arm_get_all_global_settings();
                    $general_settings = $all_global_settings['general_settings'];
                    $enable_tax= isset($general_settings['enable_tax']) ? $general_settings['enable_tax'] : 0;
                    $tax_percentage = 0;
                    if($enable_tax == 1) {
                        $tax_values = $this->arm_get_sales_tax($general_settings, $post_data, $current_user_id, $modules['forms']);
                        $tax_percentage = !empty($tax_values["tax_percentage"]) ? $tax_values["tax_percentage"] : '0';
                    }

                    foreach ($module_order as $module => $order) {
                        $module_content = '';
                        $arm_user_id = 0;
                        $arm_user_old_plan = 0;
                        $plan_id_array = array();
                        $arm_user_selected_payment_mode = 0;
                        $arm_user_selected_payment_cycle = 0;
                        $arm_last_payment_status = 'success';
                        switch ($module) {
                            case 'plans':
                                    if (is_user_logged_in()) {
                                      global $current_user;
                                        $arm_user_id = $current_user->ID;

                                        $user_firstname = $current_user->user_firstname;
                                        $user_lastname = $current_user->user_lastname;
                                        $user_email = $current_user->user_email;
                                        if($user_firstname != '' && $user_lastname != ''){
                                          $arm_user_firstname_lastname = $user_firstname. ' '.$user_lastname;
                                        }
                                        else{
                                          $arm_user_firstname_lastname = $user_email;
                                        }

                                        if (!empty($current_user_plan_ids)) {
                                            $plan_name_array = array();
                                            foreach ($current_user_plan_ids as $plan_id) {
                                                $planData = get_user_meta($arm_user_id, 'arm_user_plan_' . $plan_id, true);
                                                $arm_user_selected_payment_mode = $planData['arm_payment_mode'];
                                                $arm_user_current_plan_detail = $planData['arm_current_plan_detail'];
                                                $plan_name_array[] = isset($arm_user_current_plan_detail['arm_subscription_plan_name']) ? stripslashes($arm_user_current_plan_detail['arm_subscription_plan_name']) : '';
                                                $plan_id_array[] = $plan_id;

                                                $curPlanDetail = $planData['arm_current_plan_detail'];
                                                $completed_recurrence = $planData['arm_completed_recurring'];
                                                if (!empty($curPlanDetail)) {
                                                    $arm_user_old_plan_info = new ARM_Plan(0);
                                                    $arm_user_old_plan_info->init((object) $curPlanDetail);
                                                } else {
                                                    $arm_user_old_plan_info = new ARM_Plan($arm_user_old_plan);
                                                }
                                                $total_recurring = '';
                                                $arm_user_old_plan_options = $arm_user_old_plan_info->options;
                                                if ($arm_user_old_plan_info->is_recurring()) {
                                                    $arm_user_selected_payment_cycle = $planData['arm_payment_cycle'];
                                                    $arm_user_old_plan_data = $arm_user_old_plan_info->prepare_recurring_data($arm_user_selected_payment_cycle);
                                                    $total_recurring = $arm_user_old_plan_data['rec_time'];

                                                    $now = current_time('mysql');
                                                    $arm_last_payment_status = $wpdb->get_var($wpdb->prepare("SELECT `arm_transaction_status` FROM `" . $ARMember->tbl_arm_payment_log . "` WHERE `arm_user_id`=%d AND `arm_plan_id`=%d AND `arm_created_date`<=%s ORDER BY `arm_log_id` DESC LIMIT 0,1", $arm_user_id, $plan_id, $now)); 
                                                }



                                                $module_content .= '<input type="hidden" data-id="arm_user_firstname_lastname" value="' . $arm_user_firstname_lastname . '">';
                                                $module_content .= '<input type="hidden" data-id="arm_user_last_payment_status_' . $plan_id . '" value="' . $arm_last_payment_status . '">';
                                                $module_content .= '<input type="hidden" data-id="arm_user_done_payment_' . $plan_id . '" value="' . $completed_recurrence . '">';
                                                $module_content .= '<input type="hidden" data-id="arm_user_old_plan_total_cycle_' . $plan_id . '" value="' . $total_recurring . '">';

                                                $module_content .= '<input type="hidden" data-id="arm_user_selected_payment_cycle_' . $plan_id . '" value="' . $arm_user_selected_payment_cycle . '">';
                                                $module_content .= '<input type="hidden" data-id="arm_user_selected_payment_mode_' . $plan_id . '" value="' . $arm_user_selected_payment_mode . '">';
                                            }
                                        }
                                        $arm_is_user_logged_in_flag = 1;
                                    } else {
                                        $arm_is_user_logged_in_flag = 0;
                                    }

                                    if (!empty($plan_id_array)) {
                                        $arm_user_old_plan = implode(",", $plan_id_array);
                                    }

                                    $module_content .= '<input type="hidden" data-id="arm_user_old_plan" name="arm_user_old_plan" value="' . $arm_user_old_plan . '">';
                                    $module_content .= '<input type="hidden" name="arm_is_user_logged_in_flag" data-id="arm_is_user_logged_in_flag" value="' . $arm_is_user_logged_in_flag . '">';

                                    $all_active_plans = $arm_subscription_plans->arm_get_all_active_subscription_plans();
                                    $plans = array_keys($all_active_plans);
                                    if (!empty($plans)) {

                                        $is_hide_class = '';
                                        if ($isHidePlans == true || $is_hide_plan_selection_area == true) {
                                            $is_hide_class = 'style="display:none;"';
                                        }
                                        $form_no = '';

                                        $form_layout = '';
                                        if (!empty($modules['forms']) && $modules['forms'] != 0) {
                                            if (!empty($form_settings)) {
                                                $form_no = 'arm_form_' . $modules['forms'];
                                                $form_layout = ' arm_form_layout_' . $form_settings['style']['form_layout'];
                                            }
                                        }
                                        if (!empty($current_user_plan_ids)) {

                                            $module_content .= '<div class="arm_current_user_plan_info">' . __('Your Current Membership', 'ARMember') . ': <span>' . implode(", ", $plan_name_array) . '</span></div>';
                                        }
                                        $module_content .= '<div class="arm_module_plans_container arm_module_box ' . $form_no . ' ' . $form_layout . '" ' . $is_hide_class . '>';

                                        
                                        $column_type = (!empty($setup_modules['plans_columns'])) ? $setup_modules['plans_columns'] : '1';
                                        $module_content .= '<input type="hidden" name="arm_front_plan_skin_type" data-id="arm_front_plan_skin_type" value="' . $setup_style['plan_skin'] . '">';
                                        $allowed_payment_gateways = array();
                                        if ($setup_style['plan_skin'] == 'skin5') {
                                            $planSkinFloat = "float:none;";
                                            switch ($formPosition) {
                                                case 'left':
                                                    $planSkinFloat = "";
                                                    break;
                                                case 'right':
                                                    $planSkinFloat = "float:right;";
                                                    break;
                                            }
                                            $module_content .= '<div class="arm_form_input_container arm_container payment_plan_dropdown_skin1" style="' . $planSkinFloat . '">';
                                            $module_content .= '<div class="payment_plan_dropdown_skin">';
                                            $module_content .= '<md-select name="subscription_plan" class="arm_module_plan_input select_skin" data-ng-model="subscription_plan" aria-label="plan" ng-change="armPlanChange(\'arm_setup_form' . $setupRandomID . '\')">';
                                            $i = 0;

                                            foreach ($plans as $plan_id) {
                                                if (isset($all_active_plans[$plan_id])) {

                                                    $plan_data = $all_active_plans[$plan_id];
                                                    $planObj = new ARM_Plan(0);
                                                    $planObj->init((object) $plan_data);
                                                    $plan_type = $planObj->type;
                                                    $planText = $planObj->setup_plan_text();
                                                    if ($planObj->exists()) {
                                                        /* Checked Plan Radio According Settings. */
                                                        $plan_checked = $plan_checked_class = '';
                                                        if (!empty($selected_plan_id) && $selected_plan_id != 0 && in_array($selected_plan_id, $plans)) {
                                                            if ($selected_plan_id == $plan_id) {
                                                                $plan_checked_class = 'arm_active';
                                                                $plan_checked = 'selected="selected"';
                                                                $selected_plan_data = $plan_data;
                                                            }
                                                        } else {
                                                            if ($i == 0) {
                                                                $plan_checked_class = 'arm_active';
                                                                $plan_checked = 'selected="selected"';
                                                                $selected_plan_data = $plan_data;
                                                            }
                                                        }

                                                        /* Check Recurring Details */
                                                        $plan_options = $planObj->options;

                                                        if (is_user_logged_in()) {
                                                            if ($arm_user_old_plan == $plan_id) {
                                                                $arm_user_payment_cycles = (isset($arm_user_old_plan_options['payment_cycles']) && !empty($arm_user_old_plan_options['payment_cycles'])) ? $arm_user_old_plan_options['payment_cycles'] : array();
                                                                if (empty($arm_user_payment_cycles)) {
                                                                    $plan_amount = $planObj->amount;
                                                                    $recurring_time = isset($arm_user_old_plan_options['recurring']['time']) ? $arm_user_old_plan_options['recurring']['time'] : 'infinite';
                                                                    $recurring_type = isset($arm_user_old_plan_options['recurring']['type']) ? $arm_user_old_plan_options['recurring']['type'] : 'D';
                                                                    switch ($recurring_type) {
                                                                        case 'D':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['days']) ? $arm_user_old_plan_options['recurring']['days'] : '1';
                                                                            break;
                                                                        case 'M':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['months']) ? $arm_user_old_plan_options['recurring']['months'] : '1';
                                                                            break;
                                                                        case 'Y':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['years']) ? $arm_user_old_plan_options['recurring']['years'] : '1';
                                                                            break;
                                                                        default:
                                                                            $billing_cycle = '1';
                                                                            break;
                                                                    }
                                                                    $payment_cycles = array(array(
                                                                            'cycle_label' => $planObj->plan_text(false, false),
                                                                            'cycle_amount' => $plan_amount,
                                                                            'billing_cycle' => $billing_cycle,
                                                                            'billing_type' => $recurring_type,
                                                                            'recurring_time' => $recurring_time,
                                                                            'payment_cycle_order' => 1,
                                                                    ));
                                                                    $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                } else {
                                                                    if ( ($completed_recurrence == $total_recurring && $total_recurring!="infinite" ) || ($completed_recurrence == '' && $arm_user_selected_payment_mode == 'auto_debit_subscription')) {
                                                                        $arm_user_new_payment_cycles = (isset($plan_options['payment_cycles']) && !empty($plan_options['payment_cycles'])) ? $plan_options['payment_cycles'] : array();
                                                                        $plan_payment_cycles[$plan_id] = $arm_user_new_payment_cycles;
                                                                    } else {
                                                                        $plan_payment_cycles[$plan_id] = $arm_user_payment_cycles;
                                                                    }
                                                                }
                                                            } else {
                                                                if ($planObj->is_recurring()) {
                                                                    if (!empty($plan_options['payment_cycles'])) {
                                                                        $plan_payment_cycles[$plan_id] = $plan_options['payment_cycles'];
                                                                    } else {

                                                                        $plan_amount = $planObj->amount;
                                                                        $recurring_time = isset($plan_options['recurring']['time']) ? $plan_options['recurring']['time'] : 'infinite';
                                                                        $recurring_type = isset($plan_options['recurring']['type']) ? $plan_options['recurring']['type'] : 'D';
                                                                        switch ($recurring_type) {
                                                                            case 'D':
                                                                                $billing_cycle = isset($plan_options['recurring']['days']) ? $plan_options['recurring']['days'] : '1';
                                                                                break;
                                                                            case 'M':
                                                                                $billing_cycle = isset($plan_options['recurring']['months']) ? $plan_options['recurring']['months'] : '1';
                                                                                break;
                                                                            case 'Y':
                                                                                $billing_cycle = isset($plan_options['recurring']['years']) ? $plan_options['recurring']['years'] : '1';
                                                                                break;
                                                                            default:
                                                                                $billing_cycle = '1';
                                                                                break;
                                                                        }
                                                                        $payment_cycles = array(array(
                                                                                'cycle_label' => $planObj->plan_text(false, false),
                                                                                'cycle_amount' => $plan_amount,
                                                                                'billing_cycle' => $billing_cycle,
                                                                                'billing_type' => $recurring_type,
                                                                                'recurring_time' => $recurring_time,
                                                                                'payment_cycle_order' => 1,
                                                                        ));
                                                                        $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                    }
                                                                }
                                                            }
                                                        } else {
                                                            if ($planObj->is_recurring()) {
                                                                if (!empty($plan_options['payment_cycles'])) {
                                                                    $plan_payment_cycles[$plan_id] = $plan_options['payment_cycles'];
                                                                } else {
                                                                    $plan_amount = $planObj->amount;
                                                                    $recurring_time = isset($plan_options['recurring']['time']) ? $plan_options['recurring']['time'] : 'infinite';
                                                                    $recurring_type = isset($plan_options['recurring']['type']) ? $plan_options['recurring']['type'] : 'D';
                                                                    switch ($recurring_type) {
                                                                        case 'D':
                                                                            $billing_cycle = isset($plan_options['recurring']['days']) ? $plan_options['recurring']['days'] : '1';
                                                                            break;
                                                                        case 'M':
                                                                            $billing_cycle = isset($plan_options['recurring']['months']) ? $plan_options['recurring']['months'] : '1';
                                                                            break;
                                                                        case 'Y':
                                                                            $billing_cycle = isset($plan_options['recurring']['years']) ? $plan_options['recurring']['years'] : '1';
                                                                            break;
                                                                        default:
                                                                            $billing_cycle = '1';
                                                                            break;
                                                                    }
                                                                    $payment_cycles = array(array(
                                                                            'cycle_label' => $planObj->plan_text(false, false),
                                                                            'cycle_amount' => $plan_amount,
                                                                            'billing_cycle' => $billing_cycle,
                                                                            'billing_type' => $recurring_type,
                                                                            'recurring_time' => $recurring_time,
                                                                            'payment_cycle_order' => 1,
                                                                    ));
                                                                    $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                }
                                                            }
                                                        }

                                                        $payment_type = $planObj->payment_type;
                                                        $is_trial = '0';
                                                        $trial_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency, 0);
                                                        if ($planObj->is_recurring()) {
                                                            $stripePlans = (isset($modules['stripe_plans']) && !empty($modules['stripe_plans'])) ? $modules['stripe_plans'] : array();

                                                            if ($planObj->has_trial_period()) {
                                                                $is_trial = '1';
                                                                $trial_amount = !empty($plan_options['trial']['amount']) ?
                                                                        $arm_payment_gateways->arm_amount_set_separator($global_currency, $plan_options['trial']['amount']) : $trial_amount;
                                                                if (is_user_logged_in()) {
                                                                    if (!empty($current_user_plan_ids)) {
                                                                        if (in_array($planObj->ID, $current_user_plan_ids)) {
                                                                            $is_trial = '0';
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        if (!$planObj->is_free()) {
                                                            $trial_amount = !empty($plan_options['trial']['amount']) ? $arm_payment_gateways->arm_amount_set_separator($global_currency, $plan_options['trial']['amount']) : $trial_amount;
                                                        }

                                                        $allowed_payment_gateways_['paypal'] = "1";
                                                        $allowed_payment_gateways_['stripe'] = "1";
                                                        $allowed_payment_gateways_['bank_transfer'] = "1";
                                                        $allowed_payment_gateways_['2checkout'] = "1";
                                                        $allowed_payment_gateways_['authorize_net'] = "1";
                                                        $allowed_payment_gateways_ = apply_filters('arm_allowed_payment_gateways', $allowed_payment_gateways_, $planObj, $plan_options);

                                                        $data_allowed_payment_gateways = json_encode($allowed_payment_gateways_);

                                                        $arm_plan_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency, $planObj->amount);
                                                        $planInputAttr = ' data-type="' . $plan_type . '" data-plan_name="' . $planObj->name . '" data-amt="' . $arm_plan_amount . '" data-recurring="' . $payment_type . '" data-is_trial="' . $is_trial . '" data-trial_amt="' . $trial_amount . '" data-allowed_gateways=\'' . $data_allowed_payment_gateways . '\' data-plan_text="' . htmlentities($planText) . '"';


                                                        $count_total_cycle = 0;
                                                        if($planObj->is_recurring()){

                                                          $count_total_cycle = count($plan_payment_cycles[$plan_id]);
                                                          $planInputAttr .= '  " data-cycle="'.$count_total_cycle .'"';
                                                        }
                                                        else{
                                                          $planInputAttr .= " data-cycle='0'";
                                                        }

                                                        
                                                        
                                                        $planInputAttr .= " data-tax='".$tax_percentage."'";

                                                       
                                                        $module_content .='<md-option value="' . $plan_id . '" class="armMDOption armSelectOption' . $setup_modules['modules']['forms'] . '" ' . $planInputAttr . ' ' . $plan_checked . '>' . $planObj->name . ' (' . $planObj->plan_price(false) . ')</md-option>';
                                                        $i++;
                                                    }
                                                }
                                            }
                                            $module_content .= '</md-select>';
                                            $module_content .= '</div></div>';
                                        } 
                                        else{

                                            $module_content .= '<ul class="arm_module_plans_ul arm_column_' . $column_type . '" style="text-align:' . $formPosition . ';">';
                                            $i = 0;
                                            foreach ($plans as $plan_id) {
                                                if (isset($all_active_plans[$plan_id])) {
                                                    $plan_data = $all_active_plans[$plan_id];
                                                    $planObj = new ARM_Plan(0);
                                                    $planObj->init((object) $plan_data);
                                                    $plan_type = $planObj->type;
                                                    $planText = $planObj->setup_plan_text();
                                                    if ($planObj->exists()) {
                                                        /* Checked Plan Radio According Settings. */
                                                        $plan_checked = $plan_checked_class = '';
                                                        if (!empty($selected_plan_id) && $selected_plan_id != 0 && in_array($selected_plan_id, $plans)) {
                                                            if ($selected_plan_id == $plan_id) {
                                                                $plan_checked_class = 'arm_active';
                                                                $plan_checked = 'checked="checked"';
                                                                $selected_plan_data = $plan_data;
                                                            }
                                                        } else {
                                                            if ($i == 0) {
                                                                $plan_checked_class = 'arm_active';
                                                                $plan_checked = 'checked="checked"';
                                                                $selected_plan_data = $plan_data;
                                                            }
                                                        }
                                                        /* Check Recurring Details */
                                                        $plan_options = $planObj->options;

                                                        if (is_user_logged_in()) {
                                                            if ($arm_user_old_plan == $plan_id) {
                                                                $arm_user_payment_cycles = (isset($arm_user_old_plan_options['payment_cycles']) && !empty($arm_user_old_plan_options['payment_cycles'])) ? $arm_user_old_plan_options['payment_cycles'] : array();
                                                                if (empty($arm_user_payment_cycles)) {
                                                                    $plan_amount = $planObj->amount;
                                                                    $recurring_time = isset($arm_user_old_plan_options['recurring']['time']) ? $arm_user_old_plan_options['recurring']['time'] : 'infinite';
                                                                    $recurring_type = isset($arm_user_old_plan_options['recurring']['type']) ? $arm_user_old_plan_options['recurring']['type'] : 'D';
                                                                    switch ($recurring_type) {
                                                                        case 'D':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['days']) ? $arm_user_old_plan_options['recurring']['days'] : '1';
                                                                            break;
                                                                        case 'M':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['months']) ? $arm_user_old_plan_options['recurring']['months'] : '1';
                                                                            break;
                                                                        case 'Y':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['years']) ? $arm_user_old_plan_options['recurring']['years'] : '1';
                                                                            break;
                                                                        default:
                                                                            $billing_cycle = '1';
                                                                            break;
                                                                    }
                                                                    $payment_cycles = array(array(
                                                                            'cycle_label' => $planObj->plan_text(false, false),
                                                                            'cycle_amount' => $plan_amount,
                                                                            'billing_cycle' => $billing_cycle,
                                                                            'billing_type' => $recurring_type,
                                                                            'recurring_time' => $recurring_time,
                                                                            'payment_cycle_order' => 1,
                                                                    ));
                                                                    $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                } else {

                                                                    if (($completed_recurrence == $total_recurring && $total_recurring!="infinite" ) || ($completed_recurrence == '' && $arm_user_selected_payment_mode == 'auto_debit_subscription')) {

                                                                        $arm_user_new_payment_cycles = (isset($plan_options['payment_cycles']) && !empty($plan_options['payment_cycles'])) ? $plan_options['payment_cycles'] : array();
                                                                        $plan_payment_cycles[$plan_id] = $arm_user_new_payment_cycles;
                                                                    } else {
                                                                        $plan_payment_cycles[$plan_id] = $arm_user_payment_cycles;
                                                                    }
                                                                }
                                                            } else {
                                                                if ($planObj->is_recurring()) {
                                                                    if (!empty($plan_options['payment_cycles'])) {
                                                                        $plan_payment_cycles[$plan_id] = $plan_options['payment_cycles'];
                                                                    } else {

                                                                        $plan_amount = $planObj->amount;
                                                                        $recurring_time = isset($plan_options['recurring']['time']) ? $plan_options['recurring']['time'] : 'infinite';
                                                                        $recurring_type = isset($plan_options['recurring']['type']) ? $plan_options['recurring']['type'] : 'D';
                                                                        switch ($recurring_type) {
                                                                            case 'D':
                                                                                $billing_cycle = isset($plan_options['recurring']['days']) ? $plan_options['recurring']['days'] : '1';
                                                                                break;
                                                                            case 'M':
                                                                                $billing_cycle = isset($plan_options['recurring']['months']) ? $plan_options['recurring']['months'] : '1';
                                                                                break;
                                                                            case 'Y':
                                                                                $billing_cycle = isset($plan_options['recurring']['years']) ? $plan_options['recurring']['years'] : '1';
                                                                                break;
                                                                            default:
                                                                                $billing_cycle = '1';
                                                                                break;
                                                                        }
                                                                        $payment_cycles = array(array(
                                                                                'cycle_label' => $planObj->plan_text(false, false),
                                                                                'cycle_amount' => $plan_amount,
                                                                                'billing_cycle' => $billing_cycle,
                                                                                'billing_type' => $recurring_type,
                                                                                'recurring_time' => $recurring_time,
                                                                                'payment_cycle_order' => 1,
                                                                        ));
                                                                        $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                    }
                                                                }
                                                            }
                                                        } else {
                                                            if ($planObj->is_recurring()) {
                                                                if (!empty($plan_options['payment_cycles'])) {
                                                                    $plan_payment_cycles[$plan_id] = $plan_options['payment_cycles'];
                                                                } else {
                                                                    $plan_amount = $planObj->amount;
                                                                    $recurring_time = isset($plan_options['recurring']['time']) ? $plan_options['recurring']['time'] : 'infinite';
                                                                    $recurring_type = isset($plan_options['recurring']['type']) ? $plan_options['recurring']['type'] : 'D';
                                                                    switch ($recurring_type) {
                                                                        case 'D':
                                                                            $billing_cycle = isset($plan_options['recurring']['days']) ? $plan_options['recurring']['days'] : '1';
                                                                            break;
                                                                        case 'M':
                                                                            $billing_cycle = isset($plan_options['recurring']['months']) ? $plan_options['recurring']['months'] : '1';
                                                                            break;
                                                                        case 'Y':
                                                                            $billing_cycle = isset($plan_options['recurring']['years']) ? $plan_options['recurring']['years'] : '1';
                                                                            break;
                                                                        default:
                                                                            $billing_cycle = '1';
                                                                            break;
                                                                    }
                                                                    $payment_cycles = array(array(
                                                                            'cycle_label' => $planObj->plan_text(false, false),
                                                                            'cycle_amount' => $plan_amount,
                                                                            'billing_cycle' => $billing_cycle,
                                                                            'billing_type' => $recurring_type,
                                                                            'recurring_time' => $recurring_time,
                                                                            'payment_cycle_order' => 1,
                                                                    ));
                                                                    $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                }
                                                            }
                                                        }

                                                        $payment_type = $planObj->payment_type;

                                                        $is_trial = '0';
                                                        $trial_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency, 0);

                                                        if ($planObj->is_recurring()) {
                                                            $stripePlans = (isset($modules['stripe_plans']) && !empty($modules['stripe_plans'])) ? $modules['stripe_plans'] : array();

                                                            if ($planObj->has_trial_period()) {
                                                                $is_trial = '1';
                                                                $trial_amount = !empty($plan_options['trial']['amount']) ? $arm_payment_gateways->arm_amount_set_separator($global_currency, $plan_options['trial']['amount']) : $trial_amount;
                                                                if (is_user_logged_in()) {
                                                                    if (!empty($current_user_plan_ids)) {
                                                                        if (in_array($planObj->ID, $current_user_plan_ids)) {
                                                                            $is_trial = '0';
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        $allowed_payment_gateways_['paypal'] = "1";
                                                        $allowed_payment_gateways_['stripe'] = "1";
                                                        $allowed_payment_gateways_['bank_transfer'] = "1";
                                                        $allowed_payment_gateways_['2checkout'] = "1";
                                                        $allowed_payment_gateways_['authorize_net'] = "1";
                                                        $allowed_payment_gateways_ = apply_filters('arm_allowed_payment_gateways', $allowed_payment_gateways_, $planObj, $plan_options);
                                                        $data_allowed_payment_gateways = json_encode($allowed_payment_gateways_);
                                                        $arm_plan_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency, $planObj->amount);
                                                        $planInputAttr = ' data-type="' . $plan_type . '" data-plan_name="' . $planObj->name . '" data-amt="' . $arm_plan_amount . '" data-recurring="' . $payment_type . '" data-is_trial="' . $is_trial . '" data-trial_amt="' . $trial_amount . '"  data-allowed_gateways=\'' . $data_allowed_payment_gateways . '\' data-plan_text="' . htmlentities($planText) . '"';


                                                        $count_total_cycle = 0;
                                                        if($planObj->is_recurring()){

                                                          $count_total_cycle = count($plan_payment_cycles[$plan_id]);
                                                          $planInputAttr .= '  " data-cycle="'.$count_total_cycle .'"';
                                                        }
                                                        else{
                                                          $planInputAttr .= " data-cycle='0'";
                                                        }

                                                       
                                                        $planInputAttr .= " data-tax='".$tax_percentage."'";

                                                        
                                                        if ($setup_style['plan_skin'] == '') {
                                                            $module_content .= '<li class="arm_plan_default_skin arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            $module_content .= '<span class="arm_setup_check_circle"><i class="armfa armfa-check"></i></span>';
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span>';
                                                            $module_content .= '<div class="arm_module_plan_price_type"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
                                                            /* $module_content .= $setup_info; */
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        } else if ($setup_style['plan_skin'] == 'skin1') {
                                                            $module_content .= '<li class="arm_plan_skin1 arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span>';
                                                            $module_content .= '<div class="arm_module_plan_price_type"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
                                                            /* $module_content .= $setup_info; */
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        } else if ($setup_style['plan_skin'] == 'skin3') {
                                                            $module_content .= '<li class="arm_plan_skin3 arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            $module_content .= '<div class="arm_plan_name_box"><span class="arm_setup_check_circle"><i class="armfa armfa-check"></i></span>';
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_price_type"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
                                                            /* $module_content .= $setup_info; */
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        }
                                                        else {
                                                            $module_content .= '<li class="arm_plan_skin2 arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span>';
                                                            $module_content .= '<div class="arm_module_plan_price_type"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
                                                            /* $module_content .= $setup_info; */
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        }
                                                        $i++;
                                                    }
                                                }
                                            }
                                            $module_content .= '</ul>';
                                        }
                                        $module_content .= '</div>';
                                        $module_content = apply_filters('arm_after_setup_plan_section', $module_content, $setupID, $setup_data);
                                        $module_content .= '<div class="armclear"></div>';
                                        $module_content .= '<input type="hidden" data-ng-model="arm_form.arm_plan_type" name="arm_plan_type" value="' . ((!empty($selected_plan_data['arm_subscription_plan_type']) && $selected_plan_data['arm_subscription_plan_type'] == 'free') ? 'free' : 'paid') . '">';
                                    }

                                break;
                            case 'forms':

                                if (!empty($modules['forms']) && $modules['forms'] != 0) {
                                    if (!empty($form_settings)) {
                                        $form_style_class = 'arm_shortcode_form arm_form_' . $modules['forms'];
                                        $form_style_class .= ' arm_form_layout_' . $form_settings['style']['form_layout'];
                                        $form_style_class .= ($form_settings['style']['label_hide'] == '1') ? ' armf_label_placeholder' : '';
                                        $form_style_class .= ' armf_alignment_' . $form_settings['style']['label_align'];
                                        $form_style_class .= ' armf_layout_' . $form_settings['style']['label_position'];
                                        $form_style_class .= ' armf_button_position_' . $form_settings['style']['button_position'];
                                        $form_style_class .= ($form_settings['style']['rtl'] == '1') ? ' arm_form_rtl' : ' arm_form_ltr';
                                        $errPosCCField = !empty($form_settings['style']['validation_position']) ? $form_settings['style']['validation_position'] : 'bottom';
                                        $buttonStyle = (isset($form_settings['style']['button_style']) && !empty($form_settings['style']['button_style'])) ? $form_settings['style']['button_style'] : 'flat';
                                        $btn_style_class = ' arm_btn_style_' . $buttonStyle;

                                        $fieldPosition = !empty($form_settings['style']['field_position']) ? $form_settings['style']['field_position'] : 'left';
                                    }
                                    if (is_user_logged_in() && !$isPreview) {

                                      $form = new ARM_Form('id', $modules['forms']);
                                      $ref_template = $form->form_detail['arm_ref_template'];
                                        $form_css = $arm_member_forms->arm_ajax_generate_form_styles($modules['forms'], $form_settings, array(), $ref_template);
                                        $formStyle .= $form_css['arm_css'];
                                        $modules['forms'] = 0;
                                    } else {
                                        $formAttr = '';
                                        if ($isPreview) {
                                            $formAttr = 'preview="true"';
                                        }
                                        $module_content .= '<div class="arm_module_forms_container arm_module_box" data-ng-cloak="">';
                                        $module_content .= do_shortcode('[arm_form id="' . $modules['forms'] . '" setup="true" form_position="' . $formPosition . '" ' . $formAttr . ']');
                                        $module_content .= '</div>';
                                        $module_content = apply_filters('arm_after_setup_reg_form_section', $module_content, $setupID, $setup_data);
                                        $module_content .= '<div class="armclear"></div>';
                                    }
                                } else {
                                    if (!$isPreview) {
                                        /* Hide Setup Form for non-logged in users when there is no form configured */
                                        return '';
                                    }
                                }
                                break;
                            case 'note':
                                if (isset($setup_modules['note']) && !empty($setup_modules['note'])) {
                                    $module_content .= '<div class="arm_module_note_container arm_module_box">';
                                    $module_content .= apply_filters('the_content', stripslashes($setup_modules['note']));
                                    $module_content .= '</div>';
                                }
                                break;

                            case 'payment_cycle':
                                $form_layout = '';
                                if (!empty($form_settings)) {
                                    $form_layout = ' arm_form_layout_' . $form_settings['style']['form_layout'];
                                }
                                $payment_mode = "both";

                                $module_content .= '<div class="arm_setup_paymentcyclebox_wrapper arm_hide">';

                                if (!empty($plan_payment_cycles)) {

                                    foreach ($plan_payment_cycles as $payment_cycle_plan_id => $plan_payment_cycle_data) {

                                        $arm_user_selected_payment_cycle = 0;
                                        if (!empty($current_plan_data)) {
                                            $arm_user_selected_payment_cycle = $current_plan_data['arm_payment_cycle'];
                                        }

                                        if (!empty($plan_payment_cycle_data)) {
                                            $module_content .= '<div class="arm_module_payment_cycle_container arm_module_box arm_payment_cycle_box_' . $payment_cycle_plan_id . ' arm_form_' . $setup_modules['modules']['forms'] . ' ' . $form_layout . ' arm_hide">';
                                            if (isset($setup_data['setup_labels']['payment_cycle_section_title']) && !empty($setup_data['setup_labels']['payment_cycle_section_title'])) {
                                                $module_content .= '<div class="arm_setup_section_title_wrapper arm_setup_payment_cycle_title_wrapper arm_hide" style="text-align:' . $formPosition . ';">' . $setup_data['setup_labels']['payment_cycle_section_title'] . '</div>';
                                            } else {
                                                $module_content .= '<div class="arm_setup_section_title_wrapper arm_setup_payment_cycle_title_wrapper arm_hide" style="text-align:' . $formPosition . ';">' . __('Select Payment Cycle', 'ARMember') . '</div>';
                                            }
                                            $column_type = (!empty($setup_modules['cycle_columns'])) ? $setup_modules['cycle_columns'] : '1';

                                            if (is_array($plan_payment_cycle_data)) {
                                                if (count($plan_payment_cycle_data) <= $arm_user_selected_payment_cycle) {
                                                    $arm_user_selected_payment_cycle_no = 0;
                                                } else {
                                                    $arm_user_selected_payment_cycle_no = $arm_user_selected_payment_cycle;
                                                }

                                                $module_content .= '<input type="hidden" name="arm_payment_cycle_plan_'.$payment_cycle_plan_id.'" data-id="arm_payment_cycle_plan_'.$payment_cycle_plan_id.'" value="'.$arm_user_selected_payment_cycle_no.'" data-ng-model="rm_payment_cycle_plan_'.$payment_cycle_plan_id.'">';
                                              }



                                            if($setup_style['plan_skin'] == 'skin5'){
                                              if (is_array($plan_payment_cycle_data)) {

                                                $paymentSkinFloat = "float:none;";
                                            switch ($formPosition) {
                                                case 'left':
                                                    $paymentSkinFloat = "";
                                                    break;
                                                case 'right':
                                                    $paymentSkinFloat = "float:right;";
                                                    break;
                                            }
                                            $module_content .= '<div class="arm_form_input_container arm_container payment_gateway_dropdown_skin1" style="' . $paymentSkinFloat . '">';
                                            $module_content .= '<div class="payment_gateway_dropdown_skin">';

                                               $module_content .= '<md-select name="payment_cycle_' . $payment_cycle_plan_id . '" class="arm_module_cycle_input select_skin" data-ng-model="payment_cycle_'.$payment_cycle_plan_id.'" ng-change="armPaymentCycleChange('.$payment_cycle_plan_id.', \'arm_setup_form' . $setupRandomID . '\')">';
                                               
                                              $i = 0; 


                                              foreach ($plan_payment_cycle_data as $arm_cycle_data_key => $arm_cycle_data) {

                                                    $pc_checked = $pc_checked_class = '';
                                                    if ($i == $arm_user_selected_payment_cycle_no) {
                                                        $pc_checked = 'selected="selected""';
                                                        $pc_checked_class = 'arm_active';
                                                    }


                                                    $arm_paymentg_cycle_amount = (isset($arm_cycle_data['cycle_amount'])) ? $arm_payment_gateways->arm_amount_set_separator($global_currency, $arm_cycle_data['cycle_amount']) : 0;
                                                    $arm_paymentg_cycle_label = (isset($arm_cycle_data['cycle_label'])) ? $arm_cycle_data['cycle_label'] : '';


                                                    $module_content .='<md-option value="' . $arm_cycle_data_key  . '" class="armMDOption armSelectOption' . $setup_modules['modules']['forms'] . '" ' . $pc_checked . '  data-cycle_type="recurring" data-plan_id="' . $payment_cycle_plan_id . '" data-plan_amount = "' . $arm_paymentg_cycle_amount . '" >' . $arm_paymentg_cycle_label . '</md-option>';


                                                    $i++;
                                                }
                                                  $module_content .= '</md-select></div></div>';
                                              
                                            }


                                            }else{
                                                $module_content .= '<ul class="arm_module_payment_cycle_ul arm_column_' . $column_type . '">';
                                            $i = 0;

                                            if (is_array($plan_payment_cycle_data)) {
                                                foreach ($plan_payment_cycle_data as $arm_cycle_data_key => $arm_cycle_data) {

                                                    $pc_checked = $pc_checked_class = '';
                                                    if ($i == $arm_user_selected_payment_cycle_no) {
                                                        $pc_checked = 'checked="checked"';
                                                        $pc_checked_class = 'arm_active';
                                                    }


                                                    $arm_paymentg_cycle_amount = (isset($arm_cycle_data['cycle_amount'])) ? $arm_payment_gateways->arm_amount_set_separator($global_currency, $arm_cycle_data['cycle_amount']) : 0;
                                                    $arm_paymentg_cycle_label = (isset($arm_cycle_data['cycle_label'])) ? $arm_cycle_data['cycle_label'] : '';

                                                    $pc_content = '<label class="arm_module_payment_cycle_option">';
                                                    $pc_content .= '<span class="arm_setup_check_circle"><i class="armfa armfa-check"></i></span>';
                                                    $pc_content .= '<input type="radio" name="payment_cycle_' . $payment_cycle_plan_id . '" class="arm_module_cycle_input" value="' . ( $arm_cycle_data_key ) . '" ' . $pc_checked . ' data-ng-model="arm_form.payment_cycle" data-cycle_type="recurring" data-plan_id="' . $payment_cycle_plan_id . '" data-plan_amount = "' . $arm_paymentg_cycle_amount . '">';
                                                    $pc_content .= '<div class="arm_module_payment_cycle_name"><span class="arm_module_payment_cycle_span">' . $arm_paymentg_cycle_label . '</span></div>';
                                                    $pc_content .= '</label>';

                                                    $module_content .= '<li class="arm_setup_column_item arm_payment_cycle_' . ( $arm_cycle_data_key ) . ' ' . $pc_checked_class . '"  data-plan_id="' . $payment_cycle_plan_id . '">';
                                                    $module_content .= $pc_content;
                                                    $module_content .= '</li>';
                                                    $i++;
                                                }
                                            }
                                            $module_content .= '</ul>';
                                            } 
                                            $module_content .= '</div>';
                                        }
                                    }
                                }
                                $module_content = apply_filters('arm_after_setup_payment_cycle_section', $module_content, $setupID, $setup_data);
                                $module_content .= '</div>';
                                break;
                            case 'gateways':

                                $form_layout = '';

                                if (!empty($form_settings)) {

                                    $form_layout = ' arm_form_layout_' . $form_settings['style']['form_layout'];
                                }

                                $payment_mode = "both";
                                    $payment_gateway_skin = (isset($setup_style['gateway_skin']) && $setup_style['gateway_skin'] != '' ) ? $setup_style['gateway_skin'] : 'radio';
                                    $active_gateways = $arm_payment_gateways->arm_get_active_payment_gateways();
                                    
                                   
                                    $gateways = array_keys($active_gateways);
                                    if (!empty($gateways)) {
                                        $is_display_pg = (!empty($selected_plan_data['arm_subscription_plan_type']) && $selected_plan_data['arm_subscription_plan_type'] == 'free') ? 'display:none;' : '';
                                        $module_content .= '<div class="arm_setup_gatewaybox_wrapper" style="' . $is_display_pg . '">';
                                        if (isset($setup_data['setup_labels']['payment_section_title']) && !empty($setup_data['setup_labels']['payment_section_title'])) {
                                            $module_content .= '<div class="arm_setup_section_title_wrapper" style="text-align:' . $formPosition . ';">' . $setup_data['setup_labels']['payment_section_title'] . '</div>';
                                        }
                                        $module_content .= '<input type="hidden" name="arm_front_gateway_skin_type" data-id="arm_front_gateway_skin_type" value="' . $payment_gateway_skin . '">';
                                        $module_content .= '<div class="arm_module_gateways_container arm_module_box arm_form_' . $setup_modules['modules']['forms'] . ' ' . $form_layout . '">';

                                        $column_type = (!empty($setup_modules['gateways_columns'])) ? $setup_modules['gateways_columns'] : '1';

                                        $doNotDisplayPaymentMode = array('bank_transfer');
                                        $doNotDisplayPaymentMode = apply_filters('arm_not_display_payment_mode_setup', $doNotDisplayPaymentMode);

                                        $pglabels = isset($setup_data['arm_setup_labels']['payment_gateway_labels']) ? $setup_data['arm_setup_labels']['payment_gateway_labels'] : array();

                                        if ($payment_gateway_skin == 'radio') {

                                            $module_content .= '<ul class="arm_module_gateways_ul arm_column_' . $column_type . '" style="text-align:' . $formPosition . ';">';
                                            $i = 0;
                                            $pg_fields = $selectedKey = '';

                                            foreach ($gateways as $pg) {
                                                if (in_array($pg, array_keys($active_gateways))) {
                                                    if (isset($selected_plan_data['arm_subscription_plan_options']['trial']['is_trial_period']) && $pg == 'stripe' && $selected_plan_data['arm_subscription_plan_options']['payment_type'] == 'subscription') {
                                                        if ($selected_plan_data['arm_subscription_plan_options']['trial']['amount'] > 0) {
                                                            // continue;
                                                        }
                                                    }
                                                    if (!in_array($pg, $doNotDisplayPaymentMode)) {
                                                        $payment_mode = $modules['payment_mode'][$pg];
                                                    } else {
                                                        $payment_mode = 'manual_subscription';
                                                    }

                                                    $pg_options = $active_gateways[$pg];
                                                    $pg_checked = $pg_checked_class = '';
                                                    $display_block = 'arm_hide';
                                                    if ($i == 0) {
                                                        $pg_checked = 'checked="checked"';
                                                        $pg_checked_class = 'arm_active';
                                                        $display_block = '';
                                                        $selectedKey = $pg;
                                                    }
                                                    $pg_content = '<label class="arm_module_gateway_option">';
                                                    $pg_content .= '<span class="arm_setup_check_circle"><i class="armfa armfa-check"></i></span>';
                                                    $pg_content .= '<input type="radio" name="payment_gateway" class="arm_module_gateway_input" value="' . $pg . '" ' . $pg_checked . ' data-payment_mode="' . $payment_mode . '" data-ng-model="arm_form.payment_gateway">';
                                                    if (!empty($pglabels)) {
                                                      if(isset($pglabels[$pg])){
                                                        $pg_options['gateway_name'] = $pglabels[$pg];
                                                      }
                                                    }
                                                    $pg_content .= '<div class="arm_module_gateway_name"><span class="arm_module_gateway_span">' . $pg_options['gateway_name'] . '</span></div>';
                                                    $pg_content .= '</label>';
                                                    switch ($pg) {
                                                        case 'paypal':
                                                            break;
                                                        case 'stripe':
                                                            if ($pg_options['stripe_payment_mode'] == 'live') {
                                                                $apikey = $pg_options['stripe_pub_key'];
                                                            } else {
                                                                $apikey = $pg_options['stripe_test_pub_key'];
                                                            }
                                                            $pg_fields .= '<script data-cfasync="false">Stripe.setPublishableKey("' . $apikey . '");</script>';
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_stripe ' . $display_block . ' arm_member_form_container">';
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_credit_card_box('stripe', $column_type, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        case 'authorize_net':
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_authorize_net ' . $display_block . ' arm_member_form_container">';
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_credit_card_box('authorize_net', $column_type, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        case '2checkout':
                                                            break;
                                                        case 'bank_transfer':
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_bank_transfer ' . $display_block . ' arm_member_form_container">';
                                                            if (isset($pg_options['note']) && !empty($pg_options['note'])) {
                                                                $pg_fields .= '<div class="arm_bank_transfer_note_container">' . stripslashes($pg_options['note']) . '</div>';
                                                            }
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_bank_transfer_form($pg_options, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        default:
                                                            $gateway_fields = apply_filters('arm_membership_setup_gateway_option', '', $pg, $pg_options);
                                                            $pgHasCCFields = apply_filters('arm_payment_gateway_has_ccfields', false, $pg, $pg_options);
                                                            if ($pgHasCCFields) {
                                                                $gateway_fields .= $arm_payment_gateways->arm_get_credit_card_box($pg, $column_type, $fieldPosition, $errPosCCField);
                                                            }
                                                            if (!empty($gateway_fields)) {
                                                                $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_' . $pg . ' ' . $display_block . ' arm_member_form_container">';
                                                                $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                                $pg_fields .= $gateway_fields;
                                                                $pg_fields .= '</div>';
                                                                $pg_fields .= '</div>';
                                                            }
                                                            break;
                                                    }
                                                    $module_content .= '<li class="arm_setup_column_item arm_gateway_' . $pg . ' ' . $pg_checked_class . '">';
                                                    $module_content .= $pg_content;
                                                    $module_content .= '</li>';
                                                    $i++;
                                                    $module_content .= "<input type='hidden' name='arm_payment_mode[$pg]'  value='{$payment_mode}' />";
                                                }
                                            }
                                            $module_content .= '</ul>';
                                        } else {
                                            $paymentSkinFloat = "float:none;";
                                            switch ($formPosition) {
                                                case 'left':
                                                    $paymentSkinFloat = "";
                                                    break;
                                                case 'right':
                                                    $paymentSkinFloat = "float:right;";
                                                    break;
                                            }
                                            $module_content .= '<div class="arm_form_input_container arm_container payment_gateway_dropdown_skin1" style="' . $paymentSkinFloat . '">';
                                            $module_content .= '<div class="payment_gateway_dropdown_skin">';
                                            $module_content .= '<md-select name="payment_gateway" class="arm_module_gateway_input select_skin" data-ng-model="payment_gateway" aria-label="gateway" ng-change="armPaymentGatewayChange(\'arm_setup_form' . $setupRandomID . '\')">';
                                            $i = 0;
                                            $pg_fields = $selectedKey = '';
                                            foreach ($gateways as $pg) {
                                                if (in_array($pg, array_keys($active_gateways))) {
                                                    $payment_gateway_name = $pg;
                                                    if (isset($selected_plan_data['arm_subscription_plan_options']['trial']['is_trial_period']) && $pg == 'stripe' && $selected_plan_data['arm_subscription_plan_options']['payment_type'] == 'subscription') {
                                                        if ($selected_plan_data['arm_subscription_plan_options']['trial']['amount'] > 0) {
                                                            // continue;
                                                        }
                                                    }

                                                    if (!in_array($pg, $doNotDisplayPaymentMode)) {
                                                        $payment_mode = $modules['payment_mode'][$pg];
                                                    } else {
                                                        $payment_mode = 'manual_subscription';
                                                    }


                                                    $pg_options = $active_gateways[$pg];
                                                    $pg_checked = $pg_checked_class = '';
                                                    $display_block = 'arm_hide';
                                                    if ($i == 0) {
                                                        $pg_checked = 'selected="selected"';
                                                        $pg_checked_class = 'arm_active';
                                                        $display_block = '';
                                                        $selectedKey = $pg;
                                                    }

                                                    switch ($pg) {
                                                        case 'paypal':
                                                            break;
                                                        case 'stripe':
                                                            if ($pg_options['stripe_payment_mode'] == 'live') {
                                                                $apikey = $pg_options['stripe_pub_key'];
                                                            } else {
                                                                $apikey = $pg_options['stripe_test_pub_key'];
                                                            }
                                                            
                                                            $pg_fields .= '<script data-cfasync="false">Stripe.setPublishableKey("' . $apikey . '");</script>';
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_stripe ' . $display_block . ' arm_member_form_container">';
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_credit_card_box('stripe', $column_type, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        case 'authorize_net':
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_authorize_net ' . $display_block . ' arm_member_form_container">';
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_credit_card_box('authorize_net', $column_type, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        case '2checkout':
                                                            break;
                                                        case 'bank_transfer':
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_bank_transfer ' . $display_block . ' arm_member_form_container">';
                                                            if (isset($pg_options['note']) && !empty($pg_options['note'])) {
                                                                $pg_fields .= '<div class="arm_bank_transfer_note_container">' . stripslashes($pg_options['note']) . '</div>';
                                                            }
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_bank_transfer_form($pg_options, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        default:
                                                            $gateway_fields = apply_filters('arm_membership_setup_gateway_option', '', $pg, $pg_options);
                                                            $pgHasCCFields = apply_filters('arm_payment_gateway_has_ccfields', false, $pg, $pg_options);
                                                            if ($pgHasCCFields) {
                                                                $gateway_fields .= $arm_payment_gateways->arm_get_credit_card_box($pg, $column_type, $fieldPosition, $errPosCCField);
                                                            }
                                                            if (!empty($gateway_fields)) {
                                                                $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_' . $pg . ' ' . $display_block . ' arm_member_form_container">';
                                                                $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                                $pg_fields .= $gateway_fields;
                                                                $pg_fields .= '</div>';
                                                                $pg_fields .= '</div>';
                                                            }
                                                            break;
                                                    }


                                                    
                                                     if (!empty($pglabels)) {
                                                      if(isset($pglabels[$pg])){
                                                        $pg_options['gateway_name'] = $pglabels[$pg];
                                                      }
                                                    }


                                                    
                                                    $module_content .='<md-option value="' . $payment_gateway_name . '" class="armMDOption armSelectOption' . $setup_modules['modules']['forms'] . ' arm_gateway_' . $payment_gateway_name . '" ' . $pg_checked . ' data-payment_mode="' . $payment_mode . '">' . $pg_options['gateway_name'] . '</md-option>';
                                                    $i++;
                                                    $module_content .= "<input type='hidden' name='arm_payment_mode[$pg]'  value='{$payment_mode}' />";
                                                }
                                            }
                                            $module_content .= '</md-select>';
                                            $module_content .= '</div></div>';
                                        }

                                        $module_content .= '<div class="armclear"></div>';
                                        $module_content .= $pg_fields;
                                        $module_content .= '<div class="armclear"></div>';
                                        $module_content .= '</div>';
                                        $module_content = apply_filters('arm_after_setup_gateway_section', $module_content, $setupID, $setup_data);
                                        $module_content .= '<div class="armclear" data-ng-init="armSetDefaultPaymentGateway(\'' . $selectedKey . '\');"></div>';
                                        $module_content .= '</div>';
                                        /* Payment Mode Module */


                                        $arm_automatic_sub_label = (isset($setup_data['setup_labels']['automatic_subscription']) && !empty($setup_data['setup_labels']['automatic_subscription'])) ? $setup_data['setup_labels']['automatic_subscription'] : __('Auto Debit Payment', 'ARMember');
                                        $arm_semi_automatic_sub_label = (isset($setup_data['setup_labels']['semi_automatic_subscription']) && !empty($setup_data['setup_labels']['semi_automatic_subscription'])) ? $setup_data['setup_labels']['semi_automatic_subscription'] : __('Manual Payment', 'ARMember');
                                        $module_content .= "<div class='arm_payment_mode_wrapper' id='arm_payment_mode_wrapper' style='text-align:{$formPosition};'>";
                                        $setup_data['setup_labels']['payment_mode_selection'] = (isset($setup_data['setup_labels']['payment_mode_selection']) && !empty($setup_data['setup_labels']['payment_mode_selection'])) ? $setup_data['setup_labels']['payment_mode_selection'] : __('How you want to pay?', 'ARMember');
                                        $module_content .= "<div class='arm_setup_section_title_wrapper arm_payment_mode_selection_wrapper' >" . $setup_data['setup_labels']['payment_mode_selection'] . "</div>";
                                        $module_content .= "<div class='arm_radio_outer_wrapper'><div class='arm_radio_wrapper'><input type='radio' checked='checked' name='arm_selected_payment_mode' value='auto_debit_subscription' class='arm_selected_payment_mode' id='arm_selected_payment_mode_auto_{$setupRandomID}'/><span></span></div><label for='arm_selected_payment_mode_auto_{$setupRandomID}' style='cursor:pointer;'>&nbsp;<span class='arm_payment_mode_label'>" . $arm_automatic_sub_label . "</span></label></div>";
                                        $module_content .= "<div class='arm_radio_outer_wrapper' style='margin-left: 30px;'><div class='arm_radio_wrapper'><input type='radio'  name='arm_selected_payment_mode' value='manual_subscription' class='arm_selected_payment_mode' id='arm_selected_payment_mode_semi_auto_{$setupRandomID}'/><span></span></div><label for='arm_selected_payment_mode_semi_auto_{$setupRandomID}' style='cursor:pointer;'>&nbsp;<span class='arm_payment_mode_label'>" . $arm_semi_automatic_sub_label . "</span></label></div>";
                                        $module_content .= "";
                                        $module_content .= "</div>";
                                    }
                               
                                break;
                            case 'order_detail':
                                if (!empty($modules['plans'])) {
                                    /* $module_content .= '<div class="arm_order_description arm_module_box"></div>'; */
                                    if ($arm_manage_coupons->isCouponFeature && !empty($modules['coupons']) && $modules['coupons'] == '1') {
                                        $labels = array(
                                            'title' => (!empty($button_labels['coupon_title'])) ? $button_labels['coupon_title'] : '',
                                            'button' => (!empty($button_labels['coupon_button'])) ? $button_labels['coupon_button'] : '',
                                        );
                                        $is_used_as_invitation_code = (isset($setup_modules['modules']['coupon_as_invitation']) && $setup_modules['modules']['coupon_as_invitation'] == 1) ? true : false;

                                        $module_content .= '<div class="arm_setup_couponbox_wrapper">';
                                        if (isset($button_labels['coupon_title']) && !empty($button_labels['coupon_title'])) {
                                            $module_content .= '<div class="arm_setup_section_title_wrapper" style="text-align:' . $formPosition . ';">' . $button_labels['coupon_title'] . '</div>';
                                        }
                                        $module_content .= '<div class="arm_module_coupons_container arm_module_box">';
                                        $is_display_coupons = (!empty($selected_plan_data['arm_subscription_plan_type']) && $selected_plan_data['arm_subscription_plan_type'] == 'free') ? 'display:none;' : '';
                                        $module_content .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                        $module_content .= '<div class="arm_form_inner_container arm_msg_pos_' . $errPosCCField . '" style="padding: 0 !important;">';
                                        $module_content .= '<div class="arm_coupon_fields arm_form_wrapper_container">';
                                        $module_content .= $arm_manage_coupons->arm_redeem_coupon_html('', $labels, $selected_plan_data, $btn_style_class, $is_used_as_invitation_code, $setupRandomID, $formPosition);

                                        $module_content .= '</div>';
                                        $module_content .= '</div>';
                                        $module_content .= '</div>';
                                        $module_content .= '<div class="armclear"></div>';
                                        $module_content .= '</div>';
                                        $module_content .= '</div>';
                                    }
                                    $module_content = apply_filters('arm_after_setup_order_detail', $module_content, $setupID, $setup_data);
                                    if (isset($setup_data['setup_labels']['summary_text']) && !empty($setup_data['setup_labels']['summary_text'])) {
                                        $setupSummaryText = stripslashes($setup_data['setup_labels']['summary_text']);
                                        $setupSummaryText = str_replace('[PLAN_NAME]', '<span class="arm_plan_name_text"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[PLAN_AMOUNT]', '<span class="arm_plan_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[TAX_AMOUNT]', '<span class="arm_tax_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[TAX_PERCENTAGE]', '<span class="arm_tax_percentage_text">'.$tax_percentage.'</span>%', $setupSummaryText);
                                        $setupSummaryText = str_replace('[DISCOUNT_AMOUNT]', '<span class="arm_discount_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[PAYABLE_AMOUNT]', '<span class="arm_payable_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[TRIAL_AMOUNT]', '<span class="arm_trial_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $module_content .= "<div class='arm_setup_summary_text_container arm_module_box' style='text-align:{$formPosition};'>";
                                        $module_content .= '<input type="hidden" name="arm_total_payable_amount" data-id="arm_total_payable_amount" ng-model="arm_total_payable_amount" value=""/>';
                                        $module_content .= '<input type="hidden" name="arm_zero_amount_discount" data-id="arm_zero_amount_discount" ng-model="arm_zero_amount_discount" value="' . $arm_plan_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency) . '"/>';
                                        $module_content .= '<div class="arm_setup_summary_text">' . nl2br($setupSummaryText) . '</div>';
                                        $module_content .= '</div>';
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                        $module_html .= $module_content;
                    }

                    $content = apply_filters('arm_before_setup_form_content', $content, $setupID, $setup_data);
                    $content .= '<div class="arm_setup_form_container">';
                    $content .= '<style type="text/css" id="arm_setup_style_' . $args['id'] . '">';
                    if (!empty($setup_style)) {
                        $sfontFamily = isset($setup_style['font_family']) ? $setup_style['font_family'] : '';
                        $gFontUrl = $arm_member_forms->arm_get_google_fonts_url(array($sfontFamily));
                        if (!empty($gFontUrl)) {
                            $setupGoogleFonts .= '<link id="google-font-' . $setupID . '" rel="stylesheet" type="text/css" href="' . $gFontUrl . '" />';
                        }
                        $content .= $this->arm_generate_setup_style($setupID, $setup_style);
                    }
                    if (!empty($formStyle)) {
                        $content .= $formStyle;
                    }
                    if (!empty($custom_css)) {
                        $content .= $custom_css;
                    }
                    $content .= '</style>';
                    $content .= $setupGoogleFonts;
                    $content .= '<div class="arm_setup_messages arm_form_message_container"></div>';
                    $form_attr = ' data-ng-controller="ARMCtrl" data-ng-submit="armSetupFormSubmit(arm_form.$valid, \'arm_setup_form' . $setupRandomID . '\', $event);" onsubmit="return false;"';
                    $is_form_class_rtl = '';
                    if (is_rtl()) {
                        $is_form_class_rtl = 'is_form_class_rtl';
                    }
                    $captcha_code = arm_generate_captcha_code();
                    if (!isset($_SESSION['ARM_FILTER_INPUT'])) {
                        $_SESSION['ARM_FILTER_INPUT'] = array();
                    }
                    if (isset($_SESSION['ARM_FILTER_INPUT'][$setupRandomID])) {
                        unset($_SESSION['ARM_FILTER_INPUT'][$setupRandomID]);
                    }
                    $_SESSION['ARM_FILTER_INPUT'][$setupRandomID] = $captcha_code;
                    $_SESSION['ARM_VALIDATE_SCRIPT'] = true;
                    $form_attr .= ' data-submission-key="' . $captcha_code . '" ';
                    $content .= '<form method="post" name="arm_form" id="arm_setup_form' . $setupRandomID . '" class="arm_setup_form_' . $setupID . ' arm_membership_setup_form arm_form_' . $modules['forms'] . ' ' . $is_form_class_rtl . '" enctype="multipart/form-data" data-random-id="' . $setupRandomID . '" novalidate ' . $form_attr . '>';
                    if ($args['hide_title'] == false && $args['popup'] == false) {
                        $content .= '<h3 class="arm_setup_form_title">' . $setup_name . '</h3>';
                    }
                    $content .= '<input type="hidden" name="setup_id" value="' . $setupID . '" data-id="arm_setup_id"/>';
                    $content .= '<input type="hidden" name="setup_action" value="membership_setup"/>';
                    $content .= "<input type='text' name='arm_filter_input' data-random-key='{$setupRandomID}' value='' style='opacity:0 !important;display:none !important;visibility:hidden !important;' />";
                    $content .= '<div class="arm_setup_form_inner_container">';
                    $content .= '<input type="hidden" class="arm_global_currency" value="' . $global_currency . '"/>';

                    /* tax values */
                    if($enable_tax == 1 && !empty($tax_values)) {
                        $content .= "<input type='hidden' name='arm_tax_type' value='".$tax_values["tax_type"]."'/>";
                        if($tax_values['tax_type'] =='country_tax') {
                            $content .= "<input type='hidden' name='arm_country_tax_field' value='".$tax_values["country_tax_field"]."'/>";
                            $content .= "<input type='hidden' name='arm_country_tax_field_opts' value='".$tax_values["country_tax_field_opts_json"]."'/>";
                            $content .= "<input type='hidden' name='arm_country_tax_amount' value='".$tax_values["country_tax_amount_json"]."'/>";
                            $content .= "<input type='hidden' name='arm_country_tax_default_val' value='".$tax_values["tax_percentage"]."'/>";
                        }
                        else {
                            $content .= "<input type='hidden' name='arm_common_tax_amount' value='".$tax_values["tax_percentage"]."'/>";
                        }
                    }
                    /* tax values over */

                    $content .= $module_html;
                    $content .= '<div class="armclear"></div>';
                    $content .= '<div class="arm_setup_submit_btn_wrapper ' . $form_style_class . '" data-ng-cloak="">';
                    $content .= '<div class="arm_form_field_container arm_form_field_container_submit">';
                    $content .= '<div class="arm_label_input_separator"></div>';
                    $content .= '<div class="arm_form_label_wrapper arm_form_field_label_wrapper arm_form_member_field_submit"></div>';
                    $content .= '<div class="arm_form_input_wrapper">';
                    $content .= '<div class="arm_form_input_container_submit arm_form_input_container" id="arm_setup_form_input_container' . $setupID . '">';
                    $ngClick = 'ng-click="armSubmitBtnClick($event)"';
                    if (current_user_can('administrator')) {
                        $ngClick = 'onclick="return false;"';
                    }
                    $content .= '<md-button type="submit" name="ARMSETUPSUBMIT" class="arm_setup_submit_btn arm_form_field_submit_button arm_form_field_container_button arm_form_input_box arm_material_input ' . $btn_style_class . '" ' . $ngClick . '><span class="arm_spinner">' . file_get_contents(MEMBERSHIP_IMAGES_DIR . "/loader.svg") . '</span>' . html_entity_decode(stripslashes($submit_btn)) . '</md-button>';
                    $content .= '</div>';
                    $content .= '</div>';
                    $content .= '</div>';
                    $content .= '</div>';
                    $content .= '</div>';
                    $content .= '</form></div>';

                    if ($args['popup'] !== false) {
                        $popup_content = '<div class="arm_setup_form_popup_container">';
                        $link_title = (!empty($args['link_title'])) ? $args['link_title'] : $setup_name;
                        $link_style = $link_hover_style = '';
                        $popup_content .= '<style type="text/css">';
                        if (!empty($args['link_css'])) {
                            $link_style = esc_html($args['link_css']);
                            $popup_content .= '.arm_setup_form_popup_link_' . $setupID . '{' . $link_style . '}';
                        }
                        if (!empty($args['link_hover_css'])) {
                            $link_hover_style = esc_html($args['link_hover_css']);
                            $popup_content .= '.arm_setup_form_popup_link_' . $setupID . ':hover{' . $link_hover_style . '}';
                        }
                        $popup_content .= '</style>';
                        $pformRandomID = $setupID . '_popup_' . arm_generate_random_code();
                        $popupLinkID = 'arm_setup_form_popup_link_' . $setupID;
                        $popupLinkClass = 'arm_setup_form_popup_link arm_setup_form_popup_link_' . $setupID;
                        if (!empty($args['link_class'])) {
                            $popupLinkClass.=" " . esc_html($args['link_class']);
                        }
                        $popupLinkAttr = 'data-form_id="' . $pformRandomID . '" data-toggle="armmodal"  data-modal_bg="' . $args['modal_bgcolor'] . '" data-overlay="' . $args['overlay'] . '"';
                        if (!empty($args['link_type']) && strtolower($args['link_type']) == 'button') {
                            $popup_content .= '<button type="button" id="' . $popupLinkID . '" class="' . $popupLinkClass . ' arm_setup_form_popup_button" ' . $popupLinkAttr . '>' . $link_title . '</button>';
                        } else {
                            $popup_content .= '<a href="javascript:void(0)" id="' . $popupLinkID . '" class="' . $popupLinkClass . ' arm_setup_form_popup_ahref" ' . $popupLinkAttr . '>' . $link_title . '</a>';
                        }
                        $popup_style = $popup_content_height = '';
                        $popupHeight = 'auto';
                        $popupWidth = '500';
                        if (!empty($args['popup_height'])) {
                            if ($args['popup_height'] == 'auto') {
                                $popup_style .= 'height: auto;';
                            } else {
                                $popup_style .= 'overflow: hidden;height: ' . $args['popup_height'] . 'px;';
                                $popupHeight = ($args['popup_height'] - 70) . 'px';
                                $popup_content_height = 'overflow-x: hidden;overflow-y: auto;height: ' . ($args['popup_height'] - 70) . 'px;';
                            }
                        }
                        if (!empty($args['popup_width'])) {
                            if ($args['popup_width'] == 'auto') {
                                $popup_style .= '';
                            } else {
                                $popupWidth = $args['popup_width'];
                                $popup_style .= 'width: ' . $args['popup_width'] . 'px;';
                            }
                        }
                        $popup_content .= '<div class="popup_wrapper arm_popup_wrapper arm_popup_member_setup_form arm_popup_member_setup_form_' . $setupID . ' arm_popup_member_setup_form_' . $pformRandomID . '" style="' . $popup_style . '" data-width="' . $popupWidth . '"><div class="popup_setup_inner_container popup_wrapper_inner">';
                        $popup_content .= '<div class="popup_header">';
                        $popup_content .= '<span class="popup_close_btn arm_popup_close_btn"></span>';
                        $popup_content .= '<div class="popup_header_text arm_setup_form_heading_container">';
                        if ($args['hide_title'] == false) {
                            $popup_content .= '<span class="arm_setup_form_field_label_wrapper_text">' . $setup_name . '</span>';
                        }
                        $popup_content .= '</div>';
                        $popup_content .= '</div>';
                        $popup_content .= '<div class="popup_content_text" style="' . $popup_content_height . '" data-height="' . $popupHeight . '">';
                        $popup_content .= $content;
                        $popup_content .= '</div><div class="armclear"></div>';
                        $popup_content .= '</div></div>';
                        $popup_content .= '</div>';
                        $content = $popup_content;
                        $content .= '<div class="armclear">&nbsp;</div>';
                    }
                    $content = apply_filters('arm_after_setup_form_content', $content, $setupID, $setup_data);
                }
            }
            $ARMember->arm_check_font_awesome_icons($content);
            $ARMember->enqueue_angular_script();
            return do_shortcode($content);
        }

        function arm_setup_shortcode_func($atts, $content = "") {
            global $wp, $wpdb, $current_user, $ARMember, $arm_member_forms, $arm_global_settings, $arm_payment_gateways, $arm_manage_coupons, $arm_subscription_plans, $bpopup_loaded, $ARMSPAMFILEURL;
            /* ====================/.Begin Set Shortcode Attributes./==================== */
            $defaults = array(
                'id' => 0, /* Membership Setup Wizard ID */
                'hide_title' => false,
                'class' => '',
                'popup' => false, /* Form will be open in popup box when options is true */
                'link_type' => 'link',
                'link_class' => '', /* /* Possible Options:- `link`, `button` */
                'link_title' => __('Click here to open Set up form', 'ARMember'), /* Default to form name */
                'popup_height' => '',
                'popup_width' => '',
                'overlay' => '0.6',
                'modal_bgcolor' => '#000000',
                'redirect_to' => '',
                'link_css' => '',
                'link_hover_css' => '',
                'is_referer' => '0',
                'preview' => false,
                'setup_data' => '',
                'subscription_plan' => 0,
                'hide_plans' => 0,
                'payment_duration' => 0,
                'setup_form_id' => '',
            );
            /* Extract Shortcode Attributes */
            $args = shortcode_atts($defaults, $atts, 'arm_setup');
            extract($args);
            $args['hide_title'] = ($args['hide_title'] === 'true' || $args['hide_title'] == '1') ? true : false;
            $args['popup'] = ($args['popup'] === 'true' || $args['popup'] == '1') ? true : false;
            $isPreview = ($args['preview'] === 'true' || $args['preview'] == '1') ? true : false;
            if ($args['popup']) {
                $bpopup_loaded = 1;
            }
            $completed_recurrence = '';
            $total_recurring = '';
            /* ====================/.End Set Shortcode Attributes./==================== */
            if ((!empty($args['id']) && $args['id'] != 0) || ($isPreview && !empty($args['setup_data']))) {

                $setupID = $args['id'];
                if ($isPreview && !empty($args['setup_data'])) {
                    $setup_data = maybe_unserialize($args['setup_data']);
                    $setup_data['arm_setup_labels'] = $setup_data['setup_labels'];
                } else {
                    $setup_data = $this->arm_get_membership_setup($setupID);
                }
                $setup_data = apply_filters('arm_setup_data_before_setup_shortcode', $setup_data, $args);
                do_action('arm_before_render_membership_setup_form', $setup_data, $args);


                if (!empty($setup_data) && !empty($setup_data['setup_modules']['modules'])) {

                    $all_global_settings = $arm_global_settings->arm_get_all_global_settings();
                    $general_settings = $all_global_settings['general_settings'];
                    $setupRandomID = $setupID . '_' . arm_generate_random_code();
                    $global_currency = $arm_payment_gateways->arm_get_global_currency();
                    $current_user_id = get_current_user_id();
                    $current_user_plan_ids = get_user_meta($current_user_id, 'arm_user_plan_ids', true);
                    $current_user_plan_ids = !empty($current_user_plan_ids) ? $current_user_plan_ids : array();
                    $current_user_plan = '';
                    $current_plan_data = array();
                    if (!empty($current_user_plan_ids)) {
                        $current_user_plan = $current_user_plan_ids[0];
                        $current_plan_data = get_user_meta($current_user_id, 'arm_user_plan_' . $current_user_plan, true);
                    }
                    $setup_name = (!empty($setup_data['setup_name'])) ? stripslashes($setup_data['setup_name']) : '';
                    $button_labels = $setup_data['setup_labels']['button_labels'];
                    $submit_btn = (!empty($button_labels['submit'])) ? $button_labels['submit'] : __('Submit', 'ARMember');
                    $setup_modules = $setup_data['setup_modules'];
                    $user_selected_plan = isset($setup_modules['selected_plan']) ? $setup_modules['selected_plan'] : "";
                    $modules = $setup_modules['modules'];
                    $setup_style = isset($setup_modules['style']) ? $setup_modules['style'] : array();

                    $tax_percentage = 0;
                    $enable_tax = isset($general_settings['enable_tax']) ? $general_settings['enable_tax'] : 0;
                    if($enable_tax == 1) {
                    	$tax_values = $this->arm_get_sales_tax($general_settings, '', $current_user_id, $modules['forms']);
                        $tax_percentage = !empty($tax_values["tax_percentage"]) ? $tax_values["tax_percentage"] : '0';
                    }

                    $formPosition = (isset($setup_style['form_position']) && !empty($setup_style['form_position'])) ? $setup_style['form_position'] : 'left';
                    $plan_selection_area = (isset($setup_style['plan_area_position']) && !empty($setup_style['plan_area_position'])) ? $setup_style['plan_area_position'] : 'before';

                    $hide_current_plans = isset($setup_style['hide_current_plans']) ? $setup_style['hide_current_plans'] : 0;
                    $previuos_button_label = (isset($button_labels['previous']) && !empty($button_labels['previous'])) ? $button_labels['previous'] : __('Previous', 'ARMember');
                    $next_button_label = (isset($button_labels['next']) && !empty($button_labels['next']) )? $button_labels['next'] : __('Next', 'ARMember');

                    $two_step = (isset($setup_style['two_step'])) ? $setup_style['two_step'] : 0;
                    


                    $fieldPosition = 'left';
                    $custom_css = isset($setup_modules['custom_css']) ? $setup_modules['custom_css'] : '';
                    $modules['step'] = (!empty($modules['step'])) ? $modules['step'] : array(-1);

                    if ($plan_selection_area == 'before' || $two_step == 1) {
                        $module_order = array(
                            'plans' => 1,
                            'payment_cycle' =>2,
                            'note' => 3,
                            'forms' => 4,
                            'gateways' => 5,
                            'order_detail' => 6,
                        );
                    } else {


                        $module_order = array(
                            'forms' => 1,
                            'plans' => 2,
                            'payment_cycle' => 3,
                            'note' => 4,
                            'gateways' => 5,
                            'order_detail' => 6,
                        );
                    }

                    $modules['forms'] = (!empty($modules['forms']) && $modules['forms'] != 0) ? $modules['forms'] : 0;
                    $step_one_modules = $step_two_modules = '';
                    /* Check `GET` or `POST` Data */
                    /* first check if user have selected any plan than select that plan otherwise set value from options of setup */
                    if ($current_user_plan != '') {
                        $selected_plan_id = $current_user_plan;
                    } else {
                        $selected_plan_id = $user_selected_plan;
                    }
                    if (!empty($_REQUEST['subscription_plan']) && $_REQUEST['subscription_plan'] != 0) {
                        $selected_plan_id = $_REQUEST['subscription_plan'];
                    }

                    
                    $selected_payment_duration = 1;
                    if (!empty($_REQUEST['payment_duration']) && $_REQUEST['payment_duration'] != 0) {
                        $selected_payment_duration = $_REQUEST['payment_duration'];
                    }
                    if (!empty($args['subscription_plan']) && $args['subscription_plan'] != 0) {
                        $selected_plan_id = $args['subscription_plan'];
                        if (!empty($args['payment_duration']) && $args['payment_duration'] != 0) {
                            $selected_payment_duration = $args['payment_duration'];
                        }
                    }

                    $isHidePlans = false;
                    if (!empty($selected_plan_id) && $selected_plan_id != 0) {
                        if (!empty($_REQUEST['hide_plans']) && $_REQUEST['hide_plans'] == 1) {
                            $isHidePlans = true;
                        }
                        if (!empty($args['hide_plans']) && $args['hide_plans'] == 1) {
                            $isHidePlans = true;
                        }
                    }

                    $is_hide_plan_selection_area = false;
                    if (isset($setup_style['hide_plans']) && $setup_style['hide_plans'] == 1) {
                        $is_hide_plan_selection_area = true;
                    }

                    $arm_two_step_class = '';
                    if($two_step){
                      if ($isHidePlans == true || $is_hide_plan_selection_area == true) {

                      }
                      else{
                        $arm_two_step_class = ' arm_hide';
                      }
                    }

                    
                    if (is_user_logged_in()) {
                        global $current_user;
                        if (!empty($current_user->data->arm_primary_status)) {
                            $current_user_status = $current_user->data->arm_primary_status;
                        } else {
                            $current_user_status = arm_get_member_status($current_user_id);
                        }
                    }
                    
                    $selected_plan_data = array();
                    $module_html = $formStyle = $setupGoogleFonts = '';
                    $errPosCCField = 'right';
                    if (is_rtl()) {
                        $is_form_class_rtl = 'arm_form_rtl';
                    } else {
                        $is_form_class_rtl = 'arm_form_ltr';
                    }
                    $form_style_class = ' arm_shortcode_form arm_form_0 arm_form_layout_writer armf_label_placeholder armf_alignment_left armf_layout_block armf_button_position_left ' . $is_form_class_rtl;
                    $btn_style_class = ' arm_btn_style_flat ';
                    if (!empty($modules['forms'])) {
                        /* Query Monitor Change */
                        if( isset($GLOBALS['arm_setup_form_settings']) && isset($GLOBALS['arm_setup_form_settings'][$modules['forms']])){
                            $form_settings = $GLOBALS['arm_setup_form_settings'][$modules['forms']];
                        } else {
                            $form_settings = $wpdb->get_var("SELECT `arm_form_settings` FROM `" . $ARMember->tbl_arm_forms . "` WHERE `arm_form_id`='" . $modules['forms'] . "'");
                            if( !isset($GLOBALS['arm_setup_form_settings']) ){
                                $GLOBALS['arm_setup_form_settings'] = array();
                            }
                            $GLOBALS['arm_setup_form_settings'][$modules['forms']] = $form_settings;
                        }
                        $form_settings = (!empty($form_settings)) ? maybe_unserialize($form_settings) : array();
                    }
                    $plan_payment_cycles = array();


                    foreach ($module_order as $module => $order) {
                        $module_content = '';
                        $arm_user_id = 0;
                        $arm_user_old_plan = 0;
                        $plan_id_array = array();
                        $arm_user_selected_payment_mode = 0;
                        $arm_user_selected_payment_cycle = 0;
                        $arm_last_payment_status = 'success';

                        switch ($module) {
                            case 'plans':

                                if (!empty($modules['plans'])) {
                                    if (is_user_logged_in()) {
                                        global $current_user;
                                        $arm_user_id = $current_user->ID;

                                        $user_firstname = $current_user->user_firstname;
                                        $user_lastname = $current_user->user_lastname;
                                        $user_email = $current_user->user_email;
                                        if($user_firstname != '' && $user_lastname != ''){
                                          $arm_user_firstname_lastname = $user_firstname. ' '.$user_lastname;
                                        }
                                        else{
                                          $arm_user_firstname_lastname = $user_email;
                                        }
                                        

                                        if (!empty($current_user_plan_ids)) {
                                            $plan_name_array = array();
                                            foreach ($current_user_plan_ids as $plan_id) {
                                                $planData = get_user_meta($arm_user_id, 'arm_user_plan_' . $plan_id, true);
                                                $arm_user_selected_payment_mode = $planData['arm_payment_mode'];
                                                $arm_user_current_plan_detail = $planData['arm_current_plan_detail'];

                                                $plan_name_array[] = isset($arm_user_current_plan_detail['arm_subscription_plan_name']) ? stripslashes($arm_user_current_plan_detail['arm_subscription_plan_name']) : '';
                                                $plan_id_array[] = $plan_id;

                                                $curPlanDetail = $planData['arm_current_plan_detail'];
                                                $completed_recurrence = $planData['arm_completed_recurring'];
                                                if (!empty($curPlanDetail)) {
                                                    $arm_user_old_plan_info = new ARM_Plan(0);
                                                    $arm_user_old_plan_info->init((object) $curPlanDetail);
                                                } else {
                                                    $arm_user_old_plan_info = new ARM_Plan($arm_user_old_plan);
                                                }
                                                $total_recurring = '';
                                                $arm_user_old_plan_options = $arm_user_old_plan_info->options;
                                                if ($arm_user_old_plan_info->is_recurring()) {
                                                    $arm_user_selected_payment_cycle = $planData['arm_payment_cycle'];
                                                    $arm_user_old_plan_data = $arm_user_old_plan_info->prepare_recurring_data($arm_user_selected_payment_cycle);
                                                    $total_recurring = $arm_user_old_plan_data['rec_time'];

                                                    $now = current_time('mysql');
                                                    
                                                    $arm_last_payment_status = $wpdb->get_var($wpdb->prepare("SELECT `arm_transaction_status` FROM `" . $ARMember->tbl_arm_payment_log . "` WHERE `arm_user_id`=%d AND `arm_plan_id`=%d AND `arm_created_date`<=%s ORDER BY `arm_log_id` DESC LIMIT 0,1", $arm_user_id, $plan_id, $now)); 

                                                }


                                                $module_content .= '<input type="hidden" data-id="arm_user_firstname_lastname" value="' . $arm_user_firstname_lastname . '">';

                                                $module_content .= '<input type="hidden" data-id="arm_user_last_payment_status_' . $plan_id . '" value="' . $arm_last_payment_status . '">';

                                                $module_content .= '<input type="hidden" data-id="arm_user_done_payment_' . $plan_id . '" value="' . $completed_recurrence . '">';
                                                $module_content .= '<input type="hidden" data-id="arm_user_old_plan_total_cycle_' . $plan_id . '" value="' . $total_recurring . '">';

                                                $module_content .= '<input type="hidden" data-id="arm_user_selected_payment_cycle_' . $plan_id . '" value="' . $arm_user_selected_payment_cycle . '">';
                                                $module_content .= '<input type="hidden" data-id="arm_user_selected_payment_mode_' . $plan_id . '" value="' . $arm_user_selected_payment_mode . '">';
                                            }
                                        }
                                        $arm_is_user_logged_in_flag = 1;
                                    } else {
                                        $arm_is_user_logged_in_flag = 0;
                                    }

                                    if (!empty($plan_id_array)) {
                                        $arm_user_old_plan = implode(",", $plan_id_array);
                                    }

                                    $module_content .= '<input type="hidden" data-id="arm_user_old_plan" name="arm_user_old_plan" value="' . $arm_user_old_plan . '">';
                                    $module_content .= '<input type="hidden" name="arm_is_user_logged_in_flag" data-id="arm_is_user_logged_in_flag" value="' . $arm_is_user_logged_in_flag . '">';

                                    $planOrders = (isset($modules['plans_order']) && !empty($modules['plans_order'])) ? $modules['plans_order'] : array();
                                    if (!empty($planOrders)) {
                                        asort($planOrders);
                                    }
                                    $plans = $this->armSortModuleOrders($modules['plans'], $planOrders);
                                    if (!empty($plans)) {
                                        $all_active_plans = $arm_subscription_plans->arm_get_all_active_subscription_plans();
                                        $is_hide_class = '';
                                        if ($isHidePlans == true || $is_hide_plan_selection_area == true) {
                                            $is_hide_class = 'style="display:none;"';
                                        }
                                        $form_no = '';

                                        $form_layout = '';
                                        if (!empty($modules['forms']) && $modules['forms'] != 0) {
                                            
                                            if (!empty($form_settings)) {
                                                $form_no = 'arm_form_' . $modules['forms'];
                                                $form_layout = ' arm_form_layout_' . $form_settings['style']['form_layout'];
                                            }
                                        }

                                        if (!empty($current_user_plan_ids)) {

                                            $module_content .= '<div class="arm_current_user_plan_info">' . __('Your Current Membership', 'ARMember') . ': <span>' . implode(", ", $plan_name_array) . '</span></div>';
                                        }
                                       
                                        $module_content .= '<div class="arm_module_plans_main_container"><div class="arm_module_plans_container arm_module_box ' . $form_no . ' ' . $form_layout . '" ' . $is_hide_class . '>';

                                        
                                        $column_type = (!empty($setup_modules['plans_columns'])) ? $setup_modules['plans_columns'] : '1';
                                        $module_content .= '<input type="hidden" name="arm_front_plan_skin_type" data-id="arm_front_plan_skin_type" value="' . $setup_style['plan_skin'] . '">';
                                        $allowed_payment_gateways = array();

                                        if($hide_current_plans == 1){
                                            if(!empty($current_user_plan_ids)){
                                                $plans = array_diff($plans, $current_user_plan_ids);
                                            }
                                        }
                                        if ($setup_style['plan_skin'] == 'skin5') {
                                            $planSkinFloat = "float:none;";
                                            switch ($formPosition) {
                                                case 'left':
                                                    $planSkinFloat = "";
                                                    break;
                                                case 'right':
                                                    $planSkinFloat = "float:right;";
                                                    break;
                                            }
                                            $module_content .= '<div class="arm_form_input_container arm_container payment_plan_dropdown_skin1" style="' . $planSkinFloat . '">';
                                            $module_content .= '<div class="payment_plan_dropdown_skin">';
                                            $module_content .= '<md-select name="subscription_plan" class="arm_module_plan_input select_skin" data-ng-model="subscription_plan" aria-label="plan" ng-change="armPlanChange(\'arm_setup_form' . $setupRandomID . '\')">';
                                            
                                            $i = 0;

                                            if(empty($plans)){
                                                return;
                                            }

                                            foreach ($plans as $plan_id) {
                                                if (isset($all_active_plans[$plan_id])) {

                                                    $plan_data = $all_active_plans[$plan_id];
                                                    $planObj = new ARM_Plan(0);
                                                    $planObj->init((object) $plan_data);
                                                    $plan_type = $planObj->type;
                                                    $planText = $planObj->setup_plan_text();
                                                    if ($planObj->exists()) {
                                                        /* Checked Plan Radio According Settings. */
                                                        $plan_checked = $plan_checked_class = '';
                                                        if (!empty($selected_plan_id) && $selected_plan_id != 0 && in_array($selected_plan_id, $plans)) {
                                                            if ($selected_plan_id == $plan_id) {
                                                                $plan_checked_class = 'arm_active';
                                                                $plan_checked = 'selected="selected"';
                                                                $selected_plan_data = $plan_data;
                                                            }
                                                        } else {
                                                            if ($i == 0) {
                                                                $plan_checked_class = 'arm_active';
                                                                $plan_checked = 'selected="selected"';
                                                                $selected_plan_data = $plan_data;
                                                            }
                                                        }

                                                        /* Check Recurring Details */
                                                        $plan_options = $planObj->options;

                                                        if (is_user_logged_in()) {
                                                            if ($arm_user_old_plan == $plan_id) {
                                                                $arm_user_payment_cycles = (isset($arm_user_old_plan_options['payment_cycles']) && !empty($arm_user_old_plan_options['payment_cycles'])) ? $arm_user_old_plan_options['payment_cycles'] : array();
                                                                if (empty($arm_user_payment_cycles)) {
                                                                    $plan_amount = $planObj->amount;
                                                                    $recurring_time = isset($arm_user_old_plan_options['recurring']['time']) ? $arm_user_old_plan_options['recurring']['time'] : 'infinite';
                                                                    $recurring_type = isset($arm_user_old_plan_options['recurring']['type']) ? $arm_user_old_plan_options['recurring']['type'] : 'D';
                                                                    switch ($recurring_type) {
                                                                        case 'D':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['days']) ? $arm_user_old_plan_options['recurring']['days'] : '1';
                                                                            break;
                                                                        case 'M':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['months']) ? $arm_user_old_plan_options['recurring']['months'] : '1';
                                                                            break;
                                                                        case 'Y':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['years']) ? $arm_user_old_plan_options['recurring']['years'] : '1';
                                                                            break;
                                                                        default:
                                                                            $billing_cycle = '1';
                                                                            break;
                                                                    }
                                                                    $payment_cycles = array(array(
                                                                            'cycle_label' => $planObj->plan_text(false, false),
                                                                            'cycle_amount' => $plan_amount,
                                                                            'billing_cycle' => $billing_cycle,
                                                                            'billing_type' => $recurring_type,
                                                                            'recurring_time' => $recurring_time,
                                                                            'payment_cycle_order' => 1,
                                                                    ));
                                                                    $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                } else {
                                                                    if (($completed_recurrence == $total_recurring && $total_recurring!="infinite" ) || ($completed_recurrence == '' && $arm_user_selected_payment_mode == 'auto_debit_subscription')) {
                                                                        $arm_user_new_payment_cycles = (isset($plan_options['payment_cycles']) && !empty($plan_options['payment_cycles'])) ? $plan_options['payment_cycles'] : array();
                                                                        $plan_payment_cycles[$plan_id] = $arm_user_new_payment_cycles;
                                                                    } else {
                                                                        $plan_payment_cycles[$plan_id] = $arm_user_payment_cycles;
                                                                    }
                                                                }
                                                            } else {
                                                                if ($planObj->is_recurring()) {
                                                                    if (!empty($plan_options['payment_cycles'])) {
                                                                        $plan_payment_cycles[$plan_id] = $plan_options['payment_cycles'];
                                                                    } else {

                                                                        $plan_amount = $planObj->amount;
                                                                        $recurring_time = isset($plan_options['recurring']['time']) ? $plan_options['recurring']['time'] : 'infinite';
                                                                        $recurring_type = isset($plan_options['recurring']['type']) ? $plan_options['recurring']['type'] : 'D';
                                                                        switch ($recurring_type) {
                                                                            case 'D':
                                                                                $billing_cycle = isset($plan_options['recurring']['days']) ? $plan_options['recurring']['days'] : '1';
                                                                                break;
                                                                            case 'M':
                                                                                $billing_cycle = isset($plan_options['recurring']['months']) ? $plan_options['recurring']['months'] : '1';
                                                                                break;
                                                                            case 'Y':
                                                                                $billing_cycle = isset($plan_options['recurring']['years']) ? $plan_options['recurring']['years'] : '1';
                                                                                break;
                                                                            default:
                                                                                $billing_cycle = '1';
                                                                                break;
                                                                        }
                                                                        $payment_cycles = array(array(
                                                                                'cycle_label' => $planObj->plan_text(false, false),
                                                                                'cycle_amount' => $plan_amount,
                                                                                'billing_cycle' => $billing_cycle,
                                                                                'billing_type' => $recurring_type,
                                                                                'recurring_time' => $recurring_time,
                                                                                'payment_cycle_order' => 1,
                                                                        ));
                                                                        $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                    }
                                                                }
                                                            }
                                                        } else {
                                                            if ($planObj->is_recurring()) {
                                                                if (!empty($plan_options['payment_cycles'])) {
                                                                    $plan_payment_cycles[$plan_id] = $plan_options['payment_cycles'];
                                                                } else {
                                                                    $plan_amount = $planObj->amount;
                                                                    $recurring_time = isset($plan_options['recurring']['time']) ? $plan_options['recurring']['time'] : 'infinite';
                                                                    $recurring_type = isset($plan_options['recurring']['type']) ? $plan_options['recurring']['type'] : 'D';
                                                                    switch ($recurring_type) {
                                                                        case 'D':
                                                                            $billing_cycle = isset($plan_options['recurring']['days']) ? $plan_options['recurring']['days'] : '1';
                                                                            break;
                                                                        case 'M':
                                                                            $billing_cycle = isset($plan_options['recurring']['months']) ? $plan_options['recurring']['months'] : '1';
                                                                            break;
                                                                        case 'Y':
                                                                            $billing_cycle = isset($plan_options['recurring']['years']) ? $plan_options['recurring']['years'] : '1';
                                                                            break;
                                                                        default:
                                                                            $billing_cycle = '1';
                                                                            break;
                                                                    }
                                                                    $payment_cycles = array(array(
                                                                            'cycle_label' => $planObj->plan_text(false, false),
                                                                            'cycle_amount' => $plan_amount,
                                                                            'billing_cycle' => $billing_cycle,
                                                                            'billing_type' => $recurring_type,
                                                                            'recurring_time' => $recurring_time,
                                                                            'payment_cycle_order' => 1,
                                                                    ));
                                                                    $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                }
                                                            }
                                                        }

                                                        $payment_type = $planObj->payment_type;
                                                        $is_trial = '0';
                                                        $trial_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency, 0);
                                                        if ($planObj->is_recurring()) {
                                                            $stripePlans = (isset($modules['stripe_plans']) && !empty($modules['stripe_plans'])) ? $modules['stripe_plans'] : array();

                                                            if ($planObj->has_trial_period()) {
                                                                $is_trial = '1';
                                                                $trial_amount = !empty($plan_options['trial']['amount']) ?
                                                                        $arm_payment_gateways->arm_amount_set_separator($global_currency, $plan_options['trial']['amount']) : $trial_amount;
                                                                if (is_user_logged_in()) {
                                                                    if (!empty($current_user_plan_ids)) {
                                                                        if (in_array($planObj->ID, $current_user_plan_ids)) {
                                                                            $is_trial = '0';
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        if (!$planObj->is_free()) {
                                                            $trial_amount = !empty($plan_options['trial']['amount']) ? $arm_payment_gateways->arm_amount_set_separator($global_currency, $plan_options['trial']['amount']) : $trial_amount;
                                                        }

                                                        $allowed_payment_gateways_['paypal'] = "1";
                                                        $allowed_payment_gateways_['stripe'] = "1";
                                                        $allowed_payment_gateways_['bank_transfer'] = "1";
                                                        $allowed_payment_gateways_['2checkout'] = "1";
                                                        $allowed_payment_gateways_['authorize_net'] = "1";
                                                        $allowed_payment_gateways_ = apply_filters('arm_allowed_payment_gateways', $allowed_payment_gateways_, $planObj, $plan_options);

                                                        $data_allowed_payment_gateways = json_encode($allowed_payment_gateways_);

                                                        $arm_plan_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency, $planObj->amount);
                                                        $planInputAttr = ' data-type="' . $plan_type . '" data-plan_name="' . $planObj->name . '" data-amt="' . $arm_plan_amount . '" data-recurring="' . $payment_type . '" data-is_trial="' . $is_trial . '" data-trial_amt="' . $trial_amount . '" data-allowed_gateways=\'' . $data_allowed_payment_gateways . '\' data-plan_text="' . htmlentities($planText) . '"';

                                                        $count_total_cycle = 0;
                                                        if($planObj->is_recurring()){

                                                          $count_total_cycle = count($plan_payment_cycles[$plan_id]);
                                                          $planInputAttr .= '  " data-cycle="'.$count_total_cycle .'"';
                                                        }
                                                        else{
                                                          $planInputAttr .= " data-cycle='0'";
                                                        }
                                                        
                                                        $planInputAttr .= " data-tax='".$tax_percentage."'";

                                                        
                                                        $module_content .='<md-option value="' . $plan_id . '" class="armMDOption armSelectOption' . $setup_modules['modules']['forms'] . '" ' . $planInputAttr . ' ' . $plan_checked . '>' . $planObj->name . ' (' . $planObj->plan_price(false) . ')</md-option>';
                                                        $i++;
                                                    }
                                                }
                                            }
                                            $module_content .= '</md-select>';
                                            $module_content .= '</div></div>';
                                        } else {

                                          if($setup_style['plan_skin']  != 'skin6') {
                                            $module_content .= '<ul class="arm_module_plans_ul arm_column_' . $column_type . '" style="text-align:' . $formPosition . ';">';
                                          }
                                          else{
                                            $module_content .= '<ul class="arm_module_plans_ul arm_column_1" style="text-align:' . $formPosition . ';">';
                                          }

                                              if(empty($plans)){
                                              return;
                                             }
                                            $i = 0;
                                            foreach ($plans as $plan_id) {
                                                if (isset($all_active_plans[$plan_id])) {
                                                    $plan_data = $all_active_plans[$plan_id];
                                                    $planObj = new ARM_Plan(0);
                                                    $planObj->init((object) $plan_data);
                                                    $plan_type = $planObj->type;
                                                    $planText = $planObj->setup_plan_text();
                                                    if ($planObj->exists()) {
                                                        /* Checked Plan Radio According Settings. */
                                                        $plan_checked = $plan_checked_class = '';
                                                        if (!empty($selected_plan_id) && $selected_plan_id != 0 && in_array($selected_plan_id, $plans)) {
                                                            if ($selected_plan_id == $plan_id) {
                                                                $plan_checked_class = 'arm_active';
                                                                $plan_checked = 'checked="checked"';
                                                                $selected_plan_data = $plan_data;
                                                            }
                                                        } else {
                                                            if ($i == 0) {
                                                                $plan_checked_class = 'arm_active';
                                                                $plan_checked = 'checked="checked"';
                                                                $selected_plan_data = $plan_data;
                                                            }
                                                        }
                                                        /* Check Recurring Details */
                                                        $plan_options = $planObj->options;

                                                        if (is_user_logged_in()) {
                                                            if ($arm_user_old_plan == $plan_id) {
                                                                $arm_user_payment_cycles = (isset($arm_user_old_plan_options['payment_cycles']) && !empty($arm_user_old_plan_options['payment_cycles'])) ? $arm_user_old_plan_options['payment_cycles'] : array();
                                                                if (empty($arm_user_payment_cycles)) {
                                                                    $plan_amount = $planObj->amount;
                                                                    $recurring_time = isset($arm_user_old_plan_options['recurring']['time']) ? $arm_user_old_plan_options['recurring']['time'] : 'infinite';
                                                                    $recurring_type = isset($arm_user_old_plan_options['recurring']['type']) ? $arm_user_old_plan_options['recurring']['type'] : 'D';
                                                                    switch ($recurring_type) {
                                                                        case 'D':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['days']) ? $arm_user_old_plan_options['recurring']['days'] : '1';
                                                                            break;
                                                                        case 'M':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['months']) ? $arm_user_old_plan_options['recurring']['months'] : '1';
                                                                            break;
                                                                        case 'Y':
                                                                            $billing_cycle = isset($arm_user_old_plan_options['recurring']['years']) ? $arm_user_old_plan_options['recurring']['years'] : '1';
                                                                            break;
                                                                        default:
                                                                            $billing_cycle = '1';
                                                                            break;
                                                                    }
                                                                    $payment_cycles = array(array(
                                                                            'cycle_label' => $planObj->plan_text(false, false),
                                                                            'cycle_amount' => $plan_amount,
                                                                            'billing_cycle' => $billing_cycle,
                                                                            'billing_type' => $recurring_type,
                                                                            'recurring_time' => $recurring_time,
                                                                            'payment_cycle_order' => 1,
                                                                    ));
                                                                    $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                } else {

                                                                    if (($completed_recurrence == $total_recurring && $total_recurring!="infinite" ) || ($completed_recurrence == '' && $arm_user_selected_payment_mode == 'auto_debit_subscription')) {

                                                                        $arm_user_new_payment_cycles = (isset($plan_options['payment_cycles']) && !empty($plan_options['payment_cycles'])) ? $plan_options['payment_cycles'] : array();
                                                                        $plan_payment_cycles[$plan_id] = $arm_user_new_payment_cycles;
                                                                    } else {
                                                                        $plan_payment_cycles[$plan_id] = $arm_user_payment_cycles;
                                                                    }
                                                                }
                                                            } else {
                                                                if ($planObj->is_recurring()) {
                                                                    if (!empty($plan_options['payment_cycles'])) {
                                                                        $plan_payment_cycles[$plan_id] = $plan_options['payment_cycles'];
                                                                    } else {

                                                                        $plan_amount = $planObj->amount;
                                                                        $recurring_time = isset($plan_options['recurring']['time']) ? $plan_options['recurring']['time'] : 'infinite';
                                                                        $recurring_type = isset($plan_options['recurring']['type']) ? $plan_options['recurring']['type'] : 'D';
                                                                        switch ($recurring_type) {
                                                                            case 'D':
                                                                                $billing_cycle = isset($plan_options['recurring']['days']) ? $plan_options['recurring']['days'] : '1';
                                                                                break;
                                                                            case 'M':
                                                                                $billing_cycle = isset($plan_options['recurring']['months']) ? $plan_options['recurring']['months'] : '1';
                                                                                break;
                                                                            case 'Y':
                                                                                $billing_cycle = isset($plan_options['recurring']['years']) ? $plan_options['recurring']['years'] : '1';
                                                                                break;
                                                                            default:
                                                                                $billing_cycle = '1';
                                                                                break;
                                                                        }
                                                                        $payment_cycles = array(array(
                                                                                'cycle_label' => $planObj->plan_text(false, false),
                                                                                'cycle_amount' => $plan_amount,
                                                                                'billing_cycle' => $billing_cycle,
                                                                                'billing_type' => $recurring_type,
                                                                                'recurring_time' => $recurring_time,
                                                                                'payment_cycle_order' => 1,
                                                                        ));
                                                                        $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                    }
                                                                }
                                                            }
                                                        } else {
                                                            if ($planObj->is_recurring()) {
                                                                if (!empty($plan_options['payment_cycles'])) {
                                                                    $plan_payment_cycles[$plan_id] = $plan_options['payment_cycles'];
                                                                } else {
                                                                    $plan_amount = $planObj->amount;
                                                                    $recurring_time = isset($plan_options['recurring']['time']) ? $plan_options['recurring']['time'] : 'infinite';
                                                                    $recurring_type = isset($plan_options['recurring']['type']) ? $plan_options['recurring']['type'] : 'D';
                                                                    switch ($recurring_type) {
                                                                        case 'D':
                                                                            $billing_cycle = isset($plan_options['recurring']['days']) ? $plan_options['recurring']['days'] : '1';
                                                                            break;
                                                                        case 'M':
                                                                            $billing_cycle = isset($plan_options['recurring']['months']) ? $plan_options['recurring']['months'] : '1';
                                                                            break;
                                                                        case 'Y':
                                                                            $billing_cycle = isset($plan_options['recurring']['years']) ? $plan_options['recurring']['years'] : '1';
                                                                            break;
                                                                        default:
                                                                            $billing_cycle = '1';
                                                                            break;
                                                                    }
                                                                    $payment_cycles = array(array(
                                                                            'cycle_label' => $planObj->plan_text(false, false),
                                                                            'cycle_amount' => $plan_amount,
                                                                            'billing_cycle' => $billing_cycle,
                                                                            'billing_type' => $recurring_type,
                                                                            'recurring_time' => $recurring_time,
                                                                            'payment_cycle_order' => 1,
                                                                    ));
                                                                    $plan_payment_cycles[$plan_id] = $payment_cycles;
                                                                }
                                                            }
                                                        }

                                                        $payment_type = $planObj->payment_type;

                                                        $is_trial = '0';
                                                        $trial_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency, 0);

                                                        if ($planObj->is_recurring()) {
                                                            $stripePlans = (isset($modules['stripe_plans']) && !empty($modules['stripe_plans'])) ? $modules['stripe_plans'] : array();

                                                            if ($planObj->has_trial_period()) {
                                                                $is_trial = '1';
                                                                $trial_amount = !empty($plan_options['trial']['amount']) ? $arm_payment_gateways->arm_amount_set_separator($global_currency, $plan_options['trial']['amount']) : $trial_amount;
                                                                if (is_user_logged_in()) {
                                                                    if (!empty($current_user_plan_ids)) {
                                                                        if (in_array($planObj->ID, $current_user_plan_ids)) {
                                                                            $is_trial = '0';
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        $allowed_payment_gateways_['paypal'] = "1";
                                                        $allowed_payment_gateways_['stripe'] = "1";
                                                        $allowed_payment_gateways_['bank_transfer'] = "1";
                                                        $allowed_payment_gateways_['2checkout'] = "1";
                                                        $allowed_payment_gateways_['authorize_net'] = "1";
                                                        $allowed_payment_gateways_ = apply_filters('arm_allowed_payment_gateways', $allowed_payment_gateways_, $planObj, $plan_options);
                                                        $data_allowed_payment_gateways = json_encode($allowed_payment_gateways_);
                                                        $arm_plan_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency, $planObj->amount);
                                                        $planInputAttr = ' data-type="' . $plan_type . '" data-plan_name="' . $planObj->name . '" data-amt="' . $arm_plan_amount . '" data-recurring="' . $payment_type . '" data-is_trial="' . $is_trial . '" data-trial_amt="' . $trial_amount . '"  data-allowed_gateways=\'' . $data_allowed_payment_gateways . '\' data-plan_text="' . htmlentities($planText) . '"';

                                                        $count_total_cycle = 0;
                                                        if($planObj->is_recurring()){

                                                          $count_total_cycle = count($plan_payment_cycles[$plan_id]);
                                                          $planInputAttr .= '  " data-cycle="'.$count_total_cycle .'"';
                                                        }
                                                        else{
                                                          $planInputAttr .= " data-cycle='0'";
                                                        }

                                                        
                                                        $planInputAttr .= " data-tax='".$tax_percentage."'";


                                                        if ($setup_style['plan_skin'] == '') {
                                                            $module_content .= '<li class="arm_plan_default_skin arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            $module_content .= '<span class="arm_setup_check_circle"><i class="armfa armfa-check"></i></span>';
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span>';
                                                            $module_content .= '<div class="arm_module_plan_price_type"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        }else if ($setup_style['plan_skin'] == 'skin6') {
                                                            $module_content .= '<li class="arm_plan_skin6 arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            $module_content .= '<div class="arm_plan_skin6_left_box"><div class="arm_plan_name_box">';
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span></div>';
                                                           if(!empty($planObj->description)){
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
}
                                                             $module_content .= '</div>';


                                                             $module_content .= '<div class="arm_plan_skin6_right_box"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        }   else if ($setup_style['plan_skin'] == 'skin1') {
                                                            $module_content .= '<li class="arm_plan_skin1 arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span>';
                                                            $module_content .= '<div class="arm_module_plan_price_type"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
                                                            /* $module_content .= $setup_info; */
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        } else if ($setup_style['plan_skin'] == 'skin3') {
                                                            $module_content .= '<li class="arm_plan_skin3 arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            $module_content .= '<div class="arm_plan_name_box"><span class="arm_setup_check_circle"><i class="armfa armfa-check"></i></span>';
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_price_type"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
                                                            /* $module_content .= $setup_info; */
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        } else {
                                                            $module_content .= '<li class="arm_plan_skin2 arm_setup_column_item ' . $plan_checked_class . '">';
                                                            $module_content .= '<label class="arm_module_plan_option" id="arm_subscription_plan_option_' . $plan_id . '">';
                                                            
                                                            $module_content .= '<input type="radio" name="subscription_plan" data-id="subscription_plan_' . $plan_id . '" class="arm_module_plan_input" value="' . $plan_id . '" ' . $planInputAttr . ' ' . $plan_checked . ' required>';
                                                            $module_content .= '<span class="arm_module_plan_name">' . $planObj->name . '</span>';
                                                            $module_content .= '<div class="arm_module_plan_price_type"><span class="arm_module_plan_price">' . $planObj->plan_price(false) . '</span></div>';
                                                            $module_content .= '<div class="arm_module_plan_description">' . $planObj->description . '</div>';
                                                            /* $module_content .= $setup_info; */
                                                            $module_content .= '</label>';
                                                            $module_content .= '</li>';
                                                        }
                                                        $i++;
                                                    }
                                                }
                                            }
                                            $module_content .= '</ul>';
                                        }
                                        $module_content .= '</div></div>';
                                        $module_content = apply_filters('arm_after_setup_plan_section', $module_content, $setupID, $setup_data);
                                        $module_content .= '<div class="armclear"></div>';
                                        $module_content .= '<input type="hidden" data-ng-model="arm_form.arm_plan_type" name="arm_plan_type" value="' . ((!empty($selected_plan_data['arm_subscription_plan_type']) && $selected_plan_data['arm_subscription_plan_type'] == 'free') ? 'free' : 'paid') . '">';
                                    }
                                }

                                break;
                            case 'forms':

                                if (!empty($modules['forms']) && $modules['forms'] != 0) {
                                    
                                    if (!empty($form_settings)) {
                                        $form_style_class = 'arm_shortcode_form arm_form_' . $modules['forms'];
                                        $form_style_class .= ' arm_form_layout_' . $form_settings['style']['form_layout'];
                                        $form_style_class .= ($form_settings['style']['label_hide'] == '1') ? ' armf_label_placeholder' : '';
                                        $form_style_class .= ' armf_alignment_' . $form_settings['style']['label_align'];
                                        $form_style_class .= ' armf_layout_' . $form_settings['style']['label_position'];
                                        $form_style_class .= ' armf_button_position_' . $form_settings['style']['button_position'];
                                        $form_style_class .= ($form_settings['style']['rtl'] == '1') ? ' arm_form_rtl' : ' arm_form_ltr';
                                        $errPosCCField = !empty($form_settings['style']['validation_position']) ? $form_settings['style']['validation_position'] : 'bottom';
                                        $buttonStyle = (isset($form_settings['style']['button_style']) && !empty($form_settings['style']['button_style'])) ? $form_settings['style']['button_style'] : 'flat';
                                        $btn_style_class = ' arm_btn_style_' . $buttonStyle;

                                        $fieldPosition = !empty($form_settings['style']['field_position']) ? $form_settings['style']['field_position'] : 'left';
                                    }


                                      if($two_step){
                                  $module_content .= '<div class="arm_setup_submit_btn_wrapper ' . $form_style_class . ' arm_setup_two_step_next_wrapper" '.$is_hide_class.'>';
                                  $module_content .=   '<div class="arm_form_field_container arm_form_field_container_submit">';
                                 
                                  $module_content .=   '<div class="arm_form_input_wrapper">';
                                  $module_content .=  '<div class="arm_form_input_container_submit arm_form_input_container" id="arm_setup_form_input_container' . $setupID . '">';
                              
                                
                                  $module_content .=   '<md-button type="button" class="arm_form_field_submit_button arm_material_input ' . $btn_style_class . '" data-id="arm_setup_two_step_next">' . html_entity_decode(stripslashes($next_button_label)) . '</md-button>';
                                  $module_content .=  '</div>';
                                  $module_content .=  '</div>';
                                  $module_content .=  '</div>';
                                  $module_content .=  '</div>';


                                  $module_content .= '<div class="arm_setup_submit_btn_wrapper ' . $form_style_class . ' arm_setup_two_step_previous_wrapper arm_hide" '.$is_hide_class.'>';
                                  $module_content .=   '<div class="arm_form_field_container arm_form_field_container_submit">';
                                 
                                  $module_content .=   '<div class="arm_form_input_wrapper">';
                                  $module_content .=  '<div class="arm_form_input_container_submit arm_form_input_container" id="arm_setup_form_input_container' . $setupID . '">';
                              
                                
                                  $module_content .=   '<md-button type="button" class="arm_form_field_submit_button arm_material_input ' . $btn_style_class . '" data-id="arm_setup_two_step_previous">' . html_entity_decode(stripslashes($previuos_button_label)) . '</md-button>';
                                  $module_content .=  '</div>';
                                  $module_content .=  '</div>';
                                  $module_content .=  '</div>';
                                  $module_content .=  '</div>';
                                }



                                    if (is_user_logged_in() && !$isPreview) {
                                      $form = new ARM_Form('id', $modules['forms']);
                                      $ref_template = $form->form_detail['arm_ref_template'];
                                        $form_css = $arm_member_forms->arm_ajax_generate_form_styles($modules['forms'], $form_settings, array(), $ref_template);
                                        $formStyle .= $form_css['arm_css'];
                                        $modules['forms'] = 0;
                                        $setupGoogleFonts .= $form_css['arm_link'];
                                        
                                    } else {
                                        $formAttr = '';
                                        if ($isPreview) {
                                            $formAttr = 'preview="true"';
                                        }
                                        $module_content .= '<div class="arm_module_forms_main_container'.$arm_two_step_class.'"><div class="arm_module_forms_container arm_module_box" data-ng-cloak="">';
                                        $module_content .= do_shortcode('[arm_form id="' . $modules['forms'] . '" setup="true" form_position="' . $formPosition . '" ' . $formAttr . ' setup_form_id="'.$setupRandomID.'"]');
                                        $module_content .= '</div>';
                                        $module_content = apply_filters('arm_after_setup_reg_form_section', $module_content, $setupID, $setup_data);
                                        $module_content .= '<div class="armclear"></div></div>';
                                    }
                                } else {
                                    if (!$isPreview) {
                                        /* Hide Setup Form for non-logged in users when there is no form configured */
                                        return '';
                                    }
                                }
                                break;
                            case 'note':
                                if (isset($setup_modules['note']) && !empty($setup_modules['note'])) {
                                    $module_content .= '<div class="arm_module_note_main_container'.$arm_two_step_class.'"><div class="arm_module_note_container arm_module_box">';
                                    $module_content .= apply_filters('the_content', stripslashes($setup_modules['note']));
                                    $module_content .= '</div></div>';
                                }
                                break;
                            case 'payment_cycle':
                                $form_layout = '';
                                if (!empty($form_settings)) {
                                    $form_layout = ' arm_form_layout_' . $form_settings['style']['form_layout'];
                                }
                                $payment_mode = "both";

                                $module_content .= '<div class="arm_setup_paymentcyclebox_main_wrapper" '.$is_hide_class.'><div class="arm_setup_paymentcyclebox_wrapper arm_hide">';

                                if (!empty($plan_payment_cycles)) {

                                    foreach ($plan_payment_cycles as $payment_cycle_plan_id => $plan_payment_cycle_data) {

                                        $arm_user_selected_payment_cycle = 0;

                                        if($selected_plan_id == $payment_cycle_plan_id){
                                           $arm_user_selected_payment_cycle = $selected_payment_duration -1;
                                        }

                                        if (in_array($payment_cycle_plan_id, $current_user_plan_ids) ) {
                                          $current_plan_data = get_user_meta($current_user_id, 'arm_user_plan_' . $payment_cycle_plan_id, true);

                                            $arm_user_selected_payment_cycle = (isset($current_plan_data['arm_payment_cycle']) && !empty($current_plan_data['arm_payment_cycle'])) ? $current_plan_data['arm_payment_cycle'] : 0;
                                        }

                                        
                                        if (!empty($plan_payment_cycle_data)) {
                                            $module_content .= '<div class="arm_module_payment_cycle_container arm_module_box arm_payment_cycle_box_' . $payment_cycle_plan_id . ' arm_form_' . $setup_modules['modules']['forms'] . ' ' . $form_layout .' arm_hide">';
                                            if (isset($setup_data['setup_labels']['payment_cycle_section_title']) && !empty($setup_data['setup_labels']['payment_cycle_section_title'])) {
                                                $module_content .= '<div class="arm_setup_section_title_wrapper arm_setup_payment_cycle_title_wrapper arm_hide" style="text-align:' . $formPosition . ';">' . $setup_data['setup_labels']['payment_cycle_section_title'] . '</div>';
                                            } else {
                                                $module_content .= '<div class="arm_setup_section_title_wrapper arm_setup_payment_cycle_title_wrapper arm_hide" style="text-align:' . $formPosition . ';">' . __('Select Payment Cycle', 'ARMember') . '</div>';
                                            }
                                            $column_type = (!empty($setup_modules['cycle_columns'])) ? $setup_modules['cycle_columns'] : '1';

                                            if (is_array($plan_payment_cycle_data)) {
                                                if (count($plan_payment_cycle_data) <= $arm_user_selected_payment_cycle) {
                                                    $arm_user_selected_payment_cycle_no = 0;
                                                } else {
                                                    $arm_user_selected_payment_cycle_no = $arm_user_selected_payment_cycle;
                                                }

                                                $module_content .= '<input type="hidden" name="arm_payment_cycle_plan_'.$payment_cycle_plan_id.'" data-id="arm_payment_cycle_plan_'.$payment_cycle_plan_id.'" value="'.$arm_user_selected_payment_cycle_no.'">';
                                              }

                                            if($setup_style['plan_skin'] == 'skin5'){
                                              if (is_array($plan_payment_cycle_data)) {

                                                $paymentSkinFloat = "float:none;";
                                            switch ($formPosition) {
                                                case 'left':
                                                    $paymentSkinFloat = "";
                                                    break;
                                                case 'right':
                                                    $paymentSkinFloat = "float:right;";
                                                    break;
                                            }
                                            $module_content .= '<div class="arm_form_input_container arm_container payment_gateway_dropdown_skin1" style="' . $paymentSkinFloat . '">';
                                            $module_content .= '<div class="payment_gateway_dropdown_skin">';

                                               $module_content .= '<md-select name="payment_cycle_' . $payment_cycle_plan_id . '" class="arm_module_cycle_input select_skin" data-ng-model="payment_cycle_'.$payment_cycle_plan_id.'" ng-change="armPaymentCycleChange('.$payment_cycle_plan_id.', \'arm_setup_form' . $setupRandomID . '\')">';
                                               
                                              $i = 0;

                                              foreach ($plan_payment_cycle_data as $arm_cycle_data_key => $arm_cycle_data) {

                                                    $pc_checked = $pc_checked_class = '';
                                                    if ($i == $arm_user_selected_payment_cycle_no) {
                                                        $pc_checked = 'selected="selected""';
                                                        $pc_checked_class = 'arm_active';
                                                    }


                                                    $arm_paymentg_cycle_amount = (isset($arm_cycle_data['cycle_amount'])) ? $arm_payment_gateways->arm_amount_set_separator($global_currency, $arm_cycle_data['cycle_amount']) : 0;
                                                    $arm_paymentg_cycle_label = (isset($arm_cycle_data['cycle_label'])) ? $arm_cycle_data['cycle_label'] : '';

                                                    

                                                    $planCycleInputAttr = " data-tax='".$tax_percentage."'";



                                                    $module_content .='<md-option value="' . $arm_cycle_data_key  . '" class="armMDOption armSelectOption' . $setup_modules['modules']['forms'] . '" ' . $pc_checked . ' data-cycle_type="recurring" data-plan_id="' . $payment_cycle_plan_id . '" data-plan_amount = "' . $arm_paymentg_cycle_amount . '" '.$planCycleInputAttr.' '.$planCycleInputAttr.'>' . $arm_paymentg_cycle_label . '</md-option>';


                                                    $i++;
                                                }
                                                  $module_content .= '</md-select></div></div>';
                                              
                                            }


                                            }else{
                                                $module_content .= '<ul class="arm_module_payment_cycle_ul arm_column_' . $column_type . '">';
                                            $i = 0;

                                            if (is_array($plan_payment_cycle_data)) {
                                                
                                                foreach ($plan_payment_cycle_data as $arm_cycle_data_key => $arm_cycle_data) {

                                                    $pc_checked = $pc_checked_class = '';
                                                    if ($i == $arm_user_selected_payment_cycle_no) {
                                                        $pc_checked = 'checked="checked"';
                                                        $pc_checked_class = 'arm_active';
                                                    }


                                                    $arm_paymentg_cycle_amount = (isset($arm_cycle_data['cycle_amount'])) ? $arm_payment_gateways->arm_amount_set_separator($global_currency, $arm_cycle_data['cycle_amount']) : 0;
                                                    $arm_paymentg_cycle_label = (isset($arm_cycle_data['cycle_label'])) ? $arm_cycle_data['cycle_label'] : '';

                                                   
                                                    $planCycleInputAttr = " data-tax='".$tax_percentage."'";

                                                    $pc_content = '<label class="arm_module_payment_cycle_option">';
                                                    $pc_content .= '<span class="arm_setup_check_circle"><i class="armfa armfa-check"></i></span>';
                                                    $pc_content .= '<input type="radio" name="payment_cycle_' . $payment_cycle_plan_id . '" class="arm_module_cycle_input" value="' . ( $arm_cycle_data_key ) . '" ' . $pc_checked . ' data-ng-model="arm_form.payment_cycle" data-cycle_type="recurring" data-plan_id="' . $payment_cycle_plan_id . '" data-plan_amount = "' . $arm_paymentg_cycle_amount . '" '.$planCycleInputAttr.'>';
                                                    
                                                    $pc_content .= '<div class="arm_module_payment_cycle_name"><span class="arm_module_payment_cycle_span">' . $arm_paymentg_cycle_label . '</span></div>';
                                                    $pc_content .= '</label>';

                                                    $module_content .= '<li class="arm_setup_column_item arm_payment_cycle_' . ( $arm_cycle_data_key ) . ' ' . $pc_checked_class . '"  data-plan_id="' . $payment_cycle_plan_id . '">';
                                                    $module_content .= $pc_content;
                                                    $module_content .= '</li>';
                                                    $i++;
                                                }
                                            }
                                            $module_content .= '</ul>';
                                            } 
                                            $module_content .= '</div>';
                                        }
                                    }
                                }
                                $module_content = apply_filters('arm_after_setup_payment_cycle_section', $module_content, $setupID, $setup_data);
                                $module_content .= '</div></div>';

                                

                                break;
                            case 'gateways':

                                $form_layout = '';

                                if (!empty($form_settings)) {

                                    $form_layout = ' arm_form_layout_' . $form_settings['style']['form_layout'];
                                }

                                $payment_mode = "both";
                                if (!empty($modules['gateways'])) {
                                    $payment_gateway_skin = (isset($setup_style['gateway_skin']) && $setup_style['gateway_skin'] != '' ) ? $setup_style['gateway_skin'] : 'radio';
                                    $gatewayOrders = array();
                                    $gatewayOrders = (isset($modules['gateways_order']) && !empty($modules['gateways_order'])) ? $modules['gateways_order'] : array();
                                    if (!empty($gatewayOrders)) {
                                        asort($gatewayOrders);
                                    }
                                    $gateways = $this->armSortModuleOrders($modules['gateways'], $gatewayOrders);
                                    if (!empty($gateways)) {
                                        $active_gateways = $arm_payment_gateways->arm_get_active_payment_gateways();
                                        $is_display_pg = (!empty($selected_plan_data['arm_subscription_plan_type']) && $selected_plan_data['arm_subscription_plan_type'] == 'free') ? 'display:none;' : '';
                                        $module_content .= '<div class="arm_setup_gatewaybox_main_wrapper'.$arm_two_step_class.'"><div class="arm_setup_gatewaybox_wrapper" style="' . $is_display_pg . '">';
                                        if (isset($setup_data['setup_labels']['payment_section_title']) && !empty($setup_data['setup_labels']['payment_section_title'])) {
                                            $module_content .= '<div class="arm_setup_section_title_wrapper" style="text-align:' . $formPosition . ';">' . $setup_data['setup_labels']['payment_section_title'] . '</div>';
                                        }
                                        $module_content .= '<input type="hidden" name="arm_front_gateway_skin_type" data-id="arm_front_gateway_skin_type" value="' . $payment_gateway_skin . '">';
                                        $module_content .= '<div class="arm_module_gateways_container arm_module_box arm_form_' . $setup_modules['modules']['forms'] . ' ' . $form_layout . '">';

                                        $column_type = (!empty($setup_modules['gateways_columns'])) ? $setup_modules['gateways_columns'] : '1';

                                        $doNotDisplayPaymentMode = array('bank_transfer');
                                        $doNotDisplayPaymentMode = apply_filters('arm_not_display_payment_mode_setup', $doNotDisplayPaymentMode);

                                        $pglabels = isset($setup_data['arm_setup_labels']['payment_gateway_labels']) ? $setup_data['arm_setup_labels']['payment_gateway_labels'] : array();

                                        if ($payment_gateway_skin == 'radio') {

                                            $module_content .= '<ul class="arm_module_gateways_ul arm_column_' . $column_type .'" style="text-align:' . $formPosition . ';">';
                                            $i = 0;
                                            $pg_fields = $selectedKey = '';

                                            foreach ($gateways as $pg) {
                                                if (in_array($pg, array_keys($active_gateways))) {
                                                    if (isset($selected_plan_data['arm_subscription_plan_options']['trial']['is_trial_period']) && $pg == 'stripe' && $selected_plan_data['arm_subscription_plan_options']['payment_type'] == 'subscription') {
                                                        
                                                        if ($selected_plan_data['arm_subscription_plan_options']['trial']['amount'] > 0) {
                                                            // continue;
                                                        }
                                                    }
                                                    if (!in_array($pg, $doNotDisplayPaymentMode)) {
                                                        $payment_mode = $modules['payment_mode'][$pg];
                                                    } else {
                                                        $payment_mode = 'manual_subscription';
                                                    }

                                                    $pg_options = $active_gateways[$pg];
                                                    $pg_checked = $pg_checked_class = '';
                                                    $display_block = 'arm_hide';
                                                    if ($i == 0) {
                                                        $pg_checked = 'checked="checked"';
                                                        $pg_checked_class = 'arm_active';
                                                        $display_block = '';
                                                        $selectedKey = $pg;
                                                    }
                                                    $pg_content = '<label class="arm_module_gateway_option">';
                                                    $pg_content .= '<span class="arm_setup_check_circle"><i class="armfa armfa-check"></i></span>';
                                                    $pg_content .= '<input type="radio" name="payment_gateway" class="arm_module_gateway_input" value="' . $pg . '" ' . $pg_checked . ' data-payment_mode="' . $payment_mode . '" data-ng-model="arm_form.payment_gateway">';
                                                    if (!empty($pglabels)) {
                                                      if(isset($pglabels[$pg])){
                                                        $pg_options['gateway_name'] = $pglabels[$pg];
                                                      }
                                                    }
                                                    
                                                    $pg_content .= '<div class="arm_module_gateway_name"><span class="arm_module_gateway_span">' . $pg_options['gateway_name'] . '</span></div>';
                                                    $pg_content .= '</label>';
                                                    switch ($pg) {
                                                        case 'paypal':
                                                            break;
                                                        case 'stripe':
                                                            if ($pg_options['stripe_payment_mode'] == 'live') {
                                                                $apikey = $pg_options['stripe_pub_key'];
                                                            } else {
                                                                $apikey = $pg_options['stripe_test_pub_key'];
                                                            }
                                                            $pg_fields .= '<script data-cfasync="false" type="text/javascript" src="https://js.stripe.com/v2/"></script>';
                                                            $pg_fields .= '<script data-cfasync="false">jQuery(window).load(function () {Stripe.setPublishableKey("' . $apikey . '");});</script>';
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_stripe ' . $display_block . ' arm_member_form_container">';
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_credit_card_box('stripe', $column_type, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        case 'authorize_net':
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_authorize_net ' . $display_block . ' arm_member_form_container">';
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_credit_card_box('authorize_net', $column_type, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        case '2checkout':
                                                            break;
                                                        case 'bank_transfer':
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_bank_transfer ' . $display_block . ' arm_member_form_container">';
                                                            if (isset($pg_options['note']) && !empty($pg_options['note'])) {
                                                                $pg_fields .= '<div class="arm_bank_transfer_note_container">' . stripslashes(nl2br($pg_options['note'])) . '</div>';
                                                            }
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_bank_transfer_form($pg_options, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        default:
                                                            $gateway_fields = apply_filters('arm_membership_setup_gateway_option', '', $pg, $pg_options);
                                                            $pgHasCCFields = apply_filters('arm_payment_gateway_has_ccfields', false, $pg, $pg_options);
                                                            if ($pgHasCCFields) {
                                                                $gateway_fields .= $arm_payment_gateways->arm_get_credit_card_box($pg, $column_type, $fieldPosition, $errPosCCField);
                                                            }
                                                            if (!empty($gateway_fields)) {
                                                                $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_' . $pg . ' ' . $display_block . ' arm_member_form_container">';
                                                                $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                                $pg_fields .= $gateway_fields;
                                                                $pg_fields .= '</div>';
                                                                $pg_fields .= '</div>';
                                                            }
                                                            break;
                                                    }
                                                    $module_content .= '<li class="arm_setup_column_item arm_gateway_' . $pg . ' ' . $pg_checked_class . '">';
                                                    $module_content .= $pg_content;
                                                    $module_content .= '</li>';
                                                    $i++;
                                                    $module_content .= "<input type='hidden' name='arm_payment_mode[$pg]'  value='{$payment_mode}' />";
                                                }
                                            }
                                            $module_content .= '</ul>';
                                        } else {
                                            $paymentSkinFloat = "float:none;";
                                            switch ($formPosition) {
                                                case 'left':
                                                    $paymentSkinFloat = "";
                                                    break;
                                                case 'right':
                                                    $paymentSkinFloat = "float:right;";
                                                    break;
                                            }
                                            $module_content .= '<div class="arm_form_input_container arm_container payment_gateway_dropdown_skin1" style="' . $paymentSkinFloat . '">';
                                            $module_content .= '<div class="payment_gateway_dropdown_skin">';
                                            $module_content .= '<md-select name="payment_gateway" class="arm_module_gateway_input select_skin" data-ng-model="payment_gateway" aria-label="gateway" ng-change="armPaymentGatewayChange(\'arm_setup_form' . $setupRandomID . '\')">';
                                            $i = 0;
                                            $pg_fields = $selectedKey = '';
                                            foreach ($gateways as $pg) {
                                                if (in_array($pg, array_keys($active_gateways))) {
                                                    $payment_gateway_name = $pg;
                                                    if (isset($selected_plan_data['arm_subscription_plan_options']['trial']['is_trial_period']) && $pg == 'stripe' && $selected_plan_data['arm_subscription_plan_options']['payment_type'] == 'subscription') {
                                                        
                                                        if ($selected_plan_data['arm_subscription_plan_options']['trial']['amount'] > 0) {
                                                            // continue;
                                                        }
                                                    }

                                                    if (!in_array($pg, $doNotDisplayPaymentMode)) {
                                                        $payment_mode = $modules['payment_mode'][$pg];
                                                    } else {
                                                        $payment_mode = 'manual_subscription';
                                                    }


                                                    $pg_options = $active_gateways[$pg];
                                                    $pg_checked = $pg_checked_class = '';
                                                    $display_block = 'arm_hide';
                                                    if ($i == 0) {
                                                        $pg_checked = 'selected="selected"';
                                                        $pg_checked_class = 'arm_active';
                                                        $display_block = '';
                                                        $selectedKey = $pg;
                                                    }

                                                    switch ($pg) {
                                                        case 'paypal':
                                                            break;
                                                        case 'stripe':
                                                            if ($pg_options['stripe_payment_mode'] == 'live') {
                                                                $apikey = $pg_options['stripe_pub_key'];
                                                            } else {
                                                                $apikey = $pg_options['stripe_test_pub_key'];
                                                            }
                                                            $pg_fields .= '<script data-cfasync="false" type="text/javascript" src="https://js.stripe.com/v2/"></script>';
                                                            $pg_fields .= '<script data-cfasync="false">jQuery(window).load(function () {Stripe.setPublishableKey("' . $apikey . '");});</script>';
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_stripe ' . $display_block . ' arm_member_form_container">';
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_credit_card_box('stripe', $column_type, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        case 'authorize_net':
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_authorize_net ' . $display_block . ' arm_member_form_container">';
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_credit_card_box('authorize_net', $column_type, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        case '2checkout':
                                                            break;
                                                        case 'bank_transfer':
                                                            $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_bank_transfer ' . $display_block . ' arm_member_form_container">';
                                                            if (isset($pg_options['note']) && !empty($pg_options['note'])) {
                                                                $pg_fields .= '<div class="arm_bank_transfer_note_container">' . stripslashes(nl2br($pg_options['note'])) . '</div>';
                                                            }
                                                            $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                            $pg_fields .= $arm_payment_gateways->arm_get_bank_transfer_form($pg_options, $fieldPosition, $errPosCCField);
                                                            $pg_fields .= '</div>';
                                                            $pg_fields .= '</div>';
                                                            break;
                                                        default:
                                                            $gateway_fields = apply_filters('arm_membership_setup_gateway_option', '', $pg, $pg_options);
                                                            $pgHasCCFields = apply_filters('arm_payment_gateway_has_ccfields', false, $pg, $pg_options);
                                                            if ($pgHasCCFields) {
                                                                $gateway_fields .= $arm_payment_gateways->arm_get_credit_card_box($pg, $column_type, $fieldPosition, $errPosCCField);
                                                            }
                                                            if (!empty($gateway_fields)) {
                                                                $pg_fields .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_' . $pg . ' ' . $display_block . ' arm_member_form_container">';
                                                                $pg_fields .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                                                $pg_fields .= $gateway_fields;
                                                                $pg_fields .= '</div>';
                                                                $pg_fields .= '</div>';
                                                            }
                                                            break;
                                                    }


                                                    
                                                    if (!empty($pglabels)) {
                                                      if(isset($pglabels[$pg])){
                                                        $pg_options['gateway_name'] = $pglabels[$pg];
                                                      }
                                                    }
                                                    $module_content .='<md-option value="' . $payment_gateway_name . '" class="armMDOption armSelectOption' . $setup_modules['modules']['forms'] . ' arm_gateway_' . $payment_gateway_name . '" ' . $pg_checked . ' data-payment_mode="' . $payment_mode . '">' . $pg_options['gateway_name'] . '</md-option>';
                                                    $i++;
                                                    $module_content .= "<input type='hidden' name='arm_payment_mode[$pg]'  value='{$payment_mode}' />";
                                                }
                                            }
                                            $module_content .= '</md-select>';
                                            $module_content .= '</div></div>';
                                        }

                                        $module_content .= '<div class="armclear"></div>';
                                        $module_content .= $pg_fields;
                                        $module_content .= '<div class="armclear"></div>';
                                        $module_content .= '</div>';
                                        $module_content = apply_filters('arm_after_setup_gateway_section', $module_content, $setupID, $setup_data);
                                        $module_content .= '<div class="armclear" data-ng-init="armSetDefaultPaymentGateway(\'' . $selectedKey . '\');"></div>';
                                        $module_content .= '</div></div>';
                                        /* Payment Mode Module */

                                        $arm_automatic_sub_label = (isset($setup_data['setup_labels']['automatic_subscription']) && !empty($setup_data['setup_labels']['automatic_subscription'])) ? $setup_data['setup_labels']['automatic_subscription'] : __('Auto Debit Payment', 'ARMember');
                                        $arm_semi_automatic_sub_label = (isset($setup_data['setup_labels']['semi_automatic_subscription']) && !empty($setup_data['setup_labels']['semi_automatic_subscription'])) ? $setup_data['setup_labels']['semi_automatic_subscription'] : __('Manual Payment', 'ARMember');
                                        $module_content .= "<div class='arm_payment_mode_main_wrapper".$arm_two_step_class."'><div class='arm_payment_mode_wrapper' id='arm_payment_mode_wrapper' style='text-align:{$formPosition};'>";
                                        $setup_data['setup_labels']['payment_mode_selection'] = (isset($setup_data['setup_labels']['payment_mode_selection']) && !empty($setup_data['setup_labels']['payment_mode_selection'])) ? $setup_data['setup_labels']['payment_mode_selection'] : __('How you want to pay?', 'ARMember');
                                        $module_content .= "<div class='arm_setup_section_title_wrapper arm_payment_mode_selection_wrapper' >" . $setup_data['setup_labels']['payment_mode_selection'] . "</div>";
                                        $module_content .= "<div class='arm_radio_outer_wrapper'><div class='arm_radio_wrapper'><input type='radio' checked='checked' name='arm_selected_payment_mode' value='auto_debit_subscription' class='arm_selected_payment_mode' id='arm_selected_payment_mode_auto_{$setupRandomID}'/><span></span></div><label for='arm_selected_payment_mode_auto_{$setupRandomID}' style='cursor:pointer;'>&nbsp;<span class='arm_payment_mode_label'>" . $arm_automatic_sub_label . "</span></label></div>";
                                        $module_content .= "<div class='arm_radio_outer_wrapper' style='margin-left: 30px;'><div class='arm_radio_wrapper'><input type='radio'  name='arm_selected_payment_mode' value='manual_subscription' class='arm_selected_payment_mode' id='arm_selected_payment_mode_semi_auto_{$setupRandomID}'/><span></span></div><label for='arm_selected_payment_mode_semi_auto_{$setupRandomID}' style='cursor:pointer;'>&nbsp;<span class='arm_payment_mode_label'>" . $arm_semi_automatic_sub_label . "</span></label></div>";
                                        $module_content .= "";
                                        $module_content .= "</div></div>";
                                    }
                                }
                                break;
                            case 'order_detail':
                                if (!empty($modules['plans'])) {
                                    if ($arm_manage_coupons->isCouponFeature && !empty($modules['coupons']) && $modules['coupons'] == '1') {
                                        $labels = array(
                                            'title' => (!empty($button_labels['coupon_title'])) ? $button_labels['coupon_title'] : '',
                                            'button' => (!empty($button_labels['coupon_button'])) ? $button_labels['coupon_button'] : '',
                                        );
                                        $is_used_as_invitation_code = (isset($setup_modules['modules']['coupon_as_invitation']) && $setup_modules['modules']['coupon_as_invitation'] == 1) ? true : false;

                                        $module_content .= '<div class="arm_setup_couponbox_main_wrapper'.$arm_two_step_class.'"><div class="arm_setup_couponbox_wrapper">';
                                        if (isset($button_labels['coupon_title']) && !empty($button_labels['coupon_title'])) {
                                            $module_content .= '<div class="arm_setup_section_title_wrapper" style="text-align:' . $formPosition . ';">' . $button_labels['coupon_title'] . '</div>';
                                        }
                                        $module_content .= '<div class="arm_module_coupons_container arm_module_box">';
                                        $is_display_coupons = (!empty($selected_plan_data['arm_subscription_plan_type']) && $selected_plan_data['arm_subscription_plan_type'] == 'free') ? 'display:none;' : '';
                                        $module_content .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                                        $module_content .= '<div class="arm_form_inner_container arm_msg_pos_' . $errPosCCField . '" style="padding: 0 !important;">';
                                        $module_content .= '<div class="arm_coupon_fields arm_form_wrapper_container">';
                                        $module_content .= $arm_manage_coupons->arm_redeem_coupon_html('', $labels, $selected_plan_data, $btn_style_class, $is_used_as_invitation_code, $setupRandomID, $formPosition);

                                        $module_content .= '</div>';
                                        $module_content .= '</div>';
                                        $module_content .= '</div>';
                                        $module_content .= '<div class="armclear"></div>';
                                        $module_content .= '</div>';
                                        $module_content .= '</div></div>';
                                    }
                                    $module_content = apply_filters('arm_after_setup_order_detail', $module_content, $setupID, $setup_data);
                                    if (isset($setup_data['setup_labels']['summary_text']) && !empty($setup_data['setup_labels']['summary_text'])) {
                                        $setupSummaryText = stripslashes($setup_data['setup_labels']['summary_text']);
                                        $setupSummaryText = str_replace('[PLAN_NAME]', '<span class="arm_plan_name_text"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[PLAN_AMOUNT]', '<span class="arm_plan_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[DISCOUNT_AMOUNT]', '<span class="arm_discount_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[PAYABLE_AMOUNT]', '<span class="arm_payable_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[TAX_AMOUNT]', '<span class="arm_tax_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $setupSummaryText = str_replace('[TAX_PERCENTAGE]', '<span class="arm_tax_percentage_text">'.$tax_percentage.'</span>%', $setupSummaryText);
                                        $setupSummaryText = str_replace('[TRIAL_AMOUNT]', '<span class="arm_trial_amount_text"></span> <span class="arm_order_currency"></span>', $setupSummaryText);
                                        $module_content .= "<div class='arm_setup_summary_text_main_container".$arm_two_step_class."'><div class='arm_setup_summary_text_container arm_module_box' style='text-align:{$formPosition};'>";
                                        $module_content .= '<input type="hidden" name="arm_total_payable_amount" data-id="arm_total_payable_amount" ng-model="arm_total_payable_amount" value=""/>';
                                        $module_content .= '<input type="hidden" name="arm_zero_amount_discount" data-id="arm_zero_amount_discount" ng-model="arm_zero_amount_discount" value="' . $arm_plan_amount = $arm_payment_gateways->arm_amount_set_separator($global_currency) . '"/>';
                                        $module_content .= '<div class="arm_setup_summary_text">' . nl2br($setupSummaryText) . '</div>';
                                        $module_content .= '</div></div>';
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                        $module_html .= $module_content;
                    }

                    $content = apply_filters('arm_before_setup_form_content', $content, $setupID, $setup_data);
                    $content .= '<div class="arm_setup_form_container">';
                    $content .= '<style type="text/css" id="arm_setup_style_' . $args['id'] . '">';
                    if (!empty($setup_style)) {
                        $sfontFamily = isset($setup_style['font_family']) ? $setup_style['font_family'] : '';
                        $gFontUrl = $arm_member_forms->arm_get_google_fonts_url(array($sfontFamily));
                        if (!empty($gFontUrl)) {
                            $setupGoogleFonts .= '<link id="google-font-' . $setupID . '" rel="stylesheet" type="text/css" href="' . $gFontUrl . '" />';
                        }
                        $content .= $this->arm_generate_setup_style($setupID, $setup_style);
                    }
                    if (!empty($formStyle)) {
                        $content .= $formStyle;
                    }
                    if (!empty($custom_css)) {
                        $content .= $custom_css;
                    }
                    $content .= '</style>';
                    $content .= $setupGoogleFonts;
                    $content .= '<div class="arm_setup_messages arm_form_message_container"></div>';
                    $form_attr = ' data-ng-controller="ARMCtrl" data-ng-submit="armSetupFormSubmit(arm_form.$valid, \'arm_setup_form' . $setupRandomID . '\', $event);" onsubmit="return false;"';
                    $is_form_class_rtl = '';
                    if (is_rtl()) {
                        $is_form_class_rtl = 'is_form_class_rtl';
                    }
                    $captcha_code = arm_generate_captcha_code();
                    if (!isset($_SESSION['ARM_FILTER_INPUT'])) {
                        $_SESSION['ARM_FILTER_INPUT'] = array();
                    }
                    if (isset($_SESSION['ARM_FILTER_INPUT'][$setupRandomID])) {
                        unset($_SESSION['ARM_FILTER_INPUT'][$setupRandomID]);
                    }
                    $_SESSION['ARM_FILTER_INPUT'][$setupRandomID] = $captcha_code;
                    $_SESSION['ARM_VALIDATE_SCRIPT'] = true;
                    $form_attr .= ' data-submission-key="' . $captcha_code . '" ';
                    $content .= '<form method="post" name="arm_form" id="arm_setup_form' . $setupRandomID . '" class="arm_setup_form_' . $setupID . ' arm_membership_setup_form arm_form_' . $modules['forms'] . ' ' . $is_form_class_rtl . '" enctype="multipart/form-data" data-random-id="' . $setupRandomID . '" novalidate ' . $form_attr . '>';
                    if ($args['hide_title'] == false && $args['popup'] == false) {
                        $content .= '<h3 class="arm_setup_form_title">' . $setup_name . '</h3>';
                    }
                    $content .= '<input type="hidden" name="setup_id" value="' . $setupID . '" data-id="arm_setup_id"/>';
                    $content .= '<input type="hidden" name="setup_action" value="membership_setup"/>';
                    $content .= "<input type='text' name='arm_filter_input' data-random-key='{$setupRandomID}' value='' style='opacity:0 !important;display:none !important;visibility:hidden !important;' />";
                    $content .= '<div class="arm_setup_form_inner_container">';
                    $content .= '<input type="hidden" class="arm_global_currency" value="' . $global_currency . '"/>';

                    /* tax values */
                    if($enable_tax == 1 && !empty($tax_values)) {
                        $content .= "<input type='hidden' name='arm_tax_type' value='".$tax_values["tax_type"]."'/>";
                        if($tax_values["tax_type"] =='country_tax') {
                            $content .= "<input type='hidden' name='arm_country_tax_field' value='".$tax_values["country_tax_field"]."'/>";
                            $content .= "<input type='hidden' name='arm_country_tax_field_opts' value='".$tax_values["country_tax_field_opts_json"]."'/>";
                            $content .= "<input type='hidden' name='arm_country_tax_amount' value='".$tax_values["country_tax_amount_json"]."'/>";
                            $content .= "<input type='hidden' name='arm_country_tax_default_val' value='".$tax_values["tax_percentage"]."'/>";
                        }
                        else {
			    $content .= "<input type='hidden' name='arm_common_tax_amount' value='".$tax_values["tax_percentage"]."'/>";
                        }
                    }
                    /* tax values over */

                    $content .= $module_html;
                    
                    $content .= '<div class="arm_setup_submit_btn_main_wrapper'.$arm_two_step_class.'"><div class="arm_setup_submit_btn_wrapper ' . $form_style_class . '" data-ng-cloak="">';
                    $content .= '<div class="arm_form_field_container arm_form_field_container_submit">';
                    $content .= '<div class="arm_label_input_separator"></div>';
                    $content .= '<div class="arm_form_label_wrapper arm_form_field_label_wrapper arm_form_member_field_submit"></div>';
                    $content .= '<div class="arm_form_input_wrapper">';
                    $content .= '<div class="arm_form_input_container_submit arm_form_input_container" id="arm_setup_form_input_container' . $setupID . '">';
                    $ngClick = 'ng-click="armSubmitBtnClick($event)"';
                    if (current_user_can('administrator')) {
                        $ngClick = 'onclick="return false;"';
                    }
                    $content .= '<md-button type="submit" name="ARMSETUPSUBMIT" class="arm_setup_submit_btn arm_form_field_submit_button arm_form_field_container_button arm_form_input_box arm_material_input ' . $btn_style_class . '" ' . $ngClick . '><span class="arm_spinner">' . file_get_contents(MEMBERSHIP_IMAGES_DIR . "/loader.svg") . '</span>' . html_entity_decode(stripslashes($submit_btn)) . '</md-button>';
                    $content .= '</div>';
                    $content .= '</div>';
                    $content .= '</div>';
                    $content .= '</div>';
                    $content .= '</div></div>';
                    $content .= '</form></div>';

                    if ($args['popup'] !== false) {
                        $popup_content = '<div class="arm_setup_form_popup_container">';
                        $link_title = (!empty($args['link_title'])) ? $args['link_title'] : $setup_name;
                        $link_style = $link_hover_style = '';
                        $popup_content .= '<style type="text/css">';
                        if (!empty($args['link_css'])) {
                            $link_style = esc_html($args['link_css']);
                            $popup_content .= '.arm_setup_form_popup_link_' . $setupID . '{' . $link_style . '}';
                        }
                        if (!empty($args['link_hover_css'])) {
                            $link_hover_style = esc_html($args['link_hover_css']);
                            $popup_content .= '.arm_setup_form_popup_link_' . $setupID . ':hover{' . $link_hover_style . '}';
                        }
                        $popup_content .= '</style>';
                        $pformRandomID = $setupID . '_popup_' . arm_generate_random_code();
                        $popupLinkID = 'arm_setup_form_popup_link_' . $setupID;
                        $popupLinkClass = 'arm_setup_form_popup_link arm_setup_form_popup_link_' . $setupID;
                        if (!empty($args['link_class'])) {
                            $popupLinkClass.=" " . esc_html($args['link_class']);
                        }
                        $popupLinkAttr = 'data-form_id="' . $pformRandomID . '" data-toggle="armmodal"  data-modal_bg="' . $args['modal_bgcolor'] . '" data-overlay="' . $args['overlay'] . '"';
                        if (!empty($args['link_type']) && strtolower($args['link_type']) == 'button') {
                            $popup_content .= '<button type="button" id="' . $popupLinkID . '" class="' . $popupLinkClass . ' arm_setup_form_popup_button" ' . $popupLinkAttr . '>' . $link_title . '</button>';
                        } else {
                            $popup_content .= '<a href="javascript:void(0)" id="' . $popupLinkID . '" class="' . $popupLinkClass . ' arm_setup_form_popup_ahref" ' . $popupLinkAttr . '>' . $link_title . '</a>';
                        }
                        $popup_style = $popup_content_height = '';
                        $popupHeight = 'auto';
                        $popupWidth = '500';
                        if (!empty($args['popup_height'])) {
                            if ($args['popup_height'] == 'auto') {
                                $popup_style .= 'height: auto;';
                            } else {
                                $popup_style .= 'overflow: hidden;height: ' . $args['popup_height'] . 'px;';
                                $popupHeight = ($args['popup_height'] - 70) . 'px';
                                $popup_content_height = 'overflow-x: hidden;overflow-y: auto;height: ' . ($args['popup_height'] - 70) . 'px;';
                            }
                        }
                        if (!empty($args['popup_width'])) {
                            if ($args['popup_width'] == 'auto') {
                                $popup_style .= '';
                            } else {
                                $popupWidth = $args['popup_width'];
                                $popup_style .= 'width: ' . $args['popup_width'] . 'px;';
                            }
                        }
                        $popup_content .= '<div class="popup_wrapper arm_popup_wrapper arm_popup_member_setup_form arm_popup_member_setup_form_' . $setupID . ' arm_popup_member_setup_form_' . $pformRandomID . '" style="' . $popup_style . '" data-width="' . $popupWidth . '"><div class="popup_setup_inner_container popup_wrapper_inner">';
                        $popup_content .= '<div class="popup_header">';
                        $popup_content .= '<span class="popup_close_btn arm_popup_close_btn"></span>';
                        $popup_content .= '<div class="popup_header_text arm_setup_form_heading_container">';
                        if ($args['hide_title'] == false) {
                            $popup_content .= '<span class="arm_setup_form_field_label_wrapper_text">' . $setup_name . '</span>';
                        }
                        $popup_content .= '</div>';
                        $popup_content .= '</div>';
                        $popup_content .= '<div class="popup_content_text" style="' . $popup_content_height . '" data-height="' . $popupHeight . '">';
                        $popup_content .= $content;
                        $popup_content .= '</div><div class="armclear"></div>';
                        $popup_content .= '</div></div>';
                        $popup_content .= '</div>';
                        $content = $popup_content;
                        $content .= '<div class="armclear">&nbsp;</div>';
                    }
                    $content = apply_filters('arm_after_setup_form_content', $content, $setupID, $setup_data);
                }
            }
            $ARMember->arm_check_font_awesome_icons($content);
            $ARMember->enqueue_angular_script(true);

            $inbuild = '';
            $hiddenvalue = '';
            $hostname = $_SERVER["SERVER_NAME"];
            global $arm_members_activity, $arm_version;
            $arm_request_version = get_bloginfo('version');
            $setact = 0;
            global $armemberplugin_version_check;
            $setact = $arm_members_activity->$armemberplugin_version_check();

            if($setact != 1)
                $inbuild = " (U)";

            $hiddenvalue = '  
            <!--Plugin Name: ARMember    
                Plugin Version: ' . get_option('arm_version') . ' ' . $inbuild . '
                Developed By: Repute Infosystems
                Developer URL: http://www.reputeinfosystems.com/
            -->';

            return do_shortcode($content.$hiddenvalue);
        }

        function arm_get_sales_tax($general_settings, $post_data = '', $user_id = 0, $form_id = 0) {

            $return_arr = array(
                "tax_type" => 'common_tax',
                "country_tax_field" => '',
                "country_tax_field_opts_json" => '',
                "country_tax_amount_json" => '',
                "tax_percentage" => '',
            );

            $tax_type = isset($general_settings['tax_type']) ? $general_settings['tax_type'] : 'common_tax';
            $country_tax_field = isset($general_settings['country_tax_field']) ? $general_settings['country_tax_field'] : '';

            if($tax_type == 'country_tax') {

                $tax_percentage = !empty($general_settings['arm_country_tax_default_val']) ? $general_settings['arm_country_tax_default_val'] : 0;

                if(!empty($general_settings['arm_tax_country_name']) && $country_tax_field != '') {

                    $country_tax_field_opts = isset($general_settings['arm_tax_country_name']) ? $general_settings['arm_tax_country_name'] : '';

                    if(!empty($country_tax_field_opts)) {
                        $country_tax_amount = isset($general_settings['arm_country_tax_val']) ? $general_settings['arm_country_tax_val'] : '';
                        if(!empty($country_tax_amount)) {
                            $country_tax_amount = maybe_unserialize($country_tax_amount);
                            $country_tax_field_opts = maybe_unserialize($country_tax_field_opts);
                            $return_arr["tax_type"] = $tax_type;
                            $return_arr["country_tax_field"] = $country_tax_field;
                            $return_arr["country_tax_field_opts_json"] = json_encode($country_tax_field_opts);
                            $return_arr["country_tax_amount_json"] = json_encode($country_tax_amount);

                            if(is_user_logged_in() && !empty($user_id)) {
                                $user_country = get_user_meta($user_id, $country_tax_field, true);
                                if(!empty($user_country) && in_array($user_country, $country_tax_field_opts)) {
                                    $opt_index = array_search($user_country, $country_tax_field_opts);
                                    $tax_percentage = $country_tax_amount[$opt_index];
                                }
                            }
                            else if(!empty($post_data) && in_array($post_data[$country_tax_field], $country_tax_field_opts)) {
                                $opt_index = array_search($post_data[$country_tax_field], $country_tax_field_opts);
                                $tax_percentage = $country_tax_amount[$opt_index];
                            }
                            else if(!empty($form_id) && ctype_digit($form_id)) {
                                global $arm_member_forms;
                                $form_field_opt = $arm_member_forms->arm_get_field_option_by_meta($country_tax_field, $form_id);
                                if(!empty($form_field_opt) && !empty($form_field_opt["default_val"]) ) {
                                    $default_opt = $form_field_opt["default_val"];
                                    if(in_array($default_opt, $country_tax_field_opts)) {
                                        $opt_index = array_search($user_country, $country_tax_field_opts);
                                        $tax_percentage = $country_tax_amount[$opt_index];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else {
                $tax_percentage = isset($general_settings['tax_amount']) ? $general_settings['tax_amount'] : 0;
            }

            $return_arr["tax_percentage"] = $tax_percentage;

            return $return_arr;
        }

        function arm_generate_setup_style($setupid = 0, $setup_style = array()) {
            $defaultStyle = array(
                'content_width' => '800',
                'plan_skin' => '',
                'font_family' => 'Helvetica',
                'title_font_size' => 24,
                'title_font_bold' => 1,
                'title_font_italic' => '',
                'title_font_decoration' => '',
                'description_font_size' => 16,
                'description_font_bold' => 0,
                'description_font_italic' => '',
                'description_font_decoration' => '',
                'price_font_size' => 30,
                'price_font_bold' => 1,
                'price_font_italic' => '',
                'price_font_decoration' => '',
                'summary_font_size' => 15,
                'summary_font_bold' => 0,
                'summary_font_italic' => '',
                'summary_font_decoration' => '',
                'plan_title_font_color' => '#504f51',
                'plan_desc_font_color' => '#504f51',
                'price_font_color' => '#504f51',
                'summary_font_color' => '#504f51',
                'bg_active_color' => '#39a5ff',
                'selected_plan_title_font_color' => '#000000',
                'selected_plan_desc_font_color' => '#000000',
                'selected_price_font_color' => '#000000',
            );
            $setup_style = shortcode_atts($defaultStyle, $setup_style);

            $summary_font_style = (isset($setup_style['summary_font_bold']) && $setup_style['summary_font_bold'] == '1') ? "font-weight: bold;" : "font-weight: normal;";
            $summary_font_style .= (isset($setup_style['summary_font_italic']) && $setup_style['summary_font_italic'] == '1') ? "font-style: italic;" : "";
            $summary_font_style .= (isset($setup_style['summary_font_decoration']) && !empty($setup_style['summary_font_decoration'])) ? "text-decoration: " . $setup_style['summary_font_decoration'] . ";" : "";

            $title_font_style = (isset($setup_style['title_font_bold']) && $setup_style['title_font_bold'] == '1') ? "font-weight: bold;" : "font-weight: normal;";
            $title_font_style .= (isset($setup_style['title_font_italic']) && $setup_style['title_font_italic'] == '1') ? "font-style: italic;" : "";
            $title_font_style .= (isset($setup_style['title_font_decoration']) && !empty($setup_style['title_font_decoration'])) ? "text-decoration: " . $setup_style['title_font_decoration'] . ";" : "";

            $description_font_style = (isset($setup_style['description_font_bold']) && $setup_style['description_font_bold'] == '1') ? "font-weight: bold;" : "font-weight: normal;";
            $description_font_style .= (isset($setup_style['description_font_italic']) && $setup_style['description_font_italic'] == '1') ? "font-style: italic;" : "";
            $description_font_style .= (isset($setup_style['description_font_decoration']) && !empty($setup_style['description_font_decoration'])) ? "text-decoration: " . $setup_style['description_font_decoration'] . ";" : "";
            $price_font_style = (isset($setup_style['price_font_bold']) && $setup_style['price_font_bold'] == '1') ? "font-weight: bold;" : "font-weight: normal;";
            $price_font_style .= (isset($setup_style['price_font_italic']) && $setup_style['price_font_italic'] == '1') ? "font-style: italic;" : "";
            $price_font_style .= (isset($setup_style['price_font_decoration']) && !empty($setup_style['price_font_decoration'])) ? "text-decoration: " . $setup_style['price_font_decoration'] . ";" : "";
            $setup_content_width = ($setup_style['content_width'] == 0 && $setup_style['content_width'] != '') ? '800' : $setup_style['content_width'];
            $setup_content_width = ($setup_content_width == '') ? 'auto' : $setup_content_width.'px';
            $setup_css = '
                    .arm_setup_form_' . $setupid . '{
                        width: ' . $setup_content_width . ';
                        margin: 0 auto;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_form_title,
                    .arm_setup_form_' . $setupid . ' .arm_setup_section_title_wrapper{
                        font-family: ' . $setup_style['font_family'] . ', sans-serif, \'Trebuchet MS\';
                        font-size: 20px !important;
                        font-size: ' . ($setup_style['title_font_size'] + 2) . 'px !important;
                        color: ' . $setup_style['plan_title_font_color'] . ';
                        font-weight: normal;
                    }
                    
                    .arm_setup_form_' . $setupid . ' .arm_payment_mode_label{
                        font-family: ' . $setup_style['font_family'] . ', sans-serif, \'Trebuchet MS\';
                        font-size: ' . $setup_style['description_font_size'] . 'px !important;
                        color: ' . $setup_style['plan_desc_font_color'] . ';
                        font-weight : normal;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item .arm_module_plan_name,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item .arm_module_gateway_name,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item .arm_module_payment_cycle_name{
                        font-family: ' . $setup_style['font_family'] . ', sans-serif, \'Trebuchet MS\';
                        font-size: ' . $setup_style['title_font_size'] . 'px !important;
                        color: ' . $setup_style['plan_title_font_color'] . ' !important;
                        ' . $title_font_style . '
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_name,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_plan_name{
                        color: ' . $setup_style['selected_plan_title_font_color'] . ' !important;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item .arm_module_plan_price{
                        font-family: ' . $setup_style['font_family'] . ', sans-serif, \'Trebuchet MS\';
                        font-size: ' . $setup_style['price_font_size'] . 'px !important;
                        color: ' . $setup_style['price_font_color'] . ' !important;
                        ' . $price_font_style . '
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_price_type .arm_module_plan_price,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_plan_price{
                        color: ' . $setup_style['selected_price_font_color'] . ' !important;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item .arm_module_plan_description{
                        font-family: ' . $setup_style['font_family'] . ', sans-serif, \'Trebuchet MS\';
                        font-size: ' . $setup_style['description_font_size'] . 'px !important;
                        color: ' . $setup_style['plan_desc_font_color'] . ';
                        ' . $description_font_style . '
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_description,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_plan_description{
                        color: ' . $setup_style['selected_plan_desc_font_color'] . ';
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_summary_text_container .arm_setup_summary_text{
                        font-family: ' . $setup_style['font_family'] . ', sans-serif, \'Trebuchet MS\';
                        font-size: ' . $setup_style['summary_font_size'] . 'px !important;
                        color: ' . $setup_style['summary_font_color'] . ';
                        ' . $summary_font_style . '
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item:hover .arm_module_plan_option,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_plan_option,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item:hover .arm_module_gateway_option,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_gateway_option,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item:hover .arm_module_payment_cycle_option,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item.arm_active .arm_module_payment_cycle_option{
                        border: 1px solid ' . $setup_style['bg_active_color'] . ';
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item .arm_module_plan_name,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item .arm_module_gateway_name,
                    .arm_setup_form_' . $setupid . ' .arm_setup_column_item .arm_module_payment_cycle_name{
                        font-size: ' . $setup_style['title_font_size'] . 'px !important;
                        color: ' . $setup_style['plan_title_font_color'] . ';
                        ' . $title_font_style . '
                    }
                    .arm_setup_form_' . $setupid . ' .arm_plan_default_skin.arm_setup_column_item.arm_active .arm_module_plan_option{
                        background-color: ' . $setup_style['bg_active_color'] . ';
                        border: 1px solid ' . $setup_style['bg_active_color'] . ';
                    }
                    .arm_setup_form_' . $setupid . ' .arm_plan_default_skin.arm_setup_column_item.arm_active .arm_module_plan_option{
                        background-color: ' . $setup_style['bg_active_color'] . ';
                        border: 1px solid ' . $setup_style['bg_active_color'] . ';
                    }
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin1.arm_setup_column_item:hover .arm_module_plan_option .arm_module_plan_price_type,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin1.arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_price_type {
                        transition: all 0.7s ease 0s;
                        -webkit-transition: all 0.7s ease 0s;
                        -moz-transiton: all 0.7s ease 0s;
                        -o-transition: all 0.7s ease 0s;
                        background-color: ' . $setup_style['bg_active_color'] . ';
                        border: 1px solid ' . $setup_style['bg_active_color'] . ';
                    }
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin1.arm_setup_column_item:hover .arm_module_plan_option .arm_module_plan_price_type .arm_module_plan_price,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin1.arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_price_type .arm_module_plan_price{
                        color: ' . $setup_style['selected_price_font_color'] . ' !important;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin2.arm_setup_column_item:hover .arm_module_plan_option .arm_module_plan_name,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin2.arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_name{
                         transition: all 0.7s ease 0s;
                        -webkit-transition: all 0.7s ease 0s;
                        -moz-transiton: all 0.7s ease 0s;
                        -o-transition: all 0.7s ease 0s;
                        background-color: ' . $setup_style['bg_active_color'] . ';
                        border: 1px solid ' . $setup_style['bg_active_color'] . ';
                    }

                    .arm_setup_form_' . $setupid . ' .arm_plan_skin6.arm_setup_column_item:hover .arm_module_plan_option,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin6.arm_setup_column_item.arm_active .arm_module_plan_option{
                         transition: all 0.7s ease 0s;
                        -webkit-transition: all 0.7s ease 0s;
                        -moz-transiton: all 0.7s ease 0s;
                        -o-transition: all 0.7s ease 0s;
                        background-color: ' . $setup_style['bg_active_color'] . ';
                        border: 1px solid ' . $setup_style['bg_active_color'] . ';
                        color: '.$setup_style['selected_plan_title_font_color'].' !important;
                    }

                    .arm_setup_form_' . $setupid . ' .arm_plan_skin6.arm_setup_column_item:hover .arm_module_plan_option .arm_module_plan_name,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin6.arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_name,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin6.arm_setup_column_item:hover .arm_module_plan_option .arm_module_plan_price,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin6.arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_price,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin6.arm_setup_column_item:hover .arm_module_plan_option .arm_module_plan_description,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin6.arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_description{
                         transition: all 0.7s ease 0s;
                        -webkit-transition: all 0.7s ease 0s;
                        -moz-transiton: all 0.7s ease 0s;
                        -o-transition: all 0.7s ease 0s;
                       
                        color: '.$setup_style['selected_plan_title_font_color']. ' !important;
                    }


                    .arm_setup_form_' . $setupid . ' .arm_plan_skin2.arm_setup_column_item:hover .arm_module_plan_option .arm_module_plan_name,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin2.arm_setup_column_item.arm_active .arm_module_plan_option .arm_module_plan_name{
                        color: ' . $setup_style['selected_plan_title_font_color'] . ' !important;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_setup_check_circle{
                        border-color: ' . $setup_style['bg_active_color'] . ' !important;
                        color: ' . $setup_style['bg_active_color'] . ' !important;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin3 .arm_module_plan_option .arm_setup_check_circle i,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin3 .arm_module_plan_option:hover .arm_setup_check_circle i{
                        color:  ' . $setup_style['bg_active_color'] . ' !important;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin3 .arm_module_plan_option .arm_setup_check_circle,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin3 .arm_module_plan_option .arm_setup_check_circle,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin3 .arm_module_plan_option .arm_setup_check_circle,
                    .arm_setup_form_' . $setupid . ' .arm_plan_skin5 .arm_module_plan_option .arm_setup_check_circle{
                        border-color: ' . $setup_style['bg_active_color'] . ' !important;
                    }
                    .arm_setup_form_' . $setupid . ' .arm_module_gateways_container .arm_module_gateway_fields{
                        font-family: ' . $setup_style['font_family'] . ', sans-serif, \'Trebuchet MS\';
                    }
                ';
            return $setup_css;
        }

        function armSortModuleOrders(Array $array, Array $orderArray) {
            $ordered = array();
            if (!empty($array) && !empty($orderArray)) {
                foreach ($array as $key => $val) {
                    if (array_key_exists($val, $orderArray)) {
                        $ordered[$orderArray[$val]] = $val;
                        unset($array[$key]);
                    }
                }
            } else {
                $ordered = $array;
            }
            if (!empty($ordered)) {
                ksort($ordered);
            }
            return $ordered;
        }

        function arm_sort_module_by_order($items = array(), $item_order = array()) {
            $new_items = array();
            if (!empty($items)) {
                if (!empty($item_order)) {
                    asort($item_order);
                    foreach ($item_order as $key => $order) {
                        if (!empty($items[$key])) {
                            $new_items[$key] = $items[$key];
                            unset($items[$key]);
                        }
                    }
                    $new_items = $new_items + $items;
                } else {
                    $new_items = $items;
                }
            }
            return $new_items;
        }

        function arm_refresh_setup_items() {
            global $wp, $wpdb, $ARMember, $arm_global_settings, $arm_payment_gateways, $arm_manage_coupons, $arm_subscription_plans;
            $module_items = '';
            if (!empty($_POST['module'])) {
                $module_items = $this->arm_get_module_items_box($_POST['module']);
            }
            echo $module_items;
            exit;
        }

        function arm_get_module_items_box($module_type = 'plans', $options = array()) {
            global $wp, $wpdb, $ARMember, $arm_slugs, $arm_global_settings, $arm_payment_gateways, $arm_manage_coupons, $arm_subscription_plans;
            $module_box = '';
            $alertMessages = $ARMember->arm_alert_messages();
            $add_plan_link = admin_url('admin.php?page=' . $arm_slugs->manage_plans . '&action=new');
            $manage_gateway_link = admin_url('admin.php?page=' . $arm_slugs->general_settings . '&&action=payment_options');
            $selected_items = (!empty($options['selected'])) ? $options['selected'] : array();
            $items_order = (!empty($options['items_order'])) ? $options['items_order'] : array();
            $column_type = (!empty($options['column'])) ? $options['column'] : 1;
            $options['coupons'] = (!empty($options['coupons']) && $options['coupons'] == 1) ? $options['coupons'] : 0;
            $input_prefix = 'setup_data[setup_modules]';
            if ($module_type == 'plans') {
                $active_plans = $arm_subscription_plans->arm_get_all_active_subscription_plans();
                $filtered_items = $this->arm_sort_module_by_order($active_plans, $items_order);
                $module_box .= '<div class="arm_setup_items_box_plans">';
                if (!empty($filtered_items)) {
                    $module_box .= '<div class="arm_setup_module_column_layout_types arm_setup_plans_column_layout_types">';
                    $module_box .= '<div class="arm_column_layout_types_container">';
                    $column1_class = ($column_type == 1) ? 'arm_active_label' : '';
                    $module_box .= '<label class="' . $column1_class . '"><span class="single_column_img"></span><input type="radio" name="setup_data[setup_modules][plans_columns]" value="1" class="arm_column_layout_type_radio" ' . checked($column_type, '1', false) . ' data-module="plans"><span>' . __('Single Column', 'ARMember') . '</span></label>';
                    $column2_class = ($column_type == 2) ? 'arm_active_label' : '';
                    $module_box .= '<label class="' . $column2_class . '"><span class="two_column_img"></span><input type="radio" name="setup_data[setup_modules][plans_columns]" value="2" class="arm_column_layout_type_radio" ' . checked($column_type, '2', false) . ' data-module="plans"><span>' . __('Two Column', 'ARMember') . '</span></label>';
                    $column3_class = ($column_type == 3) ? 'arm_active_label' : '';
                    $module_box .= '<label class="' . $column3_class . '"><span class="three_column_img"></span><input type="radio" name="setup_data[setup_modules][plans_columns]" value="3" class="arm_column_layout_type_radio" ' . checked($column_type, '3', false) . ' data-module="plans"><span>' . __('Three Column', 'ARMember') . '</span></label>';
                    $module_box .= '<div class="armclear"></div></div>';
                    $module_box .= '</div>';
                    $module_box .= '<ul class="arm_setup_plans_ul arm_membership_setup_sub_ul arm_column_' . $column_type . '">';
                    $pi = 1;
                    foreach ($filtered_items as $plan) {
                        $planObj = new ARM_Plan(0);
                        $planObj->init((object) $plan);
                        $plan_id = $planObj->ID;
                        $plan_options = $planObj->options;
                        /* Check Recurring Details */
                        $bank_allow = ($planObj->is_recurring()) ? '0' : '1';
                        $auth_allow = $planObj->is_support_authorize_net();
                        $auth_allow = ($auth_allow) ? '1' : '0';
                        $twoco_allow = $planObj->is_support_2checkout();
                        $twoco_allow = ($twoco_allow) ? '1' : '0';
                        $planInputAttr = ' data-plan_name="' . $planObj->name . '" data-plan_type="' . $planObj->type . '" data-payment_type="' . $planObj->payment_type . '" data-auth_allow="' . $auth_allow . '" data-bank_allow="' . $bank_allow . '" data-twoco_allow="' . $twoco_allow . '"';
                        $plan_checked = (!empty($selected_items) && in_array($plan_id, $selected_items)) ? 'checked="checked"' : '';
                        $module_box .= '<li class="arm_membership_setup_plans_li arm_membership_setup_sub_li">';
                        $module_box .= '<div class="arm_membership_setup_sortable_icon"></div>';
                        $module_box .= '<label id="label_plan_chk_' . $plan_id . '">';
                        $module_box .= '<input type="checkbox" name="' . $input_prefix . '[modules][plans][]" value="' . $plan_id . '" id="plan_chk_' . $plan_id . '" class="arm_icheckbox plans_chk_inputs plans_chk_inputs_' . $planObj->type . '" ' . $planInputAttr . ' ' . $plan_checked . ' data-msg-required="' . __('Please select atleast one plan.', 'ARMember') . '"/>';
                        $module_box .= '<span>' . $planObj->name . '</span>';
                        $module_box .= '</label>';
                        $module_box .= '<input type="hidden" name="' . $input_prefix . '[modules][plans_order][' . $plan_id . ']" value="' . $pi . '" class="arm_module_options_order">';
                        $module_box .= '</li>';
                        $pi++;
                    }
                    $module_box .= '</ul>';
                } else {
                    $module_box .= '<span class="arm_setup_plan_error_msg error" style="display: none;">' . __('Please select atleast one plan.', 'ARMember') . '</span>';
                    $module_box .= '<a href="javascript:void(0)" class="arm_setup_module_refresh" data-module="plans" title="' . __('Reload Plan List', 'ARMember') . '"><i class="armfa armfa-refresh"></i></a>';
                    $module_box .= '<div class="arm_setup_items_empty_msg">' . __('There is no any plan configured yet.', 'ARMember');
                    $module_box .= ' <a href="' . $add_plan_link . '" target="_blank">' . __('Please click here to add plan.', 'ARMember') . '</a>';
                    $module_box .= ' ' . __('After adding plan, click on refresh button', 'ARMember');
                    $module_box .= ' (<a style="float: none;padding: 3px;" href="javascript:void(0)" class="arm_setup_module_refresh" data-module="plans"><i class="armfa armfa-refresh"></i></a>) ' . __('to get added plans.', 'ARMember');
                    $module_box .= '</div>';
                }
                $module_box .= '</div>';
            } elseif ($module_type == 'gateways') {
                $active_gateways = $arm_payment_gateways->arm_get_active_payment_gateways();
                $filtered_gatways = $this->arm_sort_module_by_order($active_gateways, $items_order);
                $module_box .= '<div class="arm_setup_items_box_gateways">';
                if (!empty($filtered_gatways)) {
                    $module_box .= '<div class="arm_setup_module_column_layout_types arm_setup_gatways_column_layout_types">';
                    $module_box .= '<div class="arm_column_layout_types_container">';
                    $column1_class = ($column_type == 1) ? 'arm_active_label' : '';
                    $module_box .= '<label class="' . $column1_class . '"><span class="single_column_img"></span><input type="radio" name="setup_data[setup_modules][gateways_columns]" value="1" class="arm_column_layout_type_radio" ' . checked($column_type, '1', false) . ' data-module="gateways"><span>' . __('Single Column', 'ARMember') . '</span></label>';
                    $column2_class = ($column_type == 2) ? 'arm_active_label' : '';
                    $module_box .= '<label class="' . $column2_class . '"><span class="two_column_img"></span><input type="radio" name="setup_data[setup_modules][gateways_columns]" value="2" class="arm_column_layout_type_radio" ' . checked($column_type, '2', false) . ' data-module="gateways"><span>' . __('Two Column', 'ARMember') . '</span></label>';
                    $column3_class = ($column_type == 3) ? 'arm_active_label' : '';
                    $module_box .= '<label class="' . $column3_class . '"><span class="three_column_img"></span><input type="radio" name="setup_data[setup_modules][gateways_columns]" value="3" class="arm_column_layout_type_radio" ' . checked($column_type, '3', false) . ' data-module="gateways"><span>' . __('Three Column', 'ARMember') . '</span></label>';
                    $module_box .= '<div class="armclear"></div></div>';
                    $module_box .= '</div>';
                    $module_box .= '<ul class="arm_setup_gateways_ul arm_membership_setup_sub_ul arm_column_' . $column_type . '">';
                    $gi = 1;
                    /* --------------------Strip Plan Box------------------------------------ */
                    $stripePlanIDWarning = $alertMessages['stripePlanIDWarning'];
                    $selected_plan = isset($options['selected_plan']) ? $options['selected_plan'] : array();
                    $stripe_plans = isset($options['stripe_plans']) ? $options['stripe_plans'] : array();
                    $stripe_plan_options = '';
                    $stripeNotPlans = $bankNotPlans = $authNotPlans = $twocoNotPlans = array();
                    $isStripeWarning = $isBTWarning = $isAuthorizeNetWarning = $is2CheckoutWarning = false;
                    if (!empty($selected_plan)) {
                        foreach ($selected_plan as $pID) {
                            $pddata = $arm_subscription_plans->arm_get_subscription_plan($pID, 'arm_subscription_plan_name, arm_subscription_plan_type, arm_subscription_plan_options');
                            $s_plan_name = $pddata['arm_subscription_plan_name'];
                            $plan_type = $pddata['arm_subscription_plan_type'];
                            $plan_options = maybe_unserialize($pddata['arm_subscription_plan_options']);
                            $payment_type = isset($plan_options['payment_type']) ? $plan_options['payment_type'] : '';
                            if ($plan_type == 'paid' && $payment_type == 'subscription') {
                                if (in_array('bank_transfer', $selected_items)) {
                                    $isBTWarning = true;
                                    $bankNotPlans[$pID] = $s_plan_name;
                                }
                                if (!empty($stripe_plans)) {
                                    $stripe_pID = (!empty($stripe_plans[$pID])) ? $stripe_plans[$pID] : '';
                                    $stripe_plan_options .= '<label class="arm_stripe_plans arm_stripe_plan_label_' . $pID . '"><span>' . stripslashes($pddata['arm_subscription_plan_name']) . '</span>';
                                    $stripe_plan_options .= '<input type="text" name="' . $input_prefix . '[modules][stripe_plans][' . $pID . ']" value="' . $stripe_pID . '" placeholder="' . __('Stripe plan ID', 'ARMember') . '">';
                                    //$stripe_plan_options .= '<span class="arm_stripe_planid_warning">' . $stripePlanIDWarning . '</span>';
                                    $stripe_plan_options .= '</label>';
                                }
                                switch ($plan_options['recurring']['type']) {
                                    case 'D':
                                        if (in_array('2checkout', $selected_items)) {
                                            $is2CheckoutWarning = true;
                                            $twocoNotPlans[$pID] = $s_plan_name;
                                        }
                                        if (in_array('authorize_net', $selected_items) && $plan_options['recurring']['days'] < 7) {
                                            $isAuthorizeNetWarning = true;
                                            $authNotPlans[$pID] = $s_plan_name;
                                        }
                                        break;
                                    case 'M':
                                        if (in_array('authorize_net', $selected_items) && $plan_options['recurring']['months'] > 12) {
                                            $isAuthorizeNetWarning = true;
                                            $authNotPlans[$pID] = $s_plan_name;
                                        }
                                        break;
                                    default:
                                        break;
                                }
                                $trialOptions = isset($plan_options['trial']) ? $plan_options['trial'] : array();
                                if (isset($trialOptions['is_trial_period']) && $trialOptions['is_trial_period'] == 1) {
                                    if (in_array('stripe', $selectedGateways)) {

                                        if ($trialOptions['amount'] > 0) {
                                            $isStripeWarning = true;
                                            $stripeNotPlans[$pID] = $s_plan_name;
                                        }
                                    }

                                    if (in_array('2checkout', $selected_items)) {
                                        $is2CheckoutWarning = true;
                                        $twocoNotPlans[$pID] = $s_plan_name;
                                    }
                                    if (in_array('authorize_net', $selected_items)) {
                                        $isAuthorizeNetWarning = true;
                                        $authNotPlans[$pID] = $s_plan_name;
                                    }
                                }
                            }
                        }
                    }
                    /* -------------------------------------------------------- */
                    foreach ($filtered_gatways as $key => $pg) {
                        $pgname = $pg['gateway_name'];
                        $gateway_checked = (!empty($selected_items) && in_array($key, $selected_items)) ? 'checked="checked"' : '';
                        $module_box .= '<li class="arm_membership_setup_gateways_li arm_membership_setup_sub_li">';
                        $module_box .= '<div class="arm_membership_setup_sortable_icon"></div>';
                        $module_box .= '<label>';
                        $module_box .= '<input type="checkbox" name="' . $input_prefix . '[modules][gateways][]" value="' . $key . '" id="gateway_chk_' . $key . '" class="arm_icheckbox gateways_chk_inputs" ' . $gateway_checked . ' data-pg_name="' . $pgname . '" data-msg-required="' . __('Please select atleast one payment gateway.', 'ARMember') . '"/>';
                        $module_box .= '<span>' . $pgname . '</span>';
                        $module_box .= '</label>';
                        $module_box .= '<input type="hidden" name="' . $input_prefix . '[modules][gateways_order][' . $key . ']" value="' . $gi . '" class="arm_module_options_order">';
                        if ($key == 'stripe') {
                            $stripe_plan_display = (!empty($stripe_plan_options)) ? 'display:block;' : '';
                            $module_box .= '<div class="arm_stripe_plan_container" style="' . $stripe_plan_display . '">';
                            $stripe_title = __("You must need to add 'Product' for recurring plans", 'ARMember') . "<br/>" . __("You can view / create product easily via the", 'ARMember') . " <a href='https://dashboard.stripe.com/subscriptions/products'>" . __('Products', 'ARMember') . "</a> " . __("page of the Stripe dashboard. After that you need to click on created 'Product' and then at 'Pricing Plan' section Add/Edit Plan(s) and after that you can get 'ID' of stripe plan", 'ARMember');
                            $module_box .= '<h4>' . __('Stripe Plans', 'ARMember') . '<i class="arm_helptip_icon armfa armfa-question-circle" title="' . $stripe_title . '"></i></h4>';
                            $module_box .= $stripe_plan_options;
                            $module_box .= '</div>';
                        }
                        $module_box .= '</li>';
                        $gi++;
                    }
                    $module_box .= '</ul>';
                    $module_box .= '<div class="armclear"></div>';
                    $module_box .= '<div class="arm_payment_gateway_warnings">';
                    $module_box .= '<span class="arm_invalid" id="arm_2checkout_warning" style="' . ($is2CheckoutWarning ? '' : 'display:none;') . '"><span class="arm_2checkout_not_support_plans">' . (implode(',', $twocoNotPlans)) . '</span> ' . __("plan's configuration is not supported by 2Checkout. So it will be hide as a payment option when user will select this plan(s).", 'ARMember') . '</span>';
                    $module_box .= '<span class="arm_invalid" id="arm_stripe_warning" style="' . ($isStripeWarning ? '' : 'display:none;') . '"><span class="arm_stripe_not_support_plans">' . (implode(',', $stripeNotPlans)) . '</span> ' . __("plan's configuration is not supported by Stripe. So it will be hide as a payment option when user will select this plan(s).", 'ARMember') . '</span>';

                    $module_box .= '<span class="arm_invalid" id="arm_authorize_net_warning" style="' . ($isAuthorizeNetWarning ? '' : 'display:none;') . '"><span class="arm_authorize_net_not_support_plans">' . (implode(',', $authNotPlans)) . '</span> ' . __("plan's configuration is not supported by Authorize.Net. So it will be hide as a payment option when user will select this plan(s).", 'ARMember') . '</span>';
                    $module_box .= '<span class="arm_invalid" id="arm_bank_transfer_warning" style="' . ($isBTWarning ? '' : 'display:none;') . '"><span class="arm_bank_transfer_not_support_plans">' . (implode(',', $bankNotPlans)) . '</span> ' . __("plan's configuration is not supported by Bank Transfer. So it will be hide as a payment option when user will select this plan(s).", 'ARMember') . '</span>';
                    $module_box .= '</div>';
                    $module_box .= '<div class="armclear"></div>';
                } else {
                    $module_box .= '<span class="arm_setup_gateway_error_msg error" style="display: none;">' . __('Payment gateway is required for paid plans.', 'ARMember') . '</span>';
                    $module_box .= '<a href="javascript:void(0)" class="arm_setup_module_refresh" data-module="gateways" title="' . __('Reload Payment Gateway List', 'ARMember') . '"><i class="armfa armfa-refresh"></i></a>';
                    $module_box .= '<div class="arm_setup_items_empty_msg">' . __('There is no any payment gateway configured yet.', 'ARMember');
                    $module_box .= ' <a href="' . $manage_gateway_link . '" target="_blank">' . __('Please click here to add payment method.', 'ARMember') . '</a>';
                    $module_box .= ' ' . __('After setup payment gateway, click on refresh button', 'ARMember');
                    $module_box .= ' (<a style="float: none;padding: 3px;" href="javascript:void(0)" class="arm_setup_module_refresh" data-module="gateways"><i class="armfa armfa-refresh"></i></a>) ' . __('to get added payment gateways.', 'ARMember');
                    $module_box .= '</div>';
                }
                $module_box .= '</div>';
            }
            return $module_box;
        }

        function arm_update_plan_form_gateway_selection() {
            global $wp, $wpdb, $ARMember, $arm_payment_gateways, $arm_subscription_plans;
            $returnArr = array(
                'plans' => '',
                'plan_layout_list' => '',
                'forms' => $this->arm_setup_form_list_options(),
                'gateways' => '',
            );
            $totalPlans = isset($_POST['total_plans']) ? $_POST['total_plans'] : 0;
            $totalGateways = isset($_POST['total_gateways']) ? $_POST['total_gateways'] : 0;
            $selectedPlans = (isset($_POST['selected_plans']) && !empty($_POST['selected_plans'])) ? explode(',', $_POST['selected_plans']) : array();
            $plansOrder = (isset($_POST['setup_data']['setup_modules']['modules']['plans_order'])) ? $_POST['setup_data']['setup_modules']['modules']['plans_order'] : array();
            $selectedGateways = (isset($_POST['selected_gateways']) && !empty($_POST['selected_gateways'])) ? explode(',', $_POST['selected_gateways']) : array();
            $user_selected_plan = (isset($_POST['default_selected_plan'])) ? $_POST['default_selected_plan'] : '';
            $activePlanCounts = $arm_subscription_plans->arm_get_total_active_plan_counts();
            if ($activePlanCounts == 0) {
                $returnArr['plans'] = "<span style='display:none;'></span>";
            } else if ($activePlanCounts != $totalPlans) {
                $allPlans = $arm_subscription_plans->arm_get_all_active_subscription_plans();
                $returnArr['plans'] = $this->arm_setup_plan_list_options($selectedPlans, $allPlans);
                $returnArr['plan_layout_list'] = $this->arm_setup_plan_layout_list_options($plansOrder, $selectedPlans, $user_selected_plan);
            }
            $activeGateways = $arm_payment_gateways->arm_get_active_payment_gateways();
            if (count($activeGateways) == 0) {
                $returnArr['gateways'] = "<span style='display:none;'></span>";
            } else if (count($activeGateways) != $totalGateways) {
                $activeGateways = $arm_payment_gateways->arm_get_active_payment_gateways();
                $returnArr['gateways'] = $this->arm_setup_gateway_list_options($selectedGateways, $activeGateways);
            }
            echo json_encode($returnArr);
            exit;
        }

        function arm_setup_plan_list_options($selectedPlans = array(), $allPlans = array()) {
            global $wp, $wpdb, $ARMember, $arm_subscription_plans;
            $planList = '';
            
            if (!empty($allPlans)) {
                foreach ($allPlans as $plan) {
                    $planObj = new ARM_Plan(0);
                    $planObj->init((object) $plan);
                    $plan_id = $planObj->ID;
                    $plan_options = $planObj->options;
                    $arm_show_plan_payment_cycles = (isset($plan_options['show_payment_cycle']) && $plan_options['show_payment_cycle'] == '1') ? 1 : 0;

                    $plan_checked = (in_array($plan_id, $selectedPlans) ? 'checked="checked"' : '');
                    $planInputAttr = $plan_checked . ' data-plan_name="' . $planObj->name . '" data-plan_type="' . $planObj->type . '" data-payment_type="' . $planObj->payment_type . '" data-show_payment_cycle="' . $arm_show_plan_payment_cycles . '" ';
                    $planList .= '<div id="label_plan_chk_' . $plan_id . '" class="arm_setup_plan_opt_wrapper">';
                    $planList .= '<input type="checkbox" name="setup_data[setup_modules][modules][plans][]" value="' . $plan_id . '" id="plan_chk_' . $plan_id . '" class="arm_icheckbox plans_chk_inputs plans_chk_inputs_' . $planObj->type . '" ' . $planInputAttr . ' data-msg-required="' . __('Please select atleast one plan.', 'ARMember') . '"/>';
                    $planList .= '<label for="plan_chk_' . $plan_id . '">' . $planObj->name . '</label>';
                    $planList .= '</div>';
                }
            }
            return $planList;
        }

        function arm_setup_plan_layout_list_options($planOrders = array(), $selectedPlans = array(), $user_selected_plan = '') {
            global $wp, $wpdb, $ARMember, $arm_subscription_plans;
            $planOrderList = '';
            $allPlans = $arm_subscription_plans->arm_get_all_subscription_plans();

            $orderPlans = $this->arm_sort_module_by_order($allPlans, $planOrders);
            $user_selected_plan = (isset($user_selected_plan)) ? $user_selected_plan : '';


            if (!empty($orderPlans)) {
                $pi = 1;
                foreach ($orderPlans as $plan) {
                    $plan_id = $plan['arm_subscription_plan_id'];
                    /* if no plan selected than set first plan default selected */
                    if ($pi == 1 && $user_selected_plan == '') {
                        $user_selected_plan = $plan_id;
                    }

                    $planClass = 'arm_membership_setup_plans_li_' . $plan_id;
                    $planClass .= (!in_array($plan_id, $selectedPlans) ? ' hidden_section ' : '');
                    $planOrderList .= '<li class="arm_membership_setup_sub_li arm_membership_setup_plans_li ' . $planClass . '">';
                    $planOrderList .= '<div class="arm_membership_setup_sortable_icon"></div>';
                    $planOrderList .= '<input type="radio" class="arm_iradio arm_default_user_selected_plan" name="setup_data[setup_modules][selected_plan]" value="' . $plan_id . '" ' . checked($user_selected_plan, $plan_id, false) . ' id="arm_setup_plan_' . $plan_id . '">';
                    $planOrderList .= '<label for="arm_setup_plan_' . $plan_id . '" class="arm_setup_plan_label">' . $plan['arm_subscription_plan_name'] . '</label>';
                    $planOrderList .= '<input type="hidden" name="setup_data[setup_modules][modules][plans_order][' . $plan_id . ']" value="' . $pi . '" class="arm_module_options_order arm_plan_order_inputs" data-plan_id="' . $plan_id . '">';
                    $planOrderList .= '</li>';
                    $pi++;
                }
            }
            return $planOrderList;
        }

        function arm_setup_form_list_options() {
            global $wp, $wpdb, $ARMember, $arm_member_forms;
            $registerForms = $arm_member_forms->arm_get_member_forms_by_type('registration', false);
            $formList = '<li data-label="' . __('Select Form', 'ARMember') . '" data-value="">' . __('Select Form', 'ARMember') . '</li>';
            if (!empty($registerForms)) {
                foreach ($registerForms as $form) {
                    $formList .= '<li data-label="' . strip_tags(stripslashes($form['arm_form_label'])) . '" data-value="' . $form['arm_form_id'] . '">' . strip_tags(stripslashes($form['arm_form_label'])) . '</li>';
                }
            }
            return $formList;
        }

        function arm_setup_gateway_list_options($selectedGateways = array(), $activeGateways = array(), $selectedPaymentModes = array(), $selectedPlans = array(), $plan_object_array = array()) {
            global $wp, $wpdb, $ARMember, $arm_payment_gateways, $arm_subscription_plans;
            $gatewayList = '';
            
            $arm_display_payment_mode_box = 'display: none;';

            if (!empty($selectedPlans) && count($selectedPlans) > 0) {
                foreach ($selectedPlans as $plan) {
                     $planObj = isset($plan_object_array[$plan]) ? $plan_object_array[$plan] : '';  
                    
                     if(is_object($planObj)){
                    $plan_type = $planObj->type;
                    $plan_options = $planObj->options;
                    $arm_show_plan_payment_cycles = (isset($plan_options['show_payment_cycle']) && $plan_options['show_payment_cycle'] == '1') ? 1 : 0;
                    if ($planObj->is_recurring() || ($plan_type == 'paid_finite' && $arm_show_plan_payment_cycles == 1)) {

                        $arm_display_payment_mode_box = 'display: block;';
                    }
                  }
                }
            }

            if (!empty($activeGateways)) {
                $doNotDisplayPaymentMode = array('bank_transfer');
                $doNotDisplayPaymentMode = apply_filters('arm_not_display_payment_mode_setup', $doNotDisplayPaymentMode);
                foreach ($activeGateways as $key => $pg) {
                    
                    $selectedPaymentModes[$key] = isset($selectedPaymentModes[$key]) ? $selectedPaymentModes[$key] : 'both';
                    $checked_auto = ($selectedPaymentModes[$key] == 'auto_debit_subscription') ? 'checked="checked"' : '';
                    $checked_manual = ($selectedPaymentModes[$key] == 'manual_subscription') ? 'checked="checked"' : '';
                    $checked_both = ($selectedPaymentModes[$key] == 'both') ? 'checked="checked"' : '';

                    $gatewayChecked = in_array($key, $selectedGateways) ? 'checked="checked"' : '';
                    if (in_array($key, $selectedGateways)) {
                        $display_payment_mode = 'display: block;';
                    } else {
                        $display_payment_mode = 'display: none;';
                    }
                    $gatewayList .= '<div class="arm_setup_gateway_opt_wrapper" id="arm_setup_gateway_opt_wrapper_id">';
                    $gatewayList .= '<input type="checkbox" name="setup_data[setup_modules][modules][gateways][]" value="' . $key . '" id="gateway_chk_' . $key . '" class="arm_icheckbox gateways_chk_inputs" data-pg_name="' . $pg['gateway_name'] . '" ' . $gatewayChecked . ' data-msg-required="' . __('Please select atleast one payment gateway.', 'ARMember') . '"/>';
                    $gatewayList .= '<label for="gateway_chk_' . $key . '">' . $pg['gateway_name'] . '</label>';

                    if (!in_array($key, $doNotDisplayPaymentMode)) {
                        $gateway_note = '';
                        $gateway_note = apply_filters('arm_setup_show_payment_gateway_notice', $gateway_note, $key);
                        $gatewayList .= '<div class="arm_gateway_payment_mode_box" style="' . $arm_display_payment_mode_box . '"><div class="' . $key . '_gateway_payment_mode_class" id="arm_gateway_payment_mode_box" style="' . $display_payment_mode . '">
                           <label>' . __('In case of subscription plan selected', 'ARMember') . '</label>
                               <br/>
                                        <input name="setup_data[setup_modules][modules][payment_mode][' . $key . ']" value="auto_debit_subscription" type="radio" class="arm_iradio arm_' . $key . '_gateway_payment_mode_input" ' . $checked_auto . ' id="arm_' . $key . '_auto_mode">
                                        <label for="arm_' . $key . '_auto_mode">' . __('Allow Auto debit method only', 'ARMember') . '</label><br>
                                        <input name="setup_data[setup_modules][modules][payment_mode][' . $key . ']" value="manual_subscription" type="radio" class="arm_iradio arm_' . $key . '_gateway_payment_mode_input" ' . $checked_manual . ' id= "arm_' . $key . '_manual_mode">
                                        <label for="arm_' . $key . '_manual_mode">' . __('Allow Semi Automatic(manual) method only', 'ARMember') . '</label><br>
                                        <input name="setup_data[setup_modules][modules][payment_mode][' . $key . ']" value="both" type="radio" class="arm_iradio arm_' . $key . '_gateway_payment_mode_input" ' . $checked_both . ' id="arm_' . $key . '_both_mode">
                                        <label for="arm_' . $key . '_both_mode">' . __('Both (allow user to select payment method)', 'ARMember') . '</label><br>' . $gateway_note . '
                                    </div></div>';
                    }
                    if (in_array($key, $doNotDisplayPaymentMode)) {
                        $gatewayList .= '<input name="setup_data[setup_modules][modules][payment_mode][' . $key . ']" value="manual_subscription" type="hidden" class="arm_iradio arm_' . $key . '_gateway_payment_mode_input" id= "arm_' . $key . '_manual_mode">';
                    }
                    $gatewayList .= '</div>';
                }
            }
            return $gatewayList;
        }

        function arm_total_setups() {
            global $wpdb,$ARMember;
            $setup_count = $wpdb->get_var("SELECT COUNT(`arm_setup_id`) FROM `" . $ARMember->tbl_arm_membership_setup . "`");
            return $setup_count;
        }

        function arm_get_membership_setup($setup_id = 0) {
            global $wp, $wpdb, $current_user, $ARMember, $arm_global_settings;
            if (is_numeric($setup_id) && $setup_id != 0) {
                /* Query Monitor Change */
                if( isset($GLOBALS['arm_setup_data']) && isset($GLOBALS['arm_setup_data'][$setup_id]) ){
                  $setup_data = $GLOBALS['arm_setup_data'][$setup_id];
                } else {
                  $setup_data = $wpdb->get_row("SELECT * FROM `" . $ARMember->tbl_arm_membership_setup . "` WHERE `arm_setup_id`='" . $setup_id . "'", ARRAY_A);
                  if( !isset($GLOBALS['arm_setup_data']) ){
                    $GLOBALS['arm_setup_data'] = array();
                  }
                  $GLOBALS['arm_setup_data'][$setup_id] = $setup_data;
                }
                if (!empty($setup_data)) {
                    $setup_data['arm_setup_name'] = (!empty($setup_data['arm_setup_name'])) ? stripslashes($setup_data['arm_setup_name']) : '';
                    $setup_data['arm_setup_modules'] = maybe_unserialize($setup_data['arm_setup_modules']);
                    $setup_data['arm_setup_labels'] = maybe_unserialize($setup_data['arm_setup_labels']);
                    $setup_data['setup_name'] = $setup_data['arm_setup_name'];
                    $setup_data['setup_modules'] = $setup_data['arm_setup_modules'];
                    $setup_data['setup_labels'] = $setup_data['arm_setup_labels'];
                }
                return $setup_data;
            } else {
                return FALSE;
            }
        }

        function arm_save_membership_setups_func($posted_data = array()) {
            global $wp, $wpdb, $current_user, $arm_slugs, $ARMember, $arm_global_settings, $arm_payment_gateways;
            $redirect_to = admin_url('admin.php?page=' . $arm_slugs->membership_setup);
            if (isset($posted_data) && !empty($posted_data) && in_array($posted_data['form_action'], array('add', 'update'))) {
                $setup_data = $posted_data['setup_data'];
                if (!empty($setup_data)) {
                    $setup_name = (!empty($setup_data['setup_name'])) ? $setup_data['setup_name'] : __('Untitled Setup', 'ARMember');
                    $setup_modules = (!empty($setup_data['setup_modules'])) ? $setup_data['setup_modules'] : array();
                    $setup_labels = (!empty($setup_data['setup_labels'])) ? $setup_data['setup_labels'] : array();
                    $payment_gateways = $arm_payment_gateways->arm_get_all_payment_gateways_for_setup();
                    foreach ($payment_gateways as $pgkey => $gateway) {
                        if ($setup_labels['payment_gateway_labels'][$pgkey] == '') {
                            $setup_labels['payment_gateway_labels'][$pgkey] = $gateway['gateway_name'];
                        }
                    }
                    if (!empty($setup_modules['modules']['module_order'])) {
                        asort($setup_modules['modules']['module_order']);
                    }

                    $db_data = array(
                        'arm_setup_name' => $setup_name,
                        'arm_setup_modules' => maybe_serialize($setup_modules),
                        'arm_setup_labels' => maybe_serialize($setup_labels),
                    );
                    if ($posted_data['form_action'] == 'add') {
                        $db_data['arm_status'] = 1;
                        $db_data['arm_created_date'] = date('Y-m-d H:i:s');
                        /* Insert Form Fields. */
                        $wpdb->insert($ARMember->tbl_arm_membership_setup, $db_data);
                        $setup_id = $wpdb->insert_id;
                        /* Action After Adding Setup Details */
                        do_action('arm_saved_membership_setup', $setup_id, $db_data);
                        $ARMember->arm_set_message('success', __('Membership setup wizard has been added successfully.', 'ARMember'));
                        $redirect_to = $arm_global_settings->add_query_arg("action", "edit_setup", $redirect_to);
                        $redirect_to = $arm_global_settings->add_query_arg("id", $setup_id, $redirect_to);
                        wp_redirect($redirect_to);
                        exit;
                    } elseif ($posted_data['form_action'] == 'update' && !empty($posted_data['id']) && $posted_data['id'] != 0) {
                        $setup_id = $posted_data['id'];
                        $field_update = $wpdb->update($ARMember->tbl_arm_membership_setup, $db_data, array('arm_setup_id' => $setup_id));
                        /* Action After Updating Setup Details */
                        do_action('arm_saved_membership_setup', $setup_id, $db_data);
                        $ARMember->arm_set_message('success', __('Membership setup wizard has been updated successfully.', 'ARMember'));
                        $redirect_to = $arm_global_settings->add_query_arg("action", "edit_setup", $redirect_to);
                        $redirect_to = $arm_global_settings->add_query_arg("id", $setup_id, $redirect_to);
                        wp_redirect($redirect_to);
                        exit;
                    }
                }
            }
            return;
        }

        function arm_delete_single_setup() {
            global $wp, $wpdb, $current_user, $ARMember, $arm_members_class, $arm_member_forms, $arm_global_settings;
            $action = $_POST['act'];
            $id = $_POST['id'];
            if ($action == 'delete') {
                if (empty($id)) {
                    $errors[] = __('Invalid action.', 'ARMember');
                } else {
                    if (!current_user_can('arm_manage_setups')) {
                        $errors[] = __('Sorry, You do not have permission to perform this action', 'ARMember');
                    } else {
                        $res_var = $wpdb->delete($ARMember->tbl_arm_membership_setup, array('arm_setup_id' => $id));
                        if ($res_var) {
                            $message = __('Setup has been deleted successfully.', 'ARMember');
                        }
                    }
                }
            }
            $return_array = $arm_global_settings->handle_return_messages(@$errors, @$message);
            echo json_encode($return_array);
            exit;
        }

        function arm_setup_shortcode_preview_func() {
            global $wpdb, $ARMember;
            if (isset($_POST['action']) && $_POST['action'] == 'arm_setup_shortcode_preview' & isset($_POST['setup_data'])) {
                $user = wp_get_current_user();

                $setup_id = $_POST['id'];
                $setupData = $_POST['setup_data'];
                ?>
                <div class="popup_wrapper arm_preview_setup_shortcode_popup_wrapper" style="width:70%;">
                    <div class="popup_wrapper_inner" style="overflow: hidden;">
                        <div class="popup_header">
                            <span class="popup_close_btn arm_popup_close_btn arm_preview_setup_shortcode_close_btn"></span>
                            <span class="add_rule_content"><?php _e('Preview', 'ARMember'); ?></span>
                        </div>
                        <div class="popup_content_text">
                <?php echo $this->arm_generate_setup_shortcode_preview($setupData, $setup_id); ?>
                        </div>
                        <div class="armclear"></div>
                    </div>
                </div>
                <?php
            }
            exit;
        }

        function arm_generate_setup_shortcode_preview($setupData = array(), $setupID = 0) {
            $setupForm = '';
            if (!empty($args['setup_data'])) {
                $setupForm .= '';
                $setupForm .= '';
                $setupForm .= '';
            }
            return $setupForm;
        }

        function arm_check_include_js_css($setup_data, $atts) {
            global $ARMember;
            $ARMember->set_front_css(true);
            $ARMember->set_front_js(true);
        }

        function arm_setup_skin_default_color_array() {
            $font_colors = array(
                'skin1' => array(
                    'arm_setup_plan_title_font_color' => '#616161',
                    'arm_setup_plan_desc_font_color' => '#616161',
                    'arm_setup_price_font_color' => '#616161',
                    'arm_setup_summary_font_color' => '#616161',
                    'arm_setup_selected_plan_title_font_color' => '#23b7e5',
                    'arm_setup_selected_plan_desc_font_color' => '#616161',
                    'arm_setup_selected_price_font_color' => '#ffffff',
                    'arm_setup_bg_active_color' => '#23b7e5'
                ),
                'skin2' => array(
                    'arm_setup_plan_title_font_color' => '#616161',
                    'arm_setup_plan_desc_font_color' => '#616161',
                    'arm_setup_price_font_color' => '#616161',
                    'arm_setup_summary_font_color' => '#616161',
                    'arm_setup_selected_plan_title_font_color' => '#ffffff',
                    'arm_setup_selected_plan_desc_font_color' => '#616161',
                    'arm_setup_selected_price_font_color' => '#23b7e5',
                    'arm_setup_bg_active_color' => '#23b7e5'
                ),
                'skin3' => array(
                    'arm_setup_plan_title_font_color' => '#616161',
                    'arm_setup_plan_desc_font_color' => '#616161',
                    'arm_setup_price_font_color' => '#616161',
                    'arm_setup_summary_font_color' => '#616161',
                    'arm_setup_selected_plan_title_font_color' => '#616161',
                    'arm_setup_selected_plan_desc_font_color' => '#616161',
                    'arm_setup_selected_price_font_color' => '#616161',
                    'arm_setup_bg_active_color' => '#23b7e5'
                ),
                'skin4' => array(
                    'arm_setup_plan_title_font_color' => '#616161',
                    'arm_setup_plan_desc_font_color' => '#616161',
                    'arm_setup_price_font_color' => '#616161',
                    'arm_setup_summary_font_color' => '#616161',
                    'arm_setup_selected_plan_title_font_color' => '#ffffff',
                    'arm_setup_selected_plan_desc_font_color' => '#ffffff',
                    'arm_setup_selected_price_font_color' => '#ffffff',
                    'arm_setup_bg_active_color' => '#23b7e5'
                ),
                'skin5' => array(
                    'arm_setup_plan_title_font_color' => '#616161',
                    'arm_setup_plan_desc_font_color' => '#616161',
                    'arm_setup_price_font_color' => '#616161',
                    'arm_setup_summary_font_color' => '#616161',
                    'arm_setup_selected_plan_title_font_color' => '#23b7e5',
                    'arm_setup_selected_plan_desc_font_color' => '#616161',
                    'arm_setup_selected_price_font_color' => '#ffffff',
                    'arm_setup_bg_active_color' => '#23b7e5'
                ),
                'skin6' => array(
                    'arm_setup_plan_title_font_color' => '#616161',
                    'arm_setup_plan_desc_font_color' => '#6b6e78',
                    'arm_setup_price_font_color' => '#616161',
                    'arm_setup_summary_font_color' => '#616161',
                    'arm_setup_selected_plan_title_font_color' => '#ffffff',
                    'arm_setup_selected_plan_desc_font_color' => '#ffffff',
                    'arm_setup_selected_price_font_color' => '#ffffff',
                    'arm_setup_bg_active_color' => '#23b7e5'
                ),
            );

            return apply_filters('arm_membership_setup_skin_colors', $font_colors);
        }

        function arm_update_card_action_func()
        {
            if(is_user_logged_in()) {
                global $wpdb, $ARMember, $arm_member_forms, $arm_transaction, $arm_payment_gateways;
                $plan_id = isset($_POST['plan_id']) ? $_POST['plan_id'] : '';
                $setup_id = isset($_POST['setup_id']) ? $_POST['setup_id'] : '';
                $arm_user_id = get_current_user_id();
                $setup_data = $this->arm_get_membership_setup($setup_id);

                $form_in_setup = !empty($setup_data['setup_modules']['modules']['forms']) ? $setup_data['setup_modules']['modules']['forms'] : '';

                $user_form_id = !empty($form_in_setup) ? $form_in_setup : get_user_meta($arm_user_id, 'arm_form_id', true);
            
                $form = new ARM_Form('id', $user_form_id);

                if (!$form->exists() || $form->type != 'registration') {
                    $default_form_id = $arm_member_forms->arm_get_default_form_id('registration');
                    $form = new ARM_Form('id', $default_form_id);
                }

                if ($form->exists() && !empty($form->fields)) 
                {
                    $form_id = $form->ID;
                    $form_settings = $form->settings;
                    $ref_template = $form->form_detail['arm_ref_template'];
                    $form_style = $form_settings['style'];
                    
                    /* Form Classes */
                    $form_style['button_position'] = (!empty($form_style['button_position'])) ? $form_style['button_position'] : 'left';
                    $form_css = $arm_member_forms->arm_ajax_generate_form_styles($form_id, $form_settings, array(), $ref_template);
                    
                    $form_style_class = 'arm_shortcode_form arm_form_' . $form_id;
                    $form_style_class .= ' arm_form_layout_' . $form_style['form_layout'];
                    $form_style_class .= ($form_style['label_hide'] == '1') ? ' armf_label_placeholder' : '';
                    $form_style_class .= ' armf_alignment_' . $form_style['label_align'];
                    $form_style_class .= ' armf_layout_' . $form_style['label_position'];
                    $form_style_class .= ' armf_button_position_' . $form_style['button_position'];
                    $form_style_class .= ($form_style['rtl'] == '1') ? ' arm_form_rtl' : ' arm_form_ltr';
                    if (is_rtl()) {
                        $form_style_class .= ' arm_rtl_site';
                    }
                    $form_style_class .= ' ' . $atts['class'];
                    //$btn_style_class = ' arm_btn_style_flat ';
                
                    $active_gateways = $arm_payment_gateways->arm_get_active_payment_gateways();
                    
                    $planData = get_user_meta($arm_user_id, 'arm_user_plan_' . $plan_id, true);
                    
                    $arm_user_payment_gateway = $planData['arm_user_gateway'];
                    
                    $pg_options = $active_gateways[$arm_user_payment_gateway];

                    $setup_modules = $setup_data['setup_modules'];
                    $modules = $setup_modules['modules'];
                    $modules['forms'] = (!empty($modules['forms']) && $modules['forms'] != 0) ? $modules['forms'] : 0;
                    
                    $column_type = (!empty($setup_modules['gateways_columns'])) ? $setup_modules['gateways_columns'] : '1';
                    //$button_labels = $setup_data['setup_labels']['button_labels'];
                    //echo $button_labels['submit'];
                    $submit_btn = !empty($_POST['btn_text']) ? $_POST['btn_text'] : __('Update Card', 'ARMember');
                    
                    
                    if (!empty($form_settings)) {
                    $errPosCCField = !empty($form_settings['style']['validation_position']) ? $form_settings['style']['validation_position'] : 'bottom';
                    $fieldPosition = !empty($form_settings['style']['field_position']) ? $form_settings['style']['field_position'] : 'left';
                    $form_title_position = (!empty($form_style['form_title_position'])) ? $form_style['form_title_position'] : 'left';
                    $buttonStyle = (isset($form_settings['style']['button_style']) && !empty($form_settings['style']['button_style'])) ? $form_settings['style']['button_style'] : 'flat';
                    $btn_style_class = ' arm_btn_style_' . $buttonStyle;
                    }

                    $setupRandomID = $setup_id . '_' . arm_generate_random_code();

                    $form_attr = ' data-ng-controller="ARMCtrl" data-ng-cloak="" data-ng-id="' . $form_id . '" data-ng-submit="armUpdateCardFormSubmit(arm_form.$valid, \'arm_update_card_form' . $setupRandomID . '\', $event);" onsubmit="return false;"';

                    
                    $is_form_class_rtl = '';
                    if (is_rtl()) {
                        $is_form_class_rtl = 'is_form_class_rtl';
                    }
                    $captcha_code = arm_generate_captcha_code();
                    if (!isset($_SESSION['ARM_FILTER_INPUT'])) {
                        $_SESSION['ARM_FILTER_INPUT'] = array();
                    }
                    if (isset($_SESSION['ARM_FILTER_INPUT'][$setupRandomID])) {
                        unset($_SESSION['ARM_FILTER_INPUT'][$setupRandomID]);
                    }
                    $_SESSION['ARM_FILTER_INPUT'][$setupRandomID] = $captcha_code;
                    $_SESSION['ARM_VALIDATE_SCRIPT'] = true;
                    $form_attr .= ' data-submission-key="' . $captcha_code . '" ';
                    

                    $arm_update_card_form = '';

                    $arm_update_card_form .= $form_css['arm_link'];
                    $arm_update_card_form .= '<style type="text/css" id="arm_update_card_form_style_' . $form_id . '">' . $form_css['arm_css'] . '</style>';
                    $arm_update_card_form .= '<div class="arm_member_form_container arm_update_card_form_container arm_form_' . $form_id . '" >';

                    $arm_update_card_form .= '<div class="arm_setup_messages arm_form_message_container"></div>';
                    $arm_update_card_form .= '<div class="armclear"></div>';
                    $arm_update_card_form .= '<form method="post" name="arm_form" id="arm_update_card_form' . $setupRandomID . '" class="arm_setup_form_' . $setup_id . ' arm_update_card_form arm_form_' . $modules['forms'] . ' ' . $is_form_class_rtl . '" enctype="multipart/form-data" data-random-id="' . $setupRandomID . '"  novalidate ' . $form_attr . '>';
                    //if($arm_user_payment_gateway=='stripe' || $arm_user_payment_gateway=='authorize_net' || $arm_user_payment_gateway=='paypal_pro')

                    $arm_allow_gateway = apply_filters("arm_allow_gateways_update_card_detail", false, $arm_user_payment_gateway);

                    if($arm_user_payment_gateway=='stripe' || $arm_user_payment_gateway=='authorize_net' || $arm_allow_gateway)
                    {
                        /*if ($pg_options['stripe_payment_mode'] == 'live') 
                        {
                            $apikey = $pg_options['stripe_pub_key'];
                        } else {
                                $apikey = $pg_options['stripe_test_pub_key'];
                        }*/
                        //$arm_update_card_form .= '<script data-cfasync="false">Stripe.setPublishableKey("' . $apikey . '");</script>';
                        $arm_update_card_form .= '<div class="arm_module_gateway_fields arm_module_gateway_fields_'.$arm_user_payment_gateway.' arm_member_form_container">';
                        $arm_update_card_form .= '<div class="' . $form_style_class . '" data-ng-cloak="">';
                        $arm_update_card_form .= '<div class="arm_update_card_form_heading_container armalign' . $form_title_position . '">';
                        $arm_update_card_form .= '<span class="arm_form_field_label_wrapper_text">'.__('Update Card Details', 'ARMember').'</span>';
                        $arm_update_card_form .= '</div>';
                        //$arm_update_card_form .= '<h3 class="arm_setup_form_title">Update Card Details</h3>';
                        $arm_update_card_form .= $arm_payment_gateways->arm_get_credit_card_box($arm_user_payment_gateway, $column_type, $fieldPosition, $errPosCCField);
                        
                        $arm_update_card_form .= '<div class="armclear"></div>';
                        $arm_update_card_form .= '<div class="arm_form_field_container arm_form_field_container_submit">';
                        $arm_update_card_form .= '<div class="arm_label_input_separator"></div>';
                        $arm_update_card_form .= '<div class="arm_form_label_wrapper arm_form_field_label_wrapper arm_form_member_field_submit"></div>';
                        $arm_update_card_form .= '<div class="arm_form_input_wrapper">';
                        $arm_update_card_form .= '<div class="arm_form_input_container_submit arm_form_input_container" id="arm_update_card_form_input_container' . $setup_id . '">';

                        $ngClick = 'ng-click="armSubmitBtnClick($event)"';
                        if (current_user_can('administrator')) {
                            $ngClick = 'onclick="return false;"';
                        }

                        $arm_update_card_form .= '<md-button type="submit" name="ARMUPDATECARDSUBMIT" class="arm_update_card_submit_btn arm_form_field_submit_button arm_form_field_container_button arm_form_input_box arm_material_input ' . $btn_style_class . '" ' . $ngClick . '><span class="arm_spinner">' . file_get_contents(MEMBERSHIP_IMAGES_DIR . "/loader.svg") . '</span>' . html_entity_decode(stripslashes($submit_btn)) . '</md-button>';

                        $arm_update_card_form .= '<md-button type="button" name="ARMUPDATECARDCANCEL" class="arm_cancel_update_card_btn arm_form_field_submit_button arm_form_field_container_button arm_form_input_box arm_material_input ' . $btn_style_class . '">' . __('Cancel', 'ARMember') . '</md-button>';

                        //$arm_update_card_form .= '<button type="button" class="arm_cancel_update_card_btn arm_form_field_submit_button arm_form_field_container_button arm_form_input_box arm_material_input '.$btn_style_class.'">'.__('Cancel', 'ARMember').'</button>';

                        $arm_update_card_form .= '</div>';
                        $arm_update_card_form .= '</div>';
                        $arm_update_card_form .= '</div>';
                        
                        $arm_update_card_form .= '<div class="armclear" data-ng-init="armSetDefaultPaymentGateway(\'' . $arm_user_payment_gateway . '\');"></div>';

                        $arm_update_card_form .= '</div>';
                        $arm_update_card_form .= '</div>';
                        $arm_update_card_form .= '<input type="hidden" name="arm_user_plan_id" id="arm_user_plan_id" value="' . $plan_id . '">';
                        $arm_update_card_form .= '<input type="hidden" name="arm_user_setup_id" id="arm_user_setup_id" value="' . $setup_id . '">';
                        $arm_update_card_form .= '<input type="hidden" name="arm_user_payment_gatway" id="arm_user_payment_gatway" value="' . $arm_user_payment_gateway . '">';
                    }
                    $arm_update_card_form .= '</form>';
                    $arm_update_card_form .= '</div>';
                }
                echo $arm_update_card_form;
                $ARMember->enqueue_angular_script(true);
                $ARMember->set_front_css();
            }
            die;
        }
        function arm_membership_update_card_form_ajax_action($setup_id = 0, $post_data = array())
        {
            global $wp, $wpdb, $arm_slugs, $arm_errors, $ARMember, $arm_payment_gateways, $arm_authorize_net, $arm_global_settings;

            if(is_user_logged_in()) 
            {
                $err_msg = $arm_global_settings->common_message['arm_general_msg'];
                $err_msg = (!empty($err_msg)) ? $err_msg : __('Sorry, Something went wrong. Please try again.', 'ARMember');
                $response = array('status' => 'error', 'type' => 'message', 'message' => $err_msg);
                $success_msg = __("Your card details have been updated!", 'ARMember');
                $arm_user_id = get_current_user_id();
                $post_data = (!empty($_POST)) ? $_POST : $post_data;
                $setup_id = (!empty($post_data['arm_user_setup_id']) && $post_data['arm_user_setup_id'] != 0) ? $post_data['arm_user_setup_id'] : $setup_id;
                $plan_id = (!empty($post_data['arm_user_plan_id']) && $post_data['arm_user_plan_id'] != 0) ? $post_data['arm_user_plan_id'] : 0;

                $active_gateways = $arm_payment_gateways->arm_get_active_payment_gateways();
                $planData = get_user_meta($arm_user_id, 'arm_user_plan_' . $plan_id, true);
                $arm_user_payment_gateway = $planData['arm_user_gateway'];
                $arm_user_payment_mode = $planData['arm_payment_mode'];
                $pg_options = $active_gateways[$arm_user_payment_gateway];

                $card_holder_name = (!empty($post_data[$arm_user_payment_gateway]['card_holder_name'])) ? $post_data[$arm_user_payment_gateway]['card_holder_name'] : '';

                $card_number = (!empty($post_data[$arm_user_payment_gateway]['card_number'])) ? $post_data[$arm_user_payment_gateway]['card_number'] : '';

                $exp_month = (!empty($post_data[$arm_user_payment_gateway]['exp_month'])) ? $post_data[$arm_user_payment_gateway]['exp_month'] : '' ;

                $exp_year = (!empty($post_data[$arm_user_payment_gateway]['exp_year'])) ? $post_data[$arm_user_payment_gateway]['exp_year'] : '' ;

                $cvc = (!empty($post_data[$arm_user_payment_gateway]['cvc'])) ? $post_data[$arm_user_payment_gateway]['cvc'] : '' ;
                if($arm_user_payment_mode=='auto_debit_subscription')
                {
                    if($arm_user_payment_gateway=='stripe')
                    {
                        if ($pg_options['stripe_payment_mode'] == 'live') 
                        {
                            $stripe_secret_key = $pg_options['stripe_secret_key'];
                            $stripe_pub_key = $pg_options['stripe_pub_key'];
                        } else {
                            $stripe_secret_key = $pg_options['stripe_test_secret_key'];
                            $stripe_pub_key = $pg_options['stripe_test_pub_key'];
                        }
                        
                        $arm_user_plan_stripe_details = $planData['arm_stripe'];
                        if(!empty($arm_user_plan_stripe_details['customer_id']))
                        {
                           $arm_user_stripe_customer_id =  $arm_user_plan_stripe_details['customer_id'];
                        }
                        if (file_exists(MEMBERSHIP_DIR . "/lib/Stripe.php")) {
                            require_once (MEMBERSHIP_DIR . "/lib/Stripe.php");
                        }
                            \Stripe\Stripe::setApiKey($stripe_secret_key);

                            $card_data = array( "number" => $card_number,
                                                "exp_month" => $exp_month,
                                                "exp_year" => $exp_year,
                                                "cvc" => $cvc,
                                                'name' => $card_holder_name,
                                            );
                            
                            try {
                                $token = Stripe\Token::create(array("card" => $card_data));
                                $request_token = $token->id;

                                $customer_id = $arm_user_stripe_customer_id;
                                $customer = Stripe\Stripe_Customer::retrieve($customer_id);
                                $customer->source = $request_token; // obtained with Checkout
                                $customer->save();

                                $response = array('status' => 'success', 'type' => 'message', 'message' => $success_msg);
                            }
                            catch (Exception $e) 
                            {
                                $StripeAcion = $e;
                                $error_msg = $StripeAcion->getJsonBody();
                                $arm_help_link = '<a href="https://stripe.com/docs/error-codes" target="_blank">'.__('Click Here', 'ARMember').'</a>';
                                $actual_error = isset($error_msg['error']['message']) ? $error_msg['error']['message'] : '';
                                $actual_error = !empty($actual_error) ? $actual_error.' '.$arm_help_link : '';
                                $response = array('status' => 'error', 'type' => 'message', 'message' => $actual_error);
                            }
                    }
                    else if($arm_user_payment_gateway=='authorize_net')
                    {
                        try {
                            $arm_authorize_net->arm_LoadAuthorizeNetLibrary($pg_options);
                            $arm_auth_subscription = new AuthorizeNet_Subscription;

                            $arm_auth_subscription->creditCardCardNumber = trim($card_number);
                            $arm_auth_subscription->creditCardExpirationDate = $exp_year . "-" . $exp_month;
                            $arm_auth_subscription->creditCardCardCode = $cvc;

                            $arm_user_plan_auth_details = $planData['arm_authorize_net'];
                            $AuthSubscriptionID =  !empty($arm_user_plan_auth_details['subscription_id']) ? $arm_user_plan_auth_details['subscription_id'] : '';
                            if(!empty($AuthSubscriptionID))
                            {
                                $request = new AuthorizeNetARB;
                                $atuh_response = $request->updateSubscription($AuthSubscriptionID, $arm_auth_subscription);
                                if ($atuh_response->isOk()) {
                                    $response = array('status' => 'success', 'type' => 'message', 'message' => $success_msg);
                                }
                            }
                        } 
                        catch (Exception $e) 
                        {
                            $arm_err_msg = $arm_global_settings->common_message['arm_unauthorized_credit_card'];
                            $gateway_error_msg = $e->getJsonBody();
                            $arm_help_link = '<a href="https://developer.authorize.net/api/reference/features/errorandresponsecodes.html" target="_blank">'.__('Click Here', 'ARMember').'</a>';

                            $actual_error = isset($gateway_error_msg['error']['message']) ? $gateway_error_msg['error']['message'] : $arm_err_msg;
                            $actual_error = !empty($actual_error) ? $actual_error.' '.$arm_help_link : '';
                            
                            $response = array('status' => 'error', 'type' => 'message', 'message' => $actual_error);
                        }
                    }
		    else {
	                    $response = apply_filters("arm_submit_gateways_updated_card_detail", $err_msg, $success_msg, $arm_user_payment_gateway, $pg_options, $card_holder_name, $card_number, $exp_month, $exp_year, $planData, $response);
		    }
                }
                echo json_encode($response);
                exit;
            }
        }
    }
}

global $arm_membership_setup;
$arm_membership_setup = new ARM_membership_setup();
