function wpestate_ajax_paypal_pack_recuring_generation()
 {
     $allowed_html = array();
     $packName = wp_kses($_POST['packName'], $allowed_html);
     $pack_id = $_POST['packId'];
     if (!is_numeric($pack_id)) {
         exit;
     }
     $is_pack = get_posts('post_type=membership_package&p=' . $pack_id);
     if (!empty($is_pack)) {
         require get_template_directory() . '/libs/resources/paypalfunctions.php';
         global $current_user;
         get_currentuserinfo();
         $pack_price = get_post_meta($pack_id, 'pack_price', true);
         $billing_period = get_post_meta($pack_id, 'biling_period', true);
         $billing_freq = intval(get_post_meta($pack_id, 'billing_freq', true));
         $pack_name = get_the_title($pack_id);
         $submission_curency_status = esc_html(get_option('wp_estate_submission_curency', ''));
         $paypal_status = esc_html(get_option('wp_estate_paypal_api', ''));
         $paymentType = "Sale";
         $dash_profile_link = wpestate_get_dashboard_profile_link();
         $obj = new paypal_recurring();
         $obj->environment = esc_html(get_option('wp_estate_paypal_api', ''));
         $obj->paymentType = urlencode('Sale');
         $obj->productdesc = urlencode($pack_name . esc_html__(' package on ', 'wpestate') . get_bloginfo('name'));
         $time = time();
         $date = date('Y-m-d H:i:s', $time);
         $obj->startDate = urlencode($date);
         $obj->billingPeriod = urlencode($billing_period);
         $obj->billingFreq = urlencode($billing_freq);
         $obj->paymentAmount = urlencode($pack_price);
         $obj->currencyID = urlencode($submission_curency_status);
         $paypal_api_username = get_option('wp_estate_paypal_api_username', '');
         $paypal_api_password = get_option('wp_estate_paypal_api_password', '');
         $paypal_api_signature = get_option('wp_estate_paypal_api_signature', '');
         $obj->API_UserName = urlencode($paypal_api_username);
         $obj->API_Password = urlencode($paypal_api_password);
         $obj->API_Signature = urlencode($paypal_api_signature);
         $obj->API_Endpoint = "https://api-3t.paypal.com/nvp";
         $obj->returnURL = urlencode($dash_profile_link);
         $obj->cancelURL = urlencode($dash_profile_link);
         $executor['paypal_execute'] = '';
         $executor['paypal_token'] = '';
         $executor['pack_id'] = $pack_id;
         $executor['recursive'] = 1;
         $executor['date'] = $date;
         $save_data[$current_user->ID] = $executor;
         update_option('paypal_pack_transfer', $save_data);
         $obj->setExpressCheckout();
     }
 }
         if ($json_resp['state'] == 'approved') {
             if (wpestate_check_downgrade_situation($current_user->ID, $pack_id)) {
                 wpestate_downgrade_to_pack($current_user->ID, $pack_id);
                 wpestate_upgrade_user_membership($current_user->ID, $pack_id, 1, '');
             } else {
                 wpestate_upgrade_user_membership($current_user->ID, $pack_id, 1, '');
             }
             wp_redirect($dash_profile_link);
         }
     }
     //end if Get
 } else {
     require get_template_directory() . '/libs/resources/paypalfunctions.php';
     $billing_period = get_post_meta($pack_id, 'biling_period', true);
     $billing_freq = intval(get_post_meta($pack_id, 'billing_freq', true));
     $obj = new paypal_recurring();
     $obj->environment = esc_html(get_option('wp_estate_paypal_api', ''));
     $obj->paymentType = urlencode('Sale');
     // or 'Sale' or 'Order'
     $paypal_api_username = esc_html(get_option('wp_estate_paypal_api_username', ''));
     $paypal_api_password = esc_html(get_option('wp_estate_paypal_api_password', ''));
     $paypal_api_signature = esc_html(get_option('wp_estate_paypal_api_signature', ''));
     $obj->API_UserName = urlencode($paypal_api_username);
     $obj->API_Password = urlencode($paypal_api_password);
     $obj->API_Signature = urlencode($paypal_api_signature);
     $obj->API_Endpoint = "https://api-3t.paypal.com/nvp";
     $obj->paymentType = urlencode('Sale');
     $obj->returnURL = urlencode($dash_profile_link);
     $obj->cancelURL = urlencode($dash_profile_link);
     $obj->paymentAmount = get_post_meta($pack_id, 'pack_price', true);
     $obj->currencyID = get_option('wp_estate_submission_curency', '');