Infusionsoft, Always Typecast!!!!!!!!!!!
Jun/091
blogPost extends php implements Infusionsoft
{
I was trying run some calls to the Infusionsoft PHP SDK and I kept getting errors that made no sense at first sight. By habit I am use to lose PHP calls that don’t check the data type. The functions that I usually write don’t care if the Data Type is String with a number in it example $var = “2″; … even in my sql queries. So when I was calling addRecurring() it was throwing errors.
For reference $_POST['numberOfDaysToBilling'] was a text input field on the previous page in a form. and the value of $_POST['numberOfDaysToBilling'] is “8″.
- My Bad Call that was throwing:
1 | $myApp->addRecurring($infusionID,false,1,3,$creditCardID,1,".$_POST['numberOfDaysToBilling']."); |
- My GOOD Call with no errors:
1 | $myApp->addRecurring($infusionID,false,1,3,$creditCardID,1,".(integer)$_POST['numberOfDaysToBilling']."); |
All variables that come from Post or Get are all type casted to String so don’t just dump data from a form into Infusionsoft calls or you will be pulling out some hair!!! ALWAYS TYPECAST
- when calling Infusionsoft.
}
Infusionsoft part 4; authenticate users, tags, custom vars
May/094
blogPost extends php implements Infusionsoft
{
Part 4
Here is what we will cover in the final series of Infusionsoft basics
- Authenticating a user “logging in” for a Subscription
- Adding a tag for a user
- Getting/Setting custom variables
First let’s authenticate a user , this is a great way to use Infusionsoft and recurring payments for a subscription based community.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php session_start(); include_once("infusionSDK/src/isdk.php"); $infusionConn = new iSDK; $connSuccess = $app->cfgCon("connectionName"); //Authenticate a User $uid = $app->authenticateUser("user@email.com","password"); if($uid >= 0) { //Store the authentication in a session var so every page will know if the user is valid $_SESSION['authenticated'] = true; } else { $_SESSION['authenticated'] = false; } ?> |
Ok the next subject confused me for quite a while… So I was trying to set a Tag for user, which would put them into a email/marketing campaign. I couldn’t find anything about Tags in the API. So I got lucky and figured out that “Tag’s” is the name in the Infusionsoft management tools, BUT to access them in the API and database they are called “Contact Group’s“. Here is the db table for “Tags” or “Contact Groups” TABLE , and here is a code sample:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php session_start(); include_once("infusionSDK/src/isdk.php"); $infusionConn = new iSDK; $connSuccess = $app->cfgCon("connectionName"); //Find the user ID from the email address they used to login with. $findFieldsID = array('Id'); $contactID = $app->dsFind('Contact',1,0,'email',''.$email.'',$findFieldsID); //Assign tag 97 to the user $groupAssignResult = $app->grpAssign($contactID['Id'],97); if($groupAssignResult == "true") { print"SUCCESS WE RULE!"; } ?> |
That’s it !!! Let me know if you have any additional questions.
-Dave www.davegeurts.com
- Part 1 – Part 2 – Part 3 – Part 4 -
}
Infusionsoft part 3, send immediate email new contact
May/092
blogPost extends php implements Infusionsoft
{
Part 3
Here is a basic outline of what we will get into this post.
- Skip the QUEUE system
- Send a custom HTML/Text welcome email immediately
- Attach the custom email to Infusionsoft
Probably the most frustrating thing that developers talk about with Infusionsoft is the inability to send an immediate email to a customer after a transaction. Infusionsoft only allows you to put an email into a queue system that can take up to an hour to actually send the email. If you were to rely on the queue in most peoples opinion including mine. You look pretty tacky and could lose a potential customer/member of a community during the queue time. The very odd thing about this is; there is a very simple work around that infusionsoft created a hook for. So I’m not sure why there is so much gnashing of teeth and bitching. Basically you manually generate the email, send it yourself immediatly and then you can even store it in Infusionsoft db through the api call attachEmail() . Here is an example, you would run this code right after a successful addContact or any type of transaction. Also pretend that the code is picking up where part 2 of this series left off… so basically a form was just submitted through POST with the users details.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <?php include_once("infusionSDK/src/isdk.php"); //Generate Email $subject = 'ObjectOrientedBlogging.com - Welcome, '.$_POST['firstName'].' '.$_POST['lastName'].' to our community'; //Create two bodies of text, one for email clients that allow HTML and one for only Text Clients $htmlBody = ' Hello '.$_POST['firstName'].' '.$_POST['lastName'].' , Thank you for your doing business with us, your username is '.$_POST['email'].' and your password is '.$_POST['password'].'. <a href=\'www.test.com/login.php?email='.$_POST['email'].'\'>Click here to login to subscription.</a> <img src='www.test.com/images/logo.jpg' /> '; $textBody = ' Hello '.$_POST['firstName'].' '.$_POST['lastName'].' , Thank you for your doing business with us, your username is '.$_POST['email'].' and your password is '.$_POST['password'].'. To login to subscription, visit this url: www.test.com/login.php?email='.$_POST['email'].' '; $from = 'demo@demo.com'; $to = $_POST['email']; $boundary = "nextPart"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "From: ".$from."\r\n"; $headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n"; //add text only version $headers .= "\n--$boundary\n"; // beginning \n added to separate previous content $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; $headers .= "".$textBody.""; //add html version $headers .= "\n--$boundary\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "".$htmlBody.""; $sendMailSuccess = mail($to, $subject, "", $headers); if($sendMailSuccess ) { //Attach this email to infusionsoft Server... Same thing as Infusionsoft automatically sending the email ! $sentDate = date("m-d-Y",mktime(0, 0, 0, date("m"), date("d"), date("Y"))); $attachSuccess = myApp->attachEmail($infusionMemberID,$from,$from,$to,"","","HTML",$subject,$htmlBody,$textBody,$headers,$sentDate,$sentDate); if($status == "TRUE" || $status == "True" || $status == "true") { print "<br/> <b><font color=\"13941c\">SUCCESS!</font><b> Email Sent and Attached!</b>"; } } ?> |
Don’t shy away from this, it is a lot of code and might look intimidating but it is really easy once you get it. You can just copy and paste and then go line by line and replace my fake content with what you need. Best part about this is it sends the email using the native php calls so if your php configuration allows send mail then you are set!
Next time….
- Authenticating a user “logging in” for a Subscription
- Adding a tag for a user
- Getting/Setting custom variables
-Dave www.davegeurts.com
- Part 1 – Part 2 – Part 3 – Part 4 -
}
Infusionsoft part 2, connecting and querying…ing ing
May/092
blogPost extends php implements Infusionsoft
{
Part 2
Ok so basically here is a breakdown of what we are going to cover tonight…
- Adding a Contact from a HTML form
- Connecting to Infusionsoft in PHP
- Confirm that the email address provided hasn’t already be used
- Validating Credit Card information
- Adding a Credit Card to a members account
The HTML form
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <form action="addContact.php" method="post">
<div>
<span style="text-decoration: underline;"><strong>Contact Information:</strong> </span>
Email: <input id="email" type="text" />
Password: <input id="password" type="password" />
First Name: <input id="firstName" type="text" />
Last Name: <input id="lastName" type="password" />
<span style="text-decoration: underline;"><strong>Credit Card Information</strong></span>
Card Type:
<select id="cardType">
<option value="Visa"> Visa
</option><option value="Discover"> Discover
</option></select>
Card Number: <input id="cardNumber" type="text" />
Expiration Date: <input id="expDate" type="text" />
CVV2: <input id="cvv2" type="text" />
<div> <input type="submit" /></div>
</div>
</form> |
php script ‘addContact.php’
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <?php include_once("infusionSDK/src/isdk.php"); //Create a connection with infusionsoft $infusionConn = new iSDK; $connSuccess = $infusionConn ->cfgCon("connectionName"); //If we connected successfully if ($connSuccess) { //Check if email address has already been used in the system $returnFields = array('Id'); $emailCheck = $infusionConn ->dsFind('Contact',1,0,'email',$_POST['email'],$returnFields); if($emailCheck[0]['Id'] > 0) { print" Error: Email address already used in our system."; } else { //Store user info in an array of data to send to infusionsoft $contactData= array('Username' => $_POST['email'], 'Email' => $_POST['email'] , 'Password' => $_POST['password'] , 'FirstName' => $_POST['firstName'] , 'LastName' => $_POST['lastName'] ); //Call the server to create a new contact //Store the id that is returned from the call for later use $contactID = $infusionConn -> addCon($contactData); //Infusionsoft wants the expire month and year separated $splitCCDate = explode("/",$_POST['expirationDate']); //Validate the credit card information $cardData = array( 'CardType' => $_POST['cardType'] , 'ContactId' => $contactID, 'NameOnCard' => $_POST['firstName'] .' '.$_POST['lastName'], 'CardNumber' => $_POST['cardNumber'], 'Last4' => substr($cardNumber,12,4), 'ExpirationMonth' => $splitCCDate[0], 'ExpirationYear' => $splitCCDate[1], 'CVV2' => $_POST['cvv2']); $isValid= $infusionConn -> validateCard($cardData); if($isValid) { //The Credit Card is valid, lets store and attach it to infusionsoft $creditCardID = $infusionConn -> dsAdd("CreditCard", $cardData); } } } else { print" Error: Could not connect to Infusionsoft. "; } ?> |
That’s about it, not so bad… right!! Of course you would want to add a capcha and validation to the HTML form. I hope the PHP is fairly straight forward, if there is something that doesn’t make sense. Hit me up with some comments and/or an email.
Next we will cover how to:
- Send a custom HTML/Text welcome email immediately
- Attach the custom email to Infusionsoft “Official Records”
-Dave www.davegeurts.com
- Part 1 – Part 2 – Part 3 – Part 4 -
}
Implementing Infusionsoft with php, the journey begins
Apr/095
blogPost extends php implements infusionsoft
{
Infusionsoft – http://www.infusion.com/
Yo, if you stumbled upon this I imagine you are a PHP developer and you are attempting to use Infusionsoft for your e-com / marketing needs. As you have probably already discovered through Google you are on a road less traveled. At least less traveled as far as developers that wish to share their experience and knowledge.
My first goal is to gather as much information and resources as possible to help with Infusion PHP API.
Here is what I came up with:
- You talk to the Infusionsoft API through xmlrpc http://en.wikipedia.org/wiki/XML-RPC
- Here is a list of all SQL Tables and Fields
- Infusionsoft php SDK – iSDK http://fuzioncore.com/infusionsoft-php-sdk/
- The best resource, a blog by Justin Morris – http://fuzioncore.com/category/infusionsoft/
- I wouldn’t waste much time with the www.infusionsoft.com “Community” 95% of it is for marketing tips, It does have a message forum with a bunch of postings from developers all though most of them dont have very good replies.
- There is appaerantly a word press plugin for infusionsoft based on PHP,… not helpful to me as I am porting a PHP/MYSQL/Authorize.net membership system I wrote that is not based on wordpress.
That is pretty much all the information that is out there when it comes to PHP and Infusionsoft. I would suggest that you use iSDK by Justin Morris. This basically takes care of all the xmlrpc for you, which can potentially be a large learning curve for some of you ‘including me!” From what I gathered Justin works for Infusionsoft , which can be good and bad. He is automatically biased but also has access to things others won’t. Justin is very nice and responds to emails and is fairly active on his blog. I posted the iSDK documentation on my webserver for your viewing pleasure, so that you dont have to download the sdk and uncompress it.
START HERE – I would suggest first reading the iSDK docs
http://www.davegeurts.com/tools/iSDK/Doc/
That is pretty much it for the first night…. stay tuned next we will connect to infusionsoft and add a member.
dave geurts – www.davegeurts.com
- Part 1 – Part 2 – Part 3 – Part 4 -
}