Location: PHPKode > projects > MembersGear > membersgear/ipn.php
<?php
         
          
         $pPostArr=$_POST;
                $myFile = "implodedat.txt";
                if(is_writable($myFile))
                {   
                     $fh = fopen($myFile, 'a') or die("can't open file");
             
                     foreach ($pPostArr as $field=>$value) { 
                               
                              if(is_array($value))
                                {
                                   $strData='';     
                                   foreach($value as $k=>$avalue)
                                     {
                                        $strData.=$avalue."|";
                                     }
                                   $post_string = $field.'='.stripslashes($strData);     
                                }   
                                else
                                {
                                    $post_string = $field.'='.stripslashes($value);
                                }
                              fwrite($fh, $post_string);
                               
                              
                              fwrite($fh, "\n"); 
                              
                        }
                        
                         fwrite($fh, $url_file);    
                         fwrite($fh, "---------------------------------------\n");     
                         fclose($fh); 
                }    
                            
                  /*  
                    
                    $iProductId=101;
                    $iUserId=329;
                    $postedArry=ARRAY();
                    $postedArry['pg_amount']=50;
                    $postedArry['e_txn_id']='1111111545';
                    $postedArry['e_processor_name']='PAYPAL';
                    $postedArry['pg_txn_stat']='1';
                    $postedArry['payment_type']='CREDITCARD';
                    $postedArry['pg_order_id']='115';
                    $postedArry['payment_date']=1242777800;  
                    $postedArry['is_upsell']='true';
                    $postedArry['upsell_level']='2';
                    $postedArry['membersite_signup_productid']=$iProductId;
                    $postedArry['membersite_signup_userid']=$iUserId;
                    $_POST=$postedArry;    
                     */
                  
                   /*
                    $postedArry=ARRAY(); 
                    $postedArry['pg_secret']='';
                    $postedArry['pg_campid']='';
                    $postedArry['pg_session']='qgpsjp55ep3m1r5511zuyp45';
                    $postedArry['pg_aff_username1']='';
                    $postedArry['pg_aff_username2']='';
                    $postedArry['pg_productid']='266';
                    $postedArry['pg_productname']='nk_test1';
                    $postedArry['pg_amount']='10.0000';
                    $postedArry['pg_shipping_cost']='0';
                    $postedArry['pg_fee']='0.5000';
                    $postedArry['pg_aff_commission1']='0';
                    $postedArry['pg_aff_commission2']='0';
                    $postedArry['pg_couponbonus']='0';
                    $postedArry['pg_couponcode']='';
                    $postedArry['pg_txn_stat']='1';
                    $postedArry['pg_txn_type']='Product Sell';
                    $postedArry['pg_order_id']='3771';
                    $postedArry['e_txn_id']='0X550338UM754644Y';
                    $postedArry['e_processor_name']='Paypal';
                    $postedArry['pg_vendor_email']='hide@address.com';
                    $postedArry['payment_date']='1/18/2011 10:34:40 AM';
                    $postedArry['payer_email']='hide@address.com';
                    $postedArry['payment_type']='Email';
                    $postedArry['tax']='0';
                    $postedArry['first_name']='Jayesh Df';
                    $postedArry['last_name']='';
                    $postedArry['pi_address_street']='asdfasfasf';
                    $postedArry['pi_address_street']='';
                    $postedArry['pi_address_city']='Surat';
                    $postedArry['pi_address_state']='Arkansas';
                    $postedArry['pi_address_zip']='555555';
                    $postedArry['pi_address_country']='Select';
                    $postedArry['sh_address_street']='asdfasfasf';
                    $postedArry['sh_address_city']='Surat';
                    $postedArry['sh_address_state']='Arkansas';
                    $postedArry['sh_address_zip']='555555';
                    $postedArry['sh_address_country']='Select';
                    $postedArry['pg_main_product_id']='235';
                    $postedArry['pg_upsell_level']='1';
                    $postedArry['membersite_signup_productid']='100';
                    $postedArry['membersite_signup_userid']='85';
                    $_POST=$postedArry;  */
                    
                        
                   require_once "config/config.php"; 
                   require_once INCLUDE_DIR."/users_signup_class.php";
                   require_once INCLUDE_DIR."/users_class.php"; 
                   require_once INCLUDE_DIR."/product_class.php"; 
                   require_once INCLUDE_DIR."/upsell_product_class.php";
                   require_once INCLUDE_DIR."/PaygearWebserviceClient.php";   
                  
                                                                             
                   $objPayGear=new PaygearWebserviceClient();
                   $users=new users_class();  
  
                   $upsell_obj=new upsell_product_class(); 
                   $usersignuupObj=new users_signup_class(); 
                   $objProclass=new product_class();   
               
                   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(); 
                            }
                            
                         }
                       
                     }                                            
                    if(isset($_POST) && sizeof($_POST)>0 )
                    {
                        $iPaygear_ProductId=urldecode($_POST['pg_productid']);
                        $iProductId=$upsell_obj->getMembersgearProductIdFromPaygearProductId($iPaygear_ProductId);
                        $iUserId=urldecode($_POST['membersite_signup_userid']); 
                        
                         $ifProductSetForUpsell1=$upsell_obj->GetSpecificUpsellProduct_yes($iProductId,1);
                         $ifProductSetForUpsell2=$upsell_obj->GetSpecificUpsellProduct_yes($iProductId,2);
                         $ifProductSetForUpsell3=$upsell_obj->GetSpecificUpsellProduct_yes($iProductId,3);
             
                        
                        if($ifProductSetForUpsell1==true or $ifProductSetForUpsell2==true or $ifProductSetForUpsell3==true)
                         {
                             $res=$objProclass->deleteDuplicateTransaction($iUserId,$iProductId);  
                             $prod=$objProclass->checkForSameActiveSubscription($iUserId,$iProductId);
                             
                             if($prod==null or $prod=="")
                             {
                                 $insertToProductUser=$usersignuupObj->insertToProductUser($iProductId,$iUserId);

                             }
                         }
                     
                        $url=PHYSICAL_DIR."/";
                        $url_file= PHYSICAL_DIR."/postedArry.txt";
                        
                                                        
                         if(is_writable($url_file) && file_exists($url_file))
                                  $usersignuupObj->writePostArrayTofile($_POST,$url_file); 
                          $usersignuupObj->updateToProductUser($_POST,$iProductId,$iUserId); 
                          
                              $linkedInPro=$objProclass->getAllLinkedProductsForSpecificProduct($iProductId);
                        $objUserInfo=$users->getSpecificUserInfoById($iUserId);
                        
                       
                        if($linkedInPro!="" and $linkedInPro!=null)
                        {
                           
                             $linkedPro=explode(",",$linkedInPro);
                           
                              $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");  
                                        
                               foreach($linkedPro as $linkedProId)
                               {
                                   
                                   $res=$objProclass->deleteDuplicateTransaction($iUserId,$linkedProId);  
                                   $IsActivePro=$objProclass->checkForSameActiveSubscription($iUserId,$linkedProId);
                                   if($IsActivePro!=$linkedProId)
                                    {
                                     //add new subscription of this pro
                                                          
                                          $results=$objProclass->GetSpecificProductPaymentOptions($linkedProId);
                                          
                                          if($results!=false)
                                          { 
                                         
                                                 $PaymentOptionId=trim($results[0]['paygear_productpaymentoptionid']);
                                                 
                                                 $get_product_info=$objProclass->GetSpecificProduct(trim($linkedProId));
                                                 $paygearProdId=$get_product_info[0]['paygear_productid'] ;
                                                 $insertToProductUser=$usersignuupObj->insertToProductUser($linkedProId,$iUserId);
                                                 $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,$linkedProId,$iUserId);
                                                     
                                                  }   
                                          
                                           }
                                   
                                    }
                              
                                }
                        
                        }
                       
                         
                          
                         
                        
                    }
                  else
                    Redirect("user_login.php");      
                    
    
?>
Return current item: MembersGear