Select Page

 

Recently we started working on a new .Net project for selling services on a website. Obviously the question about build vs. buy came about and we decided to build due to some of the not so common requirements for the client.  One of the requirements for the clients was for us to use Authorize.Net for processing all credit transactions. Having never worked with Authorize.Net before, we were very apprehensive about the request. As we read the documentation, we realized that it may not be so hard after all.

Although Authorize.Net provides a bunch of examples, surprisingly they don’t have examples of the most easy method to work with their AIM (Advanced Integrated Method). We found this to be quite surprising and also wasted a lot of time trying to find an easy way to work with other ways.  Follow this 2 post series to get a head start on working with Authorize.Net AIM libraries.

 

Communicating with Authorize.Net using AIM

It is very easy to setup your communication with Authorize.Net. All you need are your API Login ID and Transaction Key. You can get a test version of these from the following link: http://developer.authorize.net/.

After you have referenced Authorize.Net in your code behind file, the method to instantiate your gateway:  Gateway(string apiLogin, string transactionKey, bool testMode)

/*apiLogin: 8 character string provided by Authorize.Net*/
string apiLogin = “7Agv6yt7”;
/*transactionKey: 16 character string provided by Authorize.Net*/
string transactionKey = “9A8CaB6584nhFgS8”;
var gate = new Gateway(apiLogin, transactionKey, true);

 

When Test Mode is set to true, all your transactions are executed against a test server. This enables you to run a series of tests without any financial implication. Obviously for Production requests you would send false for Test Mode.

Credit Card transactions can be processed in one of 2 ways:

  1. Card Present which means you will be able to send the credit card track data to Authorize.Net. Credit Card track data is the data that is stored on the back of your credit card on the magnetic stripe. You can use Google to find ways for reading the track data from a credit card.
  2. Card Not Present which means that the user is providing you the credit card number with expiration number. This is the way you would process transactions on your site.

Obviously, you can write an application that supports both formats which is what we ended up doing due to our requirements.

There are 5 types of transactions you can run when processing credit cards-

  1. Purchase: The user purchases a product on your site. The transaction is immediately billed to their credit card
  2. Reservation: This type of transaction is used when the user is requesting a service for a future time and the seller doesn’t want to process the actual payment until the day of the service. An example would be car reservations where they may place an Authorization on the card but no payment is processed at the time of reservation.
  3. Complete Purchase on Reservation: This is the second step of a Reservation. When the seller is ready to capture and receive payment for a service, you can process the payment with the credit card issuer.
  4. Void Purchase: This type is used to void a transaction that was processed on the same day.
  5. Refund: This type of transaction is applicable when the settlement event has already been settled by Authorize.net and a payment has been issued to your bank account. At this time the transaction cannot be Voided and will have to be Refunded.

We’ll try to provide you examples for each of the transactions here. In this post, we will be presenting to you all the Card Present examples.

Purchase

In this transaction, you will need the Amount to be processed along with Track1 and Track2 data from the Credit Card.

//step 1 - create the gateway, sending in your credentials
var gate = new Gateway(authorizeNetLogin, authorizeNetTransactionKey, true);
//Step 2 - create the Purchase Request with the transaction Amount, Track 1 and Track 2 data.
var request = new CardPresentAuthorizeAndCaptureRequest(Amount, track1, track2);
//Step 3 – Process the transaction with Authorize.Net
var response = gate.Send(request);

Reservation

In this transaction, you will again need the Amount to be processed along with Track1 and Track2 data from the Credit Card.

/step 1 - create the gateway, sending in your credentials
var gate = new Gateway(authorizeNetLogin, authorizeNetTransactionKey, true);
//Step 2 - create the Authorization Request with the transaction Amount, Track 1 and Track 2 data. 
var request = new CardPresentAuthorizationRequest(Amount, track1, track2);
//Step 3 – Process the transaction with Authorize.Net
var response = gate.Send(request);

Complete Purchase on Reservation

In this transaction you will need the Transaction Id of the previously authorized ‘AuthorizationRequest’ Transaction along with the Amount.

//step 1 - create the gateway, sending in your credentials
var gate = new Gateway(authorizeNetLogin, authorizeNetTransactionKey, true);
//Step 2 - create the Authorization Request with the transaction Amount, Track 1 and Track 2 data.
var request = new CardPresentPriorAuthCapture(transactionID, Amount);
//Step 3 – Process the transaction with Authorize.Net
var response = gate.Send(request);

Void Purchase

In this transaction you will need the Transaction Id of the previously approved Transaction.

//step 1 - create the gateway, sending in your credentials
var gate = new Gateway(authorizeNetLogin, authorizeNetTransactionKey, true);
//Step 2 - create the Void Request for the requested TransactionId
var myRefundRequest = new CardPresentVoid(transactionID);
//Step 3 – Process the transaction with Authorize.Net
var response = gate.Send(myRefundRequest);

Refund

Refunds with Authorize.Net turned out to be little tricky. Depending on your settings for settlement (time of day when Authorize.Net sends you money for your transactions for the day), your Refund could actually be considered a ‘Void’. If you are trying to Refund prior to settlement, it is considered a ‘Void’ and needs to be requested as a ‘Void’ but if it after ‘Settlement’ it should be requested as a proper Refund.

For a Refund transaction, you will need the Transaction Id, Amount and Credit Card Number used for the original transaction.

//step 1 - create the gateway, sending in your credentials
var gate = new Gateway(authorizeNetLogin, authorizeNetTransactionKey, true); 
//Step 2 - create the Void Request for the requested TransactionId 
var myCreditRequest = new CardPresentCredit(transactionID);
//Step 3 – Process the transaction with Authorize.Net
var response = gate.Send(myCreditRequest);

Please check back shortly for Card Not Present examples.