Location: PHPKode > projects > MembersGear > membersgear/member/user_subscribe_product.php
<?php require_once "../config/config.php";
     
 //**********************************************Begin Page code**********************************************     
    require_once INCLUDE_DIR."/users_class.php";
    require_once INCLUDE_DIR."/users_signup_class.php";
    require_once INCLUDE_DIR."/product_class.php";  
    require_once INCLUDE_DIR."/upsell_product_class.php";    
    require_once INCLUDE_DIR."/location_class.php";   
    require_once INCLUDE_DIR."/PaygearWebserviceClient.php"; 
    $objPayGear=new PaygearWebserviceClient();   
    
     if(function_exists('wordpress_check_Plugin_structure') and function_exists('wordpress_getWordpress_status')  )
     {
      
        $wordpressStatus=wordpress_getWordpress_status();
        if($wordpressStatus){

            $dirWordpress=wordpress_physical_path_dir()."wp-config.php";
            if(file_exists($dirWordpress)){
                require_once($dirWordpress);  
                assign_sessions(); 
            }
            
         }
       
     }  
      
    $users=new users_class();
    $lsSelectedProduct=$_POST['products'];
    $upsell_obj=new upsell_product_class();  
    $userid = $_SESSION[SESSION_PREFIX.'UserID'];
    $objProclass=new product_class();
    $res=$objProclass->deleteDuplicateTransaction($userid,$lsSelectedProduct);  
    $prod=$objProclass->checkForSameActiveSubscription($userid,$lsSelectedProduct);
     
     if($prod==null or $prod=="")
     {
         
         $get_product_info =$objProclass->GetSpecificProduct(trim($_POST['products']));
         $paygearProdId=$get_product_info[0]['paygear_productid'] ;
         $isFreeProduct=$get_product_info[0]['price'];
         $formatedPrice=number_format($isFreeProduct, 2, '.', ''); 
         
         $usersignuupObj=new users_signup_class();
         $insertToProductUser=$usersignuupObj->insertToProductUser($lsSelectedProduct,$userid);
         
         $usersignuupClass=new users_signup_class();
         $lsSalePageId=$usersignuupClass->getPayGearSalePageUrl($_POST['products']);
         $lbonetimeofferprodparent=$objProclass->IsParentofontimeofferproduct(trim($_POST['products']));
         //if($lbonetimeofferprodparent==true && IS_ENABLE_ONE_TIME_OFFER =='true') 
         
         
         
             if(IS_ENABLE_ONE_TIME_OFFER =='true')
             {     
                $tommorrow =  time() + (1*24*60*60);
                setcookie(COOKIE_PREFIX.'onetimeofferuserid',encrypt($userid),$tommorrow,"/"); 
              }
             
            $tommorrow =  time() + (1*24*60*60);
             setcookie(COOKIE_PREFIX.'user__id',encrypt($userid),$tommorrow,"/"); 
           
            if($insertToProductUser!=null)
             {
               setcookie(COOKIE_PREFIX.'Product_user_id',encrypt($insertToProductUser),$tommorrow,"/"); 
               setcookie(COOKIE_PREFIX.'lst_product',encrypt( $_POST['products']),$tommorrow,"/"); 
              
             }   
          
            $objcountry=new location_class();
            
            $objUserInfo=$users->getSpecificUserInfoById($userid);
           
            if($objUserInfo[0]['country']!="" and $objUserInfo[0]['country']!=null)
               $country=$objcountry->getCountryStateNameById($objUserInfo[0]['country']);
            else
              $country="";
             
            if($objUserInfo[0]['state']!="" and $objUserInfo[0]['state']!=null)
               $state=$objcountry->getCountryStateNameById($objUserInfo[0]['state']);
            else
              $state="";
              
            if($objUserInfo[0]['billing_country']!="" and $objUserInfo[0]['billing_country']!=null)
               $billing_country=$objcountry->getCountryStateNameById($objUserInfo[0]['billing_country']);
            else
              $billing_country="";
        
            if($objUserInfo[0]['billing_state']!="" and $objUserInfo[0]['billing_state']!=null)
               $billing_state=$objcountry->getCountryStateNameById($objUserInfo[0]['billing_state']);
            else
              $billing_state=""; 
              
            if($formatedPrice=="0.00")
             {
                
                 $iUserId=$objUserInfo[0]['id'];
                 $postedArry=ARRAY();
                 $postedArry['pg_amount']='0';
                 $postedArry['e_txn_id']='0';
                 $postedArry['e_processor_name']='N/A';
                 $postedArry['pg_txn_stat']='1';
                 $postedArry['payment_type']='N/A';
                 $postedArry['pg_order_id']='0';
                 $postedArry['payment_date']=date("m/d/Y");  
                 
                 $results=$objProclass->GetSpecificProductPaymentOptions(trim($_POST['products']));
                
                 if($results!=false)
                  { 
                 
                         $ProductId=trim($_POST['products']);
                         $PaymentOptionId=trim($results[0]['paygear_productpaymentoptionid']);
                         $FirstName=trim($objUserInfo[0]['firstname']);
                         $LastName=trim($objUserInfo[0]['lastname']);
                         $Email=trim($objUserInfo[0]['email']);
                         $Address=isset($objUserInfo[0]['address1'])?trim($objUserInfo[0]['address1']):''; 
                         $City=isset($objUserInfo[0]['city'])?trim($objUserInfo[0]['city']):''; 
                         $State=$state;
                         $ZiporPostalCode=isset($objUserInfo[0]['zipcode'])?trim($objUserInfo[0]['zipcode']):''; 
                         $Country=$country;
                         $Phone=isset($objUserInfo[0]['phone_main'])?trim($objUserInfo[0]['phone_main']):''; 
                         $spFirstName=trim($objUserInfo[0]['firstname']);
                         $spLastName=trim($objUserInfo[0]['lastname']);
                         $spEmail=trim($objUserInfo[0]['email']);
                         $spAddress=isset($objUserInfo[0]['billing_address'])?trim($objUserInfo[0]['billing_address']):''; 
                         $spCity=isset($objUserInfo[0]['billing_city'])?trim($objUserInfo[0]['billing_city']):''; 
                         $spState=$billing_state;
                         $spZip=isset($_POST['zipcodeSHP'])?trim($_POST['zipcodeSHP']):''; 
                         $spCountry=$billing_country;
                         $spPhone=isset($objUserInfo[0]['billing_phone'])?trim($objUserInfo[0]['billing_phone']):''; 
                         $IPAddress=$_SERVER['REMOTE_ADDR'];
                            
                         $addUserToPaygear=$objPayGear->freePorductEntry($paygearProdId,$PaymentOptionId,$FirstName,
                                                                         $LastName,$Email,$Address,$City,$State,
                                                                         $ZiporPostalCode,$Country,$Phone,$spFirstName,
                                                                         $spLastName,$spEmail,$spAddress,$spCity,$spState,
                                                                         $spZip,$spCountry,$spPhone,$IPAddress);  
                         
                         if(strtoupper($addUserToPaygear['FreeSaleTransactionEntryResult'])==strtoupper("TRUE"))
                          {   
                             $usersignuupObj=new users_signup_class();
                             $usersignuupObj->updateToProductUser($postedArry,trim($_POST['products']),$iUserId);
                             
                             $ifProductSetForUpsell1=false;
                             $ifProductSetForUpsell1=$upsell_obj->GetSpecificUpsellProduct($ProductId,1);
                             if($ifProductSetForUpsell1!=false)
                               {
                                   $upsellurlLevel1=$ifProductSetForUpsell1[0]['upsellpageurl'];  
                                   Redirect($upsellurlLevel1,true);
                               }
                             else
                               {
                                   $thankyoupageUrl=urldecode($results[0]['thankyoupageurl']);
                                   Redirect($thankyoupageUrl,true);
                                 
                               }     
                          }
                         else
                         {
                         
                             Redirect(WEB_URL."/member/user_default_page.php"); 
                         
                         }    
                  }
                 else
                  Redirect(WEB_URL."/member/user_default_page.php");   
                 
                 
             }
            else
            { 
                $browsUrl=PAYGEAR_WEB_URL."/sell.aspx?productpaymentoption=".urlencode(stripslashes(str_replace('.','[[dot]]',$lsSalePageId)))."&userid=".urldecode(stripslashes(str_replace('.','[[dot]]',$userid)))."&productid=".urlencode(stripslashes(str_replace('.','[[dot]]',$_POST['products'])))."&firstname=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['firstname'])))."&lastname=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['lastname'])))."&email=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['email'])));   
                $browsUrl.= "&address=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['address1'])))."&city=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['city'])))."&country=".urlencode(stripslashes(str_replace('.','[[dot]]',$country)))."&state=".urlencode(stripslashes( str_replace('.','[[dot]]',$state)))."&zipcode=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['zipcode'])))."&phone=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['phone_main'])));
                $browsUrl.="&shaddress=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['billing_address'])))."&shcity=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['billing_city'])))."&shcountry=".urlencode(stripslashes(str_replace('.','[[dot]]',$billing_country)))."&shstate=".urlencode(stripslashes(str_replace('.','[[dot]]',$billing_state)))."&shzipcode=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['billing_zip'])))."&shphone=".urlencode(stripslashes(str_replace('.','[[dot]]',$objUserInfo[0]['billing_phone'])));

                //$browsUrl=PAYGEAR_WEB_URL."/sell.aspx?productpaymentoption=".urlencode($lsSalePageId)."&userid=".urldecode($userid)."&productid=".$_POST['products'];
                //$browsUrl="http://localhost:1002/sscPayGear/user/sell.aspx?productpaymentoption=".urlencode($lsSalePageId)."&userid=".urldecode($userid)."&productid=".$_POST['products'];
                  // $browsUrl="http://localhost:1002/sscPayGear/user/sell/productpaymentoption/".urlencode($lsSalePageId)."/userid/".urldecode($userid)."/productid/".$_POST['products'];
             
             
                 // $url=WEB_URL."/ipn.php" ;
                Redirect($browsUrl); 
            }      
     
     }
    else
       redirect("user_default_page.php");                
?>
Return current item: MembersGear