---- dataentry ---- type : integration # do not change this line systems : Campaign Monitor, MailBuild # the system that the integration is for name : Add customers to mailing list # the name of the integration description : Automatically add your customers to your Campaign Monitor or MailBuild lists tags_tags : mailing list, emarketing # tags, separated by commas date_dt : 2007-08-21 # the date in YYYY-MM-DD format version : # if you have a version for your code, enter it here developer_url : http://www.themancan.com/ # if you'd like a link back to your site, stick it here ---- ====== Campaign Monitor (and MailBuild) Integration ====== We at FoxyCart //really// like [[http://www.campaignmonitor.com/|Campaign Monitor]]. It's built for web-designers and developers, just like FoxyCart, and it's very easy to setup, use, and love. Campaign Monitor recently updated their API examples, so check 'em out here: http://www.campaignmonitor.com/api/samples/default.aspx#php The following is a basic script to automatically add your FoxyCart customers to your Campaign Monitor list. Here's the basic instructions: - [[http://www.campaignmonitor.com/trial/|Set up]] or [[http://app.campaignmonitor.com/login.aspx|login]] to Campaign Monitor. If you're just setting it up, follow their instructions to set up a list and etc. - Hit your "Account Settings" up in the top left. - Grab the "Your API Key" value. - Paste it into a copy of the script below in the appropriate location. - Hit the "Manage Subscribers" tab. - Click on the list you want to add your FoxyCart customers to. - Find the "API List ID" code, copy it, and paste it into your copy of the code below. - Replace the string of XXXXXX's in your copy of the code below with yoru FoxyCart datafeed key (as set in the [[http://www.foxycart.com/admin.php|FoxyCart Admin]]). - Save your copy of the code below to your PHP capable webserver. - Point FoxyCart's XML datafeed to the location of this script on your server. - TEST! Then test it again. If you have issues, let us know in [[http://forum.foxycart.com/|the forum]]. ===== The Code ===== Copy this code and modify it according to the directions above. * @version $Id: class.rc4crypt.php,v 3.2 2006/03/10 05:47:24 mukul Exp $ * @copyright Copyright © 2006 Mukul Sabharwal * @license http://www.gnu.org/copyleft/gpl.html * @package RC4Crypt */ /** * RC4 Class * @package RC4Crypt */ class rc4crypt { /** * The symmetric encryption function * * @param string $pwd Key to encrypt with (can be binary of hex) * @param string $data Content to be encrypted * @param bool $ispwdHex Key passed is in hexadecimal or not * @access public * @return string */ function encrypt ($pwd, $data, $ispwdHex = 0) { if ($ispwdHex) $pwd = @pack('H*', $pwd); // valid input, please! $key[] = ''; $box[] = ''; $cipher = ''; $pwd_length = strlen($pwd); $data_length = strlen($data); for ($i = 0; $i < 256; $i++) { $key[$i] = ord($pwd[$i % $pwd_length]); $box[$i] = $i; } for ($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $key[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for ($a = $j = $i = 0; $i < $data_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $k = $box[(($box[$a] + $box[$j]) % 256)]; $cipher .= chr(ord($data[$i]) ^ $k); } return $cipher; } /** * Decryption, recall encryption * * @param string $pwd Key to decrypt with (can be binary of hex) * @param string $data Content to be decrypted * @param bool $ispwdHex Key passed is in hexadecimal or not * @access public * @return string */ function decrypt ($pwd, $data, $ispwdHex = 0) { return rc4crypt::encrypt($pwd, $data, $ispwdHex); } } // Foxy Stuff $DataFeedKey = 'this is your foxy cart data feed key'; // your foxy cart datafeed key // Campaign Monitor Stuff $APIKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //your apikey $ListID = "XXXXXXX"; //your list ID // Declare a class for a custom field. It must be called this to allow proper mapping when the service is called. class SubscriberCustomField { public $Key; public $Value; } if (isset($_POST["FoxyData"])) { $FoxyData_encrypted = urldecode($_POST["FoxyData"]); $FoxyData_decrypted = rc4crypt::decrypt($DataFeedKey,$FoxyData_encrypted); $FoxyDataArray = new SimpleXMLElement($FoxyData_decrypted); foreach($FoxyDataArray->transactions->transaction AS $transaction) { $customer_name = ""; // got any custom stuff? - use this // $my_custom_code = ""; $resultCode = ""; $resultMessage = ""; $customer_name .= $transaction->customer_first_name; $customer_name .= " " . $transaction->customer_last_name; $customer_email = $transaction->customer_email; $customer_id = $transaction->customer_id; // got some custom stuff in the details or the options? - use this /* foreach($transaction->transaction_details->transaction_detail AS $transaction_detail) { foreach($transaction_detail->transaction_detail_options->transaction_detail_option AS $transaction_detail_option) { if ($transaction_detail_option->product_option_name == "my_custom_code") { $my_custom_code = $transaction_detail_option->product_option_value; } } } */ // ok, now we have our data, let's shake hands with the nice folks at campaign monitor try { $client = new SoapClient("http://app.campaignmonitor.com/api/api.asmx?wsdl", array('trace' => 1)); // Set the basic API request information. $params->ApiKey = $APIKey; $params->ListID = $ListID; $params->Email = $customer_email; $params->Name = $customer_name; // Adding a standard text type custom field. This also how you would add a number, or single select multi-option field. // For the single select, make sure the value you set in the form has been added in Campaign Monitor. $customeridClass = new SubscriberCustomField(); $customeridClass->Key = '[customer_id]'; $customeridClass->Value = $customer_id; $customfields = array($customeridClass); // Assign our custom field array to our parameter list $params->CustomFields = $customfields; // Make the call $result = get_object_vars($client->AddSubscriberWithCustomFields($params)); $resultCode = current($result)->Code; $resultMessage = current($result)->Message; // If not successful if ($resultCode > 0) { $isError = true; } // The following code produces the entire service request and response. It may be useful for debugging. /* print "
\n";
	  		print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
	  		print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
	  		print "
"; */ } catch (SoapFault $exception) { $isError = true; } } if ($isError) { // Something didnt work right, return an error // This ensures that the transactions will still show up on the next datafeed. print "error"; } else { // we're good. Mark it fed. print "foxy"; } } else { // Something didnt work right, return an error // This ensures that the transactions will still show up on the next datafeed. print "error"; } ?>