Authorize.net recurring billing API CFC
A few weeks ago I had to interface to Authorize.net’s recurring billing API. This is a new API they released early this year. Prior to this, if you wanted a recurring billing subscription setup, you had to log into their site and set it up manually.
When I went to begin coding I searched high and low for an existing custom tag or cfc, but did not find any. So now that mine is complete, I’ve posted it on RiaForge.
ColdFusion CFC for Authorize.net recurring billing API
There is a README file in the zip archive that has fairly detailed instructions, but here are the basics:
There are three methods: createSubscription(), updateSubscription(), and cancelSubscription().
First you must init the cfc, passing in your loginname, transaction key, and the mode which should be either “live” or “test”. When in test mode, requests are posted to Authorize.net’s special test server.
<cfset PaymentGateway = CreateObject("component","AuthorizeNetRecurring").init(
loginname = "AuthNetLoginName",
transactionKey = "YourTransactionKey",
mode = "live or test")>
<cfinvoke component="#PaymentGateway#" method="createSubscription" returnvariable="result">
<cfinvokeargument name="startDate" value="#DateFormat(Now(),"yyyy-mm-dd")#">
<cfinvokeargument name="customerEmail" value="#email#">
etc....
</cfinvoke>
Each method returns a structure containing the following keys:
| Key | Description |
| error | true or false. This is set internally based on what was returned from Authorize.net. Use this to see if the transaction was processed or not. |
| messagecode | Alpha-numeric code returned from Authorize.net. |
| messagetext | Message text returned from Authorize.net. Usually fairly descriptive. i.e. “The subscription cannot be found.” |
| resultcode | Usually something like “ok” or “error”. |
| returnedXml | The actual XML returned from Authorize.Net. Useful for debugging or detailed logging. |
You can download the Authorize.net recurring billing CFC from RIAForge.
And a “thanks” to my employer, CF WebTools for allowing me to give away this code.
September 11th, 2007 at 1:10 pm
Thanks for doing this. We have been using CF and Authorize for many years to do regular payments and credits.
We just recently started using Authorize for subscriptions so this will be great for integration.
November 30th, 2007 at 4:09 pm
FYI: If your web server runs on Windows, my company just released a library for Authorize.Net’s recurring billing. It was built in C# on the .NET platform and you can call it as a COM or .NET object (note: if you want to call it through .NET, I believe you need CF8). It supports both AIM and ARB and is fully certified by Authorize.net.
We provide extensive documentation and code samples to aid users. It does cost $99, but that’s pretty cheap for the functionality it provides. It even has extras like line totaling, supporting MD5 Hash validation (for AIM payments), copying the billing to the shipping address, etc.
You can get more information at https://www.itdevworks.com/faq.aspx and download a trial version or the documentation from our site.
Dave Parker
IT DevWorks, LLC
http://www.itdevworks.com
January 22nd, 2008 at 5:18 pm
Ryan, is it ok if we use this code in cfpayment with credits? http://cfpayment.riaforge.org.
January 22nd, 2008 at 5:41 pm
Yes you sure can. I meant to contact that project and point them to my cfc, but I forgot.
February 3rd, 2008 at 3:25 pm
Thanks ryan for the great informations and for the download-page.
Many thanks from Germany, Werbeagentur
February 5th, 2008 at 8:08 pm
You rock! ‘Nuff said.
March 7th, 2008 at 1:19 am
Again, a great Post!
June 10th, 2008 at 8:50 am
cool! thanks! go on!!