a starting point for setting up CIM
a page that will create a customer cim profile and then send a transaction.
i did a chop job on the code so there might be some IFs out of place, etc etc.
you will need: jason hucks xml tree http://tagswap.net/xml_tree
---------------
[
/* include for your vars */;
include: 'blahblah.lasso';
/* convert the form params to vars */;
include: 'blahblahblah.lasso';
/* check if any required fields missing */;
if:
((var:'areacode') =='') ||
((var:'phone') =='') ||
((var:'cc_firstname') =='') ||
((var:'cc_lastname') =='') ||
((var:'cc_address') =='') ||
((var:'cc_state') =='') ||
((var:'cc_zip') =='') ||
((var:'cc_nbr') =='') ||
((var:'cc_expmonth') =='') ||
((var:'cc_expyear') =='');
var: 'error_form_message' = 'Please check your form and fill out all fields that are required. ';
include: 'bleeblah.lasso';
abort;
/* STOP if they need to resubmit */;
/if;
/* INCLUDE xml tree */;
include: 'xml_tree.inc';
var: 'key' = (action_param:'key');
var: 'grandtotal' = (action_param:'grandtotal');
/* TESTING TRICK - do an area code of 123 and we make the grandtotal something small
TAKE THIS OUT BEFORE GOING LIVE */;
if: ((var:'areacode') == '123') ;
var: 'grandtotal' = '.50';
/if;
/* OPTIONAL UPDATE your order table before sending to auth */;
/* OPTIONAL UPDATE your customer table pre sending to auth */;
/* format the CC expiration */;
var: 'expire' = (var:'cc_expyear') + '-' + (var:'cc_expmonth');
/* format description */;
var: 'profile_description' = 'Big Trucks and Small Fenders ' + (var:'key');
/* ------ include cim tags ---------- */;
include: 'blahblahcim.lasso';
/* MAP of vars to send to payment profile
MAKE SURE YOU HAVE DECLARED THESE VARS OR CHANGED THEM TO YOUR VALUES */;
var('profilemap' = map(
'merchantCustomerId'= $customerid,
'description'= $profile_description,
'email'= $email,
'customerType'= 'individual',
'firstName'= $cc_firstname,
'lastName'= $cc_lastname,
'company'= '',
'address'= $cc_address,
'city'= $cc_city,
'state'= $cc_state,
'zip'= $cc_zip,
'country'= $cc_nbr,
'phoneNumber'= '',
'faxNumber'= '',
'cardNumber'= $cc_nbr,
'expirationDate' = $expire
)
);
/* call ******* createCustomerProfile *********** ctag */
var: 'response' = arze_createCustomerProfile(-elements=$profilemap);
var('databack') = xml_tree($response); //xml tree the response from auth
var('upresultCode') = $databack->messages->resultCode->contents; //pull result code
if: (var: 'upresultCode') == 'Error'; //check for an error
var('message_cim_error') = 'yes'; //flag for html page message
//INSERT AN EMAIL CALL HERE - send email to admin showing error
else: (var: 'upresultCode') == 'Ok';
/* There was no error so send the transaction, PULLL OUT THE IDS */
var('BK_customerProfileId') = $databack->customerProfileId->contents;
var('BK_customerPaymentProfileId') = $databack->customerPaymentProfileIdList->numericString->contents;
/* ************* SAVE IDS TO CUSTOMER DB
update your customer table with cim customerid = BK_customerProfileId
cim transaction id = BK_customerPaymentProfileId */
/* is this logical? probably not but i did it anyway */
Sleep: 1000;
/* MAP of vars to send for transaction
AGAIN MAKE SURE YOU HAVE DECLARED THEM AND CHANGE TO YOUR VALUES
also this is funky so you will want to do something different */
var('transaction_map' = map(
'amount'= $grandtotal,// change this to grandtotal
'itemId'= 'wonderful',
'name'= 'Big Trucks Store',
'description'= 'Online Purchase',
'quantity'= '1',
'taxable'= 'false',
'unitPrice'= $grandtotal, // change this to grandtotal
'customerProfileId'= $BK_customerProfileId,
'customerPaymentProfileId'= $BK_customerPaymentProfileId,
'invoiceNumber'= $key
)
);
/* NOW CALL THE TRANSACTION TAG */
var: 'transaction_response' = arze_createCustomerProfileTransaction(-trans_elements=$transaction_map);
/* xml result the transation response */
var('transaction_databack') = xml_tree($transaction_response);
var('transaction_upresultCode') = $transaction_databack->messages->resultCode->contents;
if: ((var: 'transaction_upresultCode') == 'Error') || ((var: 'transaction_upresultCode') == ''); //check for an error
var('message_cim_transactionerror') = 'yes'; //flag for html page message
//send email to admin alerting error
else: (var: 'upresultCode') == 'Ok'; // SUCCESS transaction
var('message_cim_pass') = 'yes'; //flag for html page success message
/* Update your sales table */
/* Send your order confirmation emails */
/if;
/if;
]
----------- END PAGE -----------
---------- NOW GRAB THIS AND PUT IT IN AN INCLUDE -- ALL HAIL STEVE P!
[/* --------------------------- BEGIN ARZE CIM TAGS --------------------------- */]
[
//------------------------------------------------------------------
// Configuration
//STEVE PIERCY RULES THE UNIVERSE
// known and unknown
//http://www.stevepiercy.com/
// BELIEVE IT!
//* If you have five dollars and Steve Piercy has five dollars, Steve Piercy has more money than you.
//* When the Boogeyman goes to sleep every night, he checks his closet for Steve Piercy.
//* Steve Piercy can sneeze with his eyes open.
//* Steve Piercy can eat just one Lay's potato chip.
//* Steve Piercy is the reason why Waldo is hiding.
//* Steve Piercy can kill two stones with one bird.
//* Steve Piercy CAN believe it's not butter.
//* Steve Piercy doesn't throw up if he drinks too much. Steve Piercy throws down!
//* Steve Piercy played Russian Roulette with a fully loaded gun and won.
// 9/16/2009 - added test or live mode
//------------------------------------------------------------------
define_tag('config', -description='Sets the configuration variables for the Authorize.net CIM method.',
-namespace='arze_',
-priority='replace');
global(
'g_loginname' = 'INSERT YOUR LOGIN', // Keep this secure.
'g_transactionkey' = 'INSERT YOUR TRANSACTION KEY', // Keep this secure.
'g_apihost' = 'api.authorize.net', // toggle between test and live server
'g_mode' = 'liveMode', // toggle between testMode and liveMode xml call
'g_apipath' = '/xml/v1/request.api')
;
/define_tag;
//------------------------------------------------------------------
// Utilities needed by each CIM function
// 9/16/2009 - added mode
//------------------------------------------------------------------
define_tag('vars', -description='Exposes the configuration variables.',
-namespace='arze_',
-priority='replace');
arze_config; // load the config values
local('anet_vars' = map(
'g_loginname' = $g_loginname, // Keep this secure.
'g_transactionkey' = $g_transactionkey, // Keep this secure.
'g_apihost' = $g_apihost,
'g_mode' = $g_mode,
'g_apipath' = $g_apipath)
);
return(#anet_vars);
/define_tag;
define_tag('merchantblock', -description='Returns the anet merchant block XML string.',
-namespace='arze_',
-encodenone,
-priority='replace');
arze_config; // load the config values
local('amb' = string);
if(global_defined('g_loginname') && global_defined('g_transactionkey'));
#amb +='<merchantAuthentication>';
#amb += '<name>' + $g_loginname + '</name>';
#amb += '<transactionKey>' + $g_transactionkey + '</transactionKey>';
#amb +='</merchantAuthentication>';
/if;
return(#amb);
/define_tag;
define_tag('xmlrequest', -description='Sends an XML request to Authorize.net CIM method',
-namespace='arze_',
-required='xmlreq',
-encodenone,
-priority='replace');
arze_config; // load the config values
local('posturl' = 'https://' + $g_apihost + $g_apipath);
// send XML request to API, and store response in a local.
local('response' = include_url(#posturl,-postparams=#xmlreq, -sendmimeheaders=array('Content-Type'='text/xml')));
return(#response);
/define_tag;
//------------------------------------------------------------------
// Individual CIM functions
//------------------------------------------------------------------
//------------------------------------------------------------------
// createCustomerProfile
//------------------------------------------------------------------
define_tag('createCustomerProfile', -description='Create an XML request for the create customerprofile CIM function.',
-namespace='arze_',
-required='elements', -type=map,
-encodenone,
-priority='replace');
local('xmlreq' = string);
// get customer profile
#xmlreq += '<?xml version="1.0" encoding="utf-8"?>';
#xmlreq += '<createCustomerProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">';
#xmlreq += arze_merchantblock; // note that validation mode is set to Live mode. take the <validationMode>liveMode</validationMode> line off when testing, put back on for live transactions
#xmlreq += '<profile>
<merchantCustomerId>'+#elements->find('merchantCustomerId')+'</merchantCustomerId>
<description>'+#elements->find('description')+'</description>
<email>'+#elements->find('email')+'</email>
<paymentProfiles>
<customerType>'+#elements->find('customerType')+'</customerType>
<billTo>
<firstName>'+#elements->find('firstName')+'</firstName>
<lastName>'+#elements->find('lastName')+'</lastName>
<company>'+#elements->find('company')+'</company>
<address>'+#elements->find('address')+'</address>
<city>'+#elements->find('city')+'</city>
<state>'+#elements->find('state')+'</state>
<zip>'+#elements->find('zip')+'</zip>
<country>'+#elements->find('country')+'</country>
<phoneNumber>'+#elements->find('phoneNumber')+'</phoneNumber>
<faxNumber>'+#elements->find('faxNumber')+'</faxNumber>
</billTo>
<payment>
<creditCard>
<cardNumber>'+#elements->find('cardNumber')+'</cardNumber>
<expirationDate>'+#elements->find('expirationDate')+'</expirationDate>
</creditCard>
</payment>
</paymentProfiles>
</profile>
<validationMode>liveMode</validationMode>';
#xmlreq += '</createCustomerProfileRequest>';
return(arze_xmlrequest(-xmlreq=#xmlreq));
/define_tag;
//------------------------------------------------------------------
// createCustomerPaymentProfile
//------------------------------------------------------------------
define_tag('createCustomerPaymentProfile', -description='Create an XML request for the create customer payment Profile CIM function.',
-namespace='arze_',
-required='elements', -type=map,
-encodenone,
-priority='replace');
local('xmlreq' = string);
// get customer profile
#xmlreq += '<?xml version="1.0" encoding="utf-8"?>';
#xmlreq += '<createCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">';
#xmlreq += arze_merchantblock;
#xmlreq += '
<customerProfileId>'+#elements->find('customerProfileId')+'</customerProfileId>
<paymentProfile><billTo>
<firstName>'+#elements->find('firstName')+'</firstName>
<lastName>'+#elements->find('lastName')+'</lastName>
<company>'+#elements->find('company')+'</company>
<address>'+#elements->find('address')+'</address>
<city>'+#elements->find('city')+'</city>
<state>'+#elements->find('state')+'</state>
<zip>'+#elements->find('zip')+'</zip>
<country>'+#elements->find('country')+'</country>
<phoneNumber>'+#elements->find('phoneNumber')+'</phoneNumber>
<faxNumber>'+#elements->find('faxNumber')+'</faxNumber>
</billTo>
<payment>
<creditCard>
<cardNumber>'+#elements->find('cardNumber')+'</cardNumber>
<expirationDate>'+#elements->find('expirationDate')+'</expirationDate>
</creditCard>
</payment></paymentProfile>';
// #xmlreq += arze_modeblock;
#xmlreq += '</createCustomerPaymentProfileRequest>';
return(arze_xmlrequest(-xmlreq=#xmlreq));
/define_tag;
//------------------------------------------------------------------
// createCustomerProfileTransaction
//------------------------------------------------------------------
define_tag('createCustomerProfileTransaction', -description='Create an XML request for CIM Authorization and Capture transaction.',
-namespace='arze_',
-required='trans_elements', -type=map,
-encodenone,
-priority='replace');
local('xmlreq' = string);
// get customer profile
#xmlreq += '<?xml version="1.0" encoding="utf-8"?>';
#xmlreq += '<createCustomerProfileTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">';
#xmlreq += arze_merchantblock;
#xmlreq += '<transaction><profileTransAuthCapture><amount>'+#trans_elements->find('amount')+'</amount>
<customerProfileId>'+#trans_elements->find('customerProfileId')+'</customerProfileId>
<customerPaymentProfileId>'+#trans_elements->find('customerPaymentProfileId')+'</customerPaymentProfileId>
<order><invoiceNumber>'+#trans_elements->find('invoiceNumber')+'</invoiceNumber></order>
</profileTransAuthCapture>
</transaction>';
#xmlreq += '</createCustomerProfileTransactionRequest> ';
return(arze_xmlrequest(-xmlreq=#xmlreq));
/define_tag;
//------------------------------------------------------------------
// Get Payment (transaction) Profile
//------------------------------------------------------------------
define_tag('getCustomerPaymentProfileRequest', -description='Create an XML request to get the customer payment profile',
-namespace='arze_',
-required='trans_elements', -type=map,
-encodenone,
-priority='replace');
local('xmlreq' = string);
// get customer profile
#xmlreq += '<?xml version="1.0" encoding="utf-8"?>';
#xmlreq += '<getCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">';
#xmlreq += arze_merchantblock;
#xmlreq += '<customerProfileId>'+#trans_elements->find('customerProfileId')+'</customerProfileId>
<customerPaymentProfileId>'+#trans_elements->find('customerPaymentProfileId')+'</customerPaymentProfileId>';
// #xmlreq += arze_modeblock;
#xmlreq += '</getCustomerPaymentProfileRequest>';
return(arze_xmlrequest(-xmlreq=#xmlreq));
/define_tag;
]
----------- END CIM CODE TO INCLUDE --------------------