Summary

Use this CFC to easily create, update, cancel recurring billing subscriptions at Authorize.Net.

Requires

Usage

Since these methods take so many arguments, I typically use the <cfinvoke> tag, rather than using cfscript syntax. Take a look at the introspection output to see all the possible attributes and what the defaults are.

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.

First, initalize the object, passing in your Authorize.net loginname and transaction key. Also you need to pass in the "mode", which can be either "live" or "test". The default is "test" if no mode is specified. When in test mode, calls are made to Authorize.Net's test server.

			
<cfset PaymentGateway = CreateObject("component","AuthorizeNetRecurring").init(
	loginname = "YourLoginName"",
	transactionKey = "YourTransactionKey",
	mode = "test")>
		

Then call your desired method. Looking through Authorize.Net's documentation on their recurring billing API will help you better see what attributes are required for each type of transaction (create, update and cancel).

<cfinvoke component="#PaymentGateway#" method="createSubscription" returnvariable="result">
	<!--- to allow for a 1 month trial, set startDate to be 1 month from today.
	If ommitted, the default value is today --->
	<cfinvokeargument name="startDate" value="#DateFormat(DateAdd("m",1,Now()),"yyyy-mm-dd")#">
	<cfinvokeargument name="customerEmail" value="#Session.signup.email#">
	<cfinvokeargument name="billFirstName" value="#Form.ccfname#">
	<cfinvokeargument name="billLastName" value="#Form.cclname#">
	<cfinvokeargument name="billAddress" value="#Form.ccAddress#">
	<cfinvokeargument name="billCity" value="#Form.ccCity#">
	<cfinvokeargument name="billState" value="#Form.ccstate#">
	<cfinvokeargument name="billZip" value="#Form.cczip#">
	<cfinvokeargument name="shipFirstName" value="#Session.signup.FirstName#">
	<cfinvokeargument name="shipLastName" value="#Session.signup.LastName#">
	<cfinvokeargument name="shipAddress" value="#tmpAddress#">
	<cfinvokeargument name="shipCity" value="#Session.signup.City#">
	<cfinvokeargument name="shipState" value="#Session.signup.State#">
	<cfinvokeargument name="shipZip" value="#Session.signup.Zip#">

	<cfinvokeargument name="amount" value="#cfg_RetailPrice#">
	<cfinvokeargument name="subscriptionName" value="Monthly Subscription">
	<cfinvokeargument name="orderDescription" value="#tmpSignupCode#">
	<cfinvokeargument name="totalOccurrences" value="36">
	<cfinvokeargument name="cardNumber" value="#Form.ccnum#">
	<cfinvokeargument name="expirationDate" value="#Form.ccexpyr#-#Form.ccexpmo#">
	
	<--- first year is at lower rate --->
	<cfinvokeargument name="trialAmount" value="#cfg_12moPrice#">
	<cfinvokeargument name="trialOccurrences" value="12">
</cfinvoke>
		

When updating, the only required attribute is the subcriptionId. Pass in whatever else you'd like to modify. There are rules about modifying payment terms after the first charge has been made, see the Authorize.Net documentation for details.

<cfinvoke component="#PaymentGateway#" method="updateSubscription" returnvariable="result">
	<cfinvokeargument name="subscriptionId" value="234322">
	<cfinvokeargument name="customerEmail" value="Bob123@hotmail.com">
	<cfinvokeargument name="shipFirstName" value="Robbert">
</cfinvoke>

To cancel, just pass in the subscriptionId.

<cfinvoke component="#PaymentGateway#" method="cancelSubscription" returnvariable="result">
	<cfinvokeargument name="subscriptionId" value="234322">
</cfinvoke>

This code is fairly young, so if you encounter any issues please let me know about it and I'll see what I can do.