I have seen many shopping carts on the web that make thousands of dollars a month just processing your e-commerce transactions. Now you too can cut out the middleman and save a few bucks or build your own processor and make a few bucks. This example uses Authorize.net's AIM implementation. In order for the following code to work correctly you must have a few things:
Once you have obtained a Authorize.net Merchant Account and a unique transaction key you can begin, although you will need a secure directory to be able to use there gateway. Now lets start with the application.
Collecting the Data:
I will assume that most of you know how to create a form to collect the data
from the user so I will not go into detail about this section. (Please note
that this does not provide any sort of data validation. You will need to
include some sort of validation on your production site)
Form Collection Page:
customer.cfm
| <html> <head> <title>Enter Your Information</title> </head> <body> <form method="POST" action="credit.cfm"> <p> Name:<br> <input type="text" name="x_FirstName" size="20"><input type="text" name="x_LastName" size="20"></p> <p>Company:<br> <input type="text" name="x_Company" size="43"></p> <p>Address:<br> <input type="text" name="x_Address" size="43"><br> </p> <p>City:<br> <input type="text" name="x_City" size="20"></p> <p>State:<br> <input type="text" name="x_State" size="20"></p> <p>Country:<br> <input type="text" name="x_Country" size="20"></p> <p>Phone Number:<br> <input type="text" name="x_PhoneNumber" size="20"></p> <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> |
Collecting Credit Card Info:
Nothing special about this page. Just notice that we change the form
fields into session variables using a loop. (Please note that this does
not provide any sort of data validation. You will need to include some
sort of validation on your production site)
Form Collection Page:
credit.cfm
| <!--- Change form fields
into session variables ---> <cfloop collection="#form#" item="var"> <cfif var contains "x_"> <cfset "session.#var#"="#evaluate('form.' & var)#"> </cfif> </cfloop>
|
Charging the Credit Card:
Here is the meat and potatoes of this application. For organization
purposes I placed the card charge code in an include (find that code in the next
section). First notice the form to session loop like on the page before.
Once the information has been recorded we begin the charge request.
Form Collection Page:
charge.cfm
| <!--- Change form fields
into session variables ---> <cfloop collection="#form#" item="var"> <cfif var contains "x_"> <cfset "session.#var#"="#evaluate('form.' & var)#"> </cfif> </cfloop> <!---
-------------------------------------------------------------------------------------------------------------
Handles Charging --------------------------------------- ---> <html> <!---
-------------------------------------------------------------------------------------------------------------
Handles Response Codes --------------------------------------- ---> |
Charging the Credit Card Include:
For a complete list of all the available fields you can submit to
Authorize.net check out the following link:
http://www.authorize.net/support/AIM_guide.pdf. I have chosen to show
you the most basic type of response. You will want to build on this as
this is by no means a complete application. If you have questions on how
to add more fields please email me at
IvanS@CoastalMalls.com.
Form Collection Page:
charge.cfm
| <!--- First lets get out Merchant Account
User ID, Transaction Key and Amount ---> <cfset
x_login = "[Enter your User ID Here]"> <!--- Now lets open a connection to Authorize.Net using CFHTTP ---> <cfhttp url="https://secure.authorize.net/gateway/transact.dll"
method="post"> <!--- Everything is now up to Authorize.net in processing the card. A response will be sent back to the server in a comma delimitated list. This list will tell you several things such as: If the card is approved/declined, the approval code, transaction id, and more. Use the following code to grab these values from the list ---> <cfset AuthList = "#cfhttp.FileContent#"> <cfloop index="counter" list="#authList#"
delimiters=","> <!--- You may notice that the list submitted back to you contains 69+ fields in the list. I will leave it up to you on how to grab that information from the list. ---> <!--- You may want to insert these values into a database for future use. Just grab the data from the list and insert the values just like you would any data. ---> <!--- You may also want to clear the session variable
just in case the browser decides to hit the refresh button. You can do
this using the following code: |
*** Remember ***
This is by no means a completed application, but rather a backbone for you to
build upon. If you have any questions please email me at
IvanS@CoastalMalls.com