Jump to content

aMember Intergration


rmatakajr

Recommended Posts

Im in contact with Matt right now for this question, and I am makeing a thread

so i can keep the community updated

 

Basicly I have aMemeber membership system. Now they sigup process

for a member is only one way.. where you have your userers signup

in aMemeber and then aMemeber will create accounts in 3rd Party

apps

 

You cant have 3rd Party Apps Create signups in aMemeber

and i will tell you that it is extremmly hard and if your not

a seasoned PHP developer... dont waste your time.

 

But ofcource.. i have to have things the hard way! So here I am

ripping up the system to alleviate this one way cluster-fuk

because i need WHM to send off signup information to aMember.

 

So here is what i got, and why im working with Matt to get this done

when an invoice is paid it shoots off the action hook

 

actionhook_InvoicePaid($vars)

 

Now here is my problem, using the

 

$invoiceID = $vars['InvoiceID'];

 

I need to

 

1) Make sure at least one of the items ordered in that invoice

the product id 10 or 11 (these are the membership products)

 

2) Once i verify this, i need to get the userid, so i can get

the account information. email, password, etc...

 

3) I then send this off to aMember {more on this in a moment}

 

 

NOW!!

 

My hack at this was

   $result = mysql_query("SELECT packageid, userid FROM tblhosting WHERE orderid='".$invoiceID."'");

   $packageid_array = mysql_fetch_array($result,MYSQL_ASSOC);
$packageid=$packageid_array['packageid'];

   // verify package id is of the correct product type - one that should have additional action taken
   if(($packageid == "0000000011") || ($packageid == "0000000010")   )
   {
      // success
   }

 

 

From what i tested, when an invoice becomes paid, the invoice id and the order id match in the

 

tblhosting table, then when i delete the invoice the row in the tblhosting is deleted but not the

 

tblinvoiceitems,

 

The tblinvoiceitems contains a relid .. but i have no idea how the relid is used

 

Now when i asked Matt He said

 

The Order ID does not equal Invoice ID. It may do on some occasions as a coincidence but it certainly won't remain that way once you have more invoices in the system.

 

So oviously this is not the SURE FIRE WAY.. and this is what im lokoing for help on.. in other words

 

I need the SUREFIRE way, with the invoice id to make sure that the items ordered was indeed 10 or 11 and

 

get the userid.

 

=================== NOW FOR AMEMBER =====================

 

 

I figured i would show you the way to hack an aMember signup process

 

** PLEASE NOTE, THIS IS ONLY FOR FREE PRODUCTS IN aMEMBER

 

This is because im having WHM handle the billing, i just needed to create accounts in aMemeber, so that

 

the protected directories that aMemeber

protects would create an entry in the htgroup and htpasswd files

 

SO ITS IMPORTANT TO SETUP YOUR PROTECTED DIR WITH htpassword

as the METHOD OF PROTECTION

 

 

So...

 

aMemebr is stuborn you cant send off usual posts to the signup.php

page because it wont maintain session varibales, and then you will

have an added memeber into the system, that is not active and

no entrys are created in the htpassword or htgroup files

 

PAIN IN THE ASSSS!!

 

So i had to basicly hack the **** out of the signup.php page

in order to imitate the signup and thankyou automation process

so that the proper entries are created!

 

PLUS YOU MAY NOTE, in PHP5 Curl does not followredirect no more

so i had to incorperate a CURL redirect hack.. because amember

does redirects, during the signup process

 

 

This is the code that makes the request to aMemeber

make a file named send_to_amember.php

 

Place this code

 


// cURL CURLOPT_FOLLOWLOCATION WorkAround
// When OpenBase Dir or SafeMode is set
function curl_redir_exec($ch,$debug="")
{
   static $curl_loops = 0;
   static $curl_max_loops = 20;

   if ($curl_loops++ >= $curl_max_loops)
   {
       $curl_loops = 0;
       return FALSE;
   }
   curl_setopt($ch, CURLOPT_HEADER, true);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $data = curl_exec($ch);
   $debbbb = $data;
   list($header, $data) = explode("\n\n", $data, 2);
   $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

   if ($http_code == 301 || $http_code == 302) {
       $matches = array();
       //check in header
	if(preg_match('/Location:(.*?)\n/', $header, $matches))
	{
		$url = @parse_url(trim(array_pop($matches)));
	}

	if (!$url)
       {
           //couldn't process the url to redirect to
           $curl_loops = 0;
           return $data;
       }
       $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));

	//if (!$url['scheme'])
       //    $url['scheme'] = $last_url['scheme'];
       //if (!$url['host'])
       //    $url['host'] = $last_url['host'];
       //if (!$url['path'])
       //    $url['path'] = $last_url['path'];

       $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');

	curl_setopt($ch, CURLOPT_URL, $new_url);
   //    debug('Redirecting to', $new_url);
       return curl_exec($ch);
   } else {
	// Check in Data
	if(preg_match('/<meta(.*)url=(.*?)"/i',$debbbb,$matches))
	{
		$url=@parse_url(trim($matches[2]));
	}

	if (!$url)
       {
           //couldn't process the url to redirect to
		$curl_loops=0;
		return $debbbb;
       }

	$last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));

	//if (!$url['scheme'])
       //    $url['scheme'] = $last_url['scheme'];
       //if (!$url['host'])
       //    $url['host'] = $last_url['host'];
       //if (!$url['path'])
       //    $url['path'] = $last_url['path'];

       $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');
       curl_setopt($ch, CURLOPT_URL, $new_url);
      // debug('Redirecting to', $new_url);
       return curl_redir_exec($ch);

   }
}


// SETUP POST FIELDS

$f_name='Rick';
$l_name='M';
$email='email@yourdomain.com';
$username='username';
$pass='pass';

$url_post  = 'product_id'."=". '1'. "&";
$url_post  .= 'paysys_id'."="."free". "&";
$url_post  .= 'paysys_id_not_required'."="."for javascript". "&";
$url_post  .= 'name_f'."=".$f_name. "&";
$url_post  .= 'name_l'."=".$l_name. "&";
$url_post  .= 'email'."=".$email. "&";
$url_post  .= 'login'."=".$username . "&";
$url_post  .= 'pass0'."=".$pass. "&";
$url_post  .= 'pass1'."=".$pass. "&";
$url_post  .= 'do_payment'."="."1". "&";
$url_post  .= 'price_group'."=".''. "&";
$url_post  .= 'i_agree'."="."1". "&";

// NOTE: Make Sure to make a /cookies/ folder in your
// amember directory
// curl needs this to maintain PHP session


//if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off'))
if(function_exists('curl_init'))
{
$ch = curl_init();
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL,'http://www.yourdomain.com/members/signup_hacked.php');

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS,$url_post);

// $DOC_ROOT/amember/cookies/cookie.txt MAKE SURE READABLE and WRITEABLE !!
curl_setopt ($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/amembers/cookies/cookies.txt');

// CURLOPT_FOLLOWLOCATION Does Not Work With OpenBase Dir or SafeMode
// Work Around Function Included in general.php
// curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1);
$contents=curl_redir_exec($ch);


            // THIS ECHOS THE RESPONSE
echo '<pre>'.htmlentities($contents).'</pre>'; exit();
// CLOSE HANDLE
curl_close ($ch);
}

 

 

Now we are ready to send off a request to aMemeber

make another file named signup_hacked.php and

put it in the same folder as signup.php

 

 

Add this code

 

 



include('./config.inc.php');
$signup_scope_allowed = array('', 'signup');


$vars = & get_input_vars();
$additional_values='';


// IF YOU WANT TO CHECK FOR EXISTING USER // OFF NOW
//if($db->users_find_by_string($vars['email'], 'email', 1)){
//die('USER EXISTS');
//}

// Setup Vars

$vars['login'] = strtolower($vars['login']);
$vars['paysys_id'] = 'free';
$vars['pass'] = $vars['pass1'];
$vars['paysys_id'] = $vars['paysys_id'];

$begin_date = date('Y-m-d');
$expire_date = '2037-12-31'; // LIFETIME

// BECAUSE WE HANDLE SUBSCRIPTIONS WITH WHM
// SO SETUP LIFETIME!

// But that makes a termination question for Matt!! 


// ADD USER
$member_id = $db->add_pending_user($vars);
$payment_id = $db->add_waiting_payment($member_id, 		               $vars['product_id'], 
$vars['paysys_id'],						  
'0.00', 								   $begin_date, 							   $expire_date,						    
$vars,								   $additional_values);


$payment = $db->get_payment($payment_id);
$db->update_payment($payment_id, $payment);

// IF YOU WANT TO IMPLIMENT ERRORS

//    if ($error) {
//        $db->delete_payment($payment_id);
//		$db->delete_user($member_id);
//	}

$db->finish_waiting_payment(
		intval($payment['payment_id']), 
                   		'free', 
		$REMOTE_ADDR, 
		'',
                    		$vars);	



 

 

Thats Basicly it, You now can automate the signup of a FREE product

in amember, i hope this helps as i hope someone can clear up my

issue as well

 

I will keep things posted as i develop more

 

 

Thanks

Rick

 

 

PS: by the way make sure you copy and paste your messages

into a note pad if your writing a long post like this

because i just lost everything when i tried to POST!!!!!

But im a trooper!! :)

Link to comment
Share on other sites

Ok this is how to solve my first part, getting the correct item ordered before the amember script gets called, Matt Said

 

 

Basically, take the invoice id, query tblinvoiceitems, get the relid field on a row that has a type Hosting, then lookup that relid in tblhosting on the id field. You can then get the packageid from there.

 

 

SO Thanks to this user in post

http://forum.whmcs.com/showthread.php?t=8536

I got a quick start from here

 

 


function actionhook_InvoicePaid($vars) {
   # This function runs when an invoice is fully paid and therefore the services renewed
   # $vars["InvoiceID"]

   // we need invoiceid in order to do a lookup
   $invoiceID = $vars['InvoiceID'];

   // lookup relid from the invoiceid
   $result = mysql_query("SELECT relid FROM tblinvoiceitems WHERE type='Hosting' AND invoiceid='".$invoiceID."'");

   $grab_relid = mysql_fetch_row($result);
   $relid = $grab_relid[0];

   // lookup the packageid from the relid
   $result = mysql_query("SELECT packageid, userid FROM tblhosting WHERE id='".$relid."'");

   $grab_packageid = mysql_fetch_row($result);
   $packageid = $grab_packageid[0];

   // verify package id is of the correct product type - one that should have additional action taken
   if(($packageid == "0000000011") || ($packageid == "0000000010")   )
   {
     //success spark amember code!
   }

 

 

 

Take Care

Rick

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated