Authorize.net Instructions

You can download the Authorize.net class here.

The Authorize.net Class is used to interact with Authorize.net in order to authorize and capture funds off of a credit card. In order to use the Authorize.net service you have to sign up for an account on at Authorize.net. In order to use this class correctly you have to have the API Login and Transaction Key for your account.


The first thing you have to do to use the class is to set your API Login and Transaction Key into the constant values in the class. You can find these values on lines 23 and 24 of the class. Line 25 is a Boolean value weather you want to use the live server or the development system. By default it is set to the development environment. To move to the live environment simply change the value from false to true.

Create New Authorization

Creating an authorization requests the right to take funds from a credit card at a later point. This is ideal for e-Commerce applications as you are not supposed to take money from the customer until you know you are going to ship the order. Authorizations are generally good for 30 days. After 30 days you can no longer capture funds based on the authorization. In order to create the authorization you call the authorize method of the class with the following paramaters:

$authorizenet = new AuthorizeNetAIM();

$authorizenet->authorize($amount, $cc_number, $cvv, $expire, $first_name, $last_name, $address, $city, $state, $zip, $country);

Variable Description

$amount (required): The dollar amount you want to authorize

$cc_number (required): The credit card number you want to authorize funds against

$cvv (required): The Credit Card Verification Number that is found on the back of most credit cards. This number is usually 3 digits, but is 4 digits for American Express

$expire (required): The expiration date of the credit card. For best results it should be in the format of MMYY or MMYYYY.

$first_name (required): The first name of the card holder

$last_name (required): The last name of the card holder

$address (optional): The street address of the card holder

$city (optional): The city of the card holder

$state (optional): State abbreviation of the card holder

$zip (optional): The zip code of the card holder

$country (optional): The country of the card holder

It should be noted that while many of these paramaters are optional, based on your Authorize.net account it could effect the outcome of your authorization.

Create Authorization and Capture All At Once

This is generally called “Auth Capture” as it creates an authorization and captures the funds immediately. This is best suited for situations where the customer receives their good or services right up front (a brick and morter store, or a consulting services). It works exactly the same as a regular authorization with regards to the paramaters it takes in. Here is the syntax:

$authorizenet = new AuthorizeNetAIM();

$authorizenet->authorize_capture($amount, $cc_number, $cvv, $expire, $first_name, $last_name, $address, $city, $state, $zip, $country);

(See above for description of parameters and if they are required or optional)

Capture Funds

Capture funds is used to actually take money from a credit card based on a previous authorization. Here is the syntax:

$authorizenet = new AuthorizeNetAIM();

$authorizenet->capture($amount, $transaction_id, $authorization_number, $cc_number, $expire);

Variable Description

$amount (required): The amount you want to capture. This value cannot be higher than the amount you requested from the initial authorization

$transaction_id (required): The transaction ID that Authorize.net gave you when you created your initial authorization

$authorization_number (required): The authorization number that Authorize.net gave you when you created your initial authorization

$cc_number (required): The credit card number that you created the initial authorization with

$expire (required): The expiration date of the credit card

Issue Credit

Credit is used to credit funds back onto a credit card. You must have an open authorization on the card to be able to credit funds back to a credit card. You call the function with the following syntax:

$authorizenet = new AuthorizeNetAIM();

$authorizenet->credit($amount, $cc_number, $cc_expire, $trans_id)

Variable Description

$amount (required): The amount of money you want to credit back to the account

$cc_number (required): The credit card number

$cc_expire (required): The credit card expiration number

$trans_id (required): The transaction ID from the initial authorization

Void Authorization

Void authorization is used when you no longer want to interact with Authorize.net using a specific authorization. This would be used if a customer cancels their order. To void an authorization use the following syntax:

$authorizenet = new AuthorizeNetAIM();

$authorizenet->void_authorization($trans_id);

Variable Description

$trans_id (required): The transaction ID from the original authorization

Function Response

Each one of the methods of this class return a specifically designed array that will give you all the information for the results. When running the functons simply do a print_r on the result to see the results. Here are the results that come back from Authorize.net

response_code, response_subcode, ‘response_reason_code, response_reason_text, authorization_code, avs_response, transaction_id, invoice_number, description, amount, method, transaction_type, customer_id, first_name, last_name, company

If you have any questions please post a comment or contact me.

Leave a Reply