CyberSource ColdFusion Solution

I have received this question so many times via email I decided to post a blog entry for it. CyberSource is a payment solution I have used in the past for a product called Bill Me Later but it can be used for a number of other solutions as well.

Here are the instructions for setting this payment solution up.

1. Download the Simple Order API (32-bit). I installed the Windows Java version.

2. Modify your jvm.config file. This depends on what version of ColdFusion you are using. Also, you will need to edit this file manually because the CyberSource arguments need to appear first. Do not edit the JVM arguments in the ColdFusion administrator because it will add them to the end which will not work.

ColdFusion MX 6.x

Notice that the following line below has been commented out because it interferes with the CyberSource JVM arguments.

#-Djavax.xml.parsers.SAXParserFactory=com.macromedia.crimson.jaxp.SAXParserFactoryImpl -Djavax.xml.parsers.DocumentBuilderFactory=com.macromedia.crimson.jaxp.DocumentBuilderFactoryImpl

#
# VM configuration
#
# Where to find JVM, if {java.home}/jre exists then that JVM is used
# if not then it must be the path to the JRE itself
java.home=D:/CFusionMX/runtime/jre
#
# If no java.home is specified a VM is located by looking in these places in this
# order:
#
# 1) bin directory for java.dll (windows) or lib/<ARCH>/libjava.so (unix)
# 2) ../jre
# 3) registry (windows only)
# 4) JAVA_HOME env var plus jre (ie $JAVA_HOME/jre)
#

# Arguments to VM
java.args=-server -DJINTEGRA_NATIVE_MODE -DJINTEGRA_PREFETCH_ENUMS -Xms256m -Xmx512m -Dsun.io.useCanonCaches=false -Xbootclasspath/a:"{application.home}/../lib/webchartsJava2D.jar" -XX:MaxPermSize=128m -XX:+UseParallelGC
#-Djavax.xml.parsers.SAXParserFactory=com.macromedia.crimson.jaxp.SAXParserFactoryImpl -Djavax.xml.parsers.DocumentBuilderFactory=com.macromedia.crimson.jaxp.DocumentBuilderFactoryImpl

#
# commas will be converted to platform specific separator and the result will be passed
# as -Djava.ext.dirs= to the VM
java.ext.dirs={jre.home}/lib/ext

#
# where to find shared libraries
java.library.path={application.home}/../lib,{application.home}/../jintegra/bin,{application.home}/../jintegra/bin/international,{application.home}/../lib/_nti40/bin
system.path.first=false

# JVM classpath
java.class.path=E:/WEBROOT/simapi-2.0.0/lib/cybsclients.jar,E:/WEBROOT/simapi-2.0.0/lib/cybssecurity.jar,E:/WEBROOT/simapi-2.0.0/lib/xalan.jar,E:/WEBROOT/simapi-2.0.0/lib/xercesImpl.jar,E:/WEBROOT/simapi-2.0.0/lib/xml-apis.jar,{application.home}/servers/lib,{application.home}/../lib/cfusion.jar,{application.home}/../lib,{application.home}/../runtime/lib/jrun.jar,{application.home}/../runtime/lib

ColdFusion MX 7.x

#
# VM configuration
#
# Where to find JVM, if {java.home}/jre exists then that JVM is used
# if not then it must be the path to the JRE itself
java.home=C:/CFusionMX7/runtime/jre
#
# If no java.home is specified a VM is located by looking in these places in this
# order:
#
# 1) bin directory for java.dll (windows) or lib/<ARCH>/libjava.so (unix)
# 2) ../jre
# 3) registry (windows only)
# 4) JAVA_HOME env var plus jre (ie $JAVA_HOME/jre)
#

# Arguments to VM
java.args=-server -DJINTEGRA_NATIVE_MODE -DJINTEGRA_PREFETCH_ENUMS -Xms256m -Xmx512m -Dsun.io.useCanonCaches=false -XX:MaxPermSize=128m -Dcoldfusion.rootDir={application.home}/../ -Dcoldfusion.libPath={application.home}/../lib -XX:+UseParallelGC -Dcoldfusion.classPath={application.home}/../../classes,{application.home}/../lib/updates,{application.home}/../lib/,{application.home}/../gateway/lib/,{application.home}/../wwwroot/WEB-INF/cfform/jars,C:/CFusionMX7/wwwroot/WEB-INF/classes,C:/CFusionMX7/wwwroot/WEB-INF/classes/VeriSign.jar

#
# commas will be converted to platform specific separator and the result will be passed
# as -Djava.ext.dirs= to the VM
java.ext.dirs={jre.home}/lib/ext

#
# where to find shared libraries
java.library.path={application.home}/../lib,{application.home}/../jintegra/bin,{application.home}/../jintegra/bin/international
system.path.first=false

#
# set the current working directory - useful for Windows to control
# the default search path used when loading DLLs since it comes
# before system directory, windows directory and PATH
java.user.dir={application.home}/../../lib

# JVM classpath
#java.class.path={application.home}/servers/lib,{application.home}/../lib/macromedia_drivers.jar,{application.home}/lib/cfmx_mbean.jar,{application.home}/lib
java.class.path=C:/WEBROOT/simapi-2.0.0/lib/cybsclients.jar,C:/WEBROOT/simapi-2.0.0/lib/cybssecurity.jar,C:/WEBROOT/simapi-2.0.0/lib/xalan.jar,C:/WEBROOT/simapi-2.0.0/lib/xercesImpl.jar,C:/WEBROOT/simapi-2.0.0/lib/xml-apis.jar,{application.home}/servers/lib,{application.home}/../lib/macromedia_drivers.jar,{application.home}/lib/cfmx_mbean.jar,{application.home}/lib

3. Restart ColdFusion

4. Run the following test script.

<cfobject type="java" name="oClient" class="com.cybersource.ws.client.Client" action="create">
<cfobject type="java" name="oClientProperties" class="java.util.Properties" action="create">
<cfobject type="java" name="oRequestProperties" class="java.util.Properties" action="create">
<cfobject type="java" name="oHashMapResponse" class="java.util.HashMap" action="create">

<cfscript>
   oClientProperties.setProperty("merchantID", "your merchant id");
   oClientProperties.setProperty("targetAPIVersion", "1.7");
   oClientProperties.setProperty("keysDirectory", "E:/WEBROOT/simapi-2.0.0/keys");
   oClientProperties.setProperty("sendToProduction", "false");
   oClientProperties.setProperty("enableLog", "true");
   oClientProperties.setProperty("logDirectory", "E:/WEBROOT/simapi-2.0.0/logs");
   oClientProperties.setProperty("logMaximumSize", "10");
   
   oRequestProperties.setProperty( "ccAuthService_run", "true" );
   oRequestProperties.setProperty( "merchantReferenceCode", "10000" );
   oRequestProperties.setProperty( "billTo_firstName", "John" );
   oRequestProperties.setProperty( "billTo_lastName", "Doe" );
   oRequestProperties.setProperty( "billTo_street1", "1295 Charleston Road" );
   oRequestProperties.setProperty( "billTo_city", "Mountain View" );
   oRequestProperties.setProperty( "billTo_state", "CA" );
   oRequestProperties.setProperty( "billTo_postalCode", "94043" );
   oRequestProperties.setProperty( "billTo_country", "US" );
   oRequestProperties.setProperty( "billTo_email", "nobody@cybersource.com" );
   oRequestProperties.setProperty( "billTo_ipAddress", "10.7.7.7" );
   oRequestProperties.setProperty( "billTo_phoneNumber", "650-965-6000" );
   oRequestProperties.setProperty( "shipTo_firstName", "Jane" );
   oRequestProperties.setProperty( "shipTo_lastName", "Doe" );
   oRequestProperties.setProperty( "shipTo_street1", "100 Elm Street" );
   oRequestProperties.setProperty( "shipTo_city", "San Mateo" );
   oRequestProperties.setProperty( "shipTo_state", "CA" );
   oRequestProperties.setProperty( "shipTo_postalCode", "94401" );
   oRequestProperties.setProperty( "shipTo_country", "US" );
   oRequestProperties.setProperty( "card_accountNumber", "4111111111111111" );
   oRequestProperties.setProperty( "card_expirationMonth", "12" );
   oRequestProperties.setProperty( "card_expirationYear", "2021" );
   oRequestProperties.setProperty( "purchaseTotals_currency", "USD" );
   oRequestProperties.setProperty( "purchaseTotals_grandTotalAmount", "56.78" );
   
   try {
      oHashMapResponse = oClient.runTransaction(oRequestProperties, oClientProperties);   
      if (oHashMapResponse.get("decision") EQ "ACCEPT")
         requestID = oHashMapResponse.get("requestID");
   } // try
   // do some error handling, probably need a couple-three catches    catch ("com.cybersource.ws.client.ClientException" e) {
      writeoutput("#e.getLogString()#");
   } // catch client exception    catch ("com.cybersource.ws.client.FaultException" e) {
      writeoutput("#e.getLogString()#");
   } // catch client exception    
   //oHashMapResponse = oClient.runTransaction(oRequestProperties, oClientProperties);    
</cfscript>

<cfdump var="#oHashMapResponse#">

That should be it. Also make sure you set the following directories to your specific path.

keysDirectory
logDirectory

Comments
Jean Moniatte's Gravatar Hello,

thanks a lot for publishing your findings. I am testing this with CF8 and cannot get pass this exception:

The cause of this exception was that: java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to org.apache.xml.dtm.DTMManager.

Any idea on how what I might be doing wrong?

Thanks,
# Posted By Jean Moniatte | 8/10/07 5:24 PM
Jean Moniatte's Gravatar Not adding xalan.jar to the class path fixed the issue.

Thanks again for having publishing this here.
# Posted By Jean Moniatte | 8/10/07 7:01 PM
Dave Cordes's Gravatar Jean,
No problem. I've gotten so many requests for it I decided to blog on it so I'm glad you found it useful.
# Posted By Dave Cordes | 9/27/07 11:44 PM
# Posted By krosafcheg | 10/18/07 11:00 PM
Jason's Gravatar Just wanted to say thank you, no one seemd to have these answers, certainly not Cybersource. ty ty ty
# Posted By Jason | 5/8/08 9:09 AM
poplop's Gravatar http://ru-t.com/about antimaulnetizm
&#1072;&#1085;&#1090;&#1080;&#1084;
&#1072;&#1091;&#1083;&#1085;&#1077;&#1090;&#1080;&#1079;&#1084;
# Posted By poplop | 6/4/08 5:28 AM
Steve Palmer's Gravatar Thank you for this great information. Saved me a lot of time. As someone else commented earlier, with ColdFusion 8 I was able to leave out the explicit path to xalan.jar (apparently the one in the CF\lib directory is compatible) however the other two jar files that are already in the CF\lib directory (xercesImpl.jar and xml-apis.jar) do not seem to work even though they have a newer date stamp. You must use the ones provided with the API for some reason. The files are exactly the same size, which made me think they might be the same code, but apparently not. I'm a little reluctant to point the CF class path to the older files for fear it might mess up something else. Any comments are appreciated.
# Posted By Steve Palmer | 6/24/08 4:14 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.