Click here to Skip to main content
Click here to Skip to main content

A Wrapper for Using .NET to Submit Credit Card Transactions via the Authorize Gateway

, 11 Apr 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A .NET wrapper for Authorize

Introduction

Recently, I had to write a website that processes credit card transactions, and I was shocked to find that Authorize, one of the larger payment gateways, did not provide any sort of .NET API. They support HTTP Posting of a string that defines the transaction, and they send back a string that describes the result. So, I wrote a wrapper class for use in our website, and decided to offer it here for anyone else that may need it. (It's also a good way to get peer review of code that I'm using....)

Using the Code

This is meant to be used as a library. The solution has two projects in it, one is the Authorize code as a DLL, the other is a console app that simply demonstrates how the library is used. Authorize requires three pieces of information, which are your login to their system. These are provided by static properties, then you build a request object, set its properties, add line items and then send the transaction, getting back a response which will tell you if the process succeeded or failed, and why.

One property which I didn't expose is this:

 private bool _testRequest = false; 

Setting this will alternate between using the test and live server, so I expect a user would set it to true during testing, then back for release. The Authorize docs specify several URLs for test and live server, the ones in my code were correct at the time of printing, I will obviously become aware if they change it, and endeavour to keep it up to date.

What follows is the code of my sample app, showing how the library is to be used:

    //first set the properties
    AuthorizeRequest.Login = "myLogin";
    AuthorizeRequest.Password = "MyPassword";
    AuthorizeRequest.TransactionKey = "whatever";

    // optionally set other settings
    AuthorizeRequest.Operation = AuthorizeRequest.Type.AUTH_CAPTURE;
    AuthorizeRequest.TransactionType = AuthorizeRequest.Method.CC;

    // now build the request
    AuthorizeRequest request = new AuthorizeRequest();

    request.ClientFirstName = "fred";
    request.ClientLastName = "Jones";
    request.CompanyName = "Acme";
    request.Address = "Address";
    request.City = "city";    
    request.Country = "India";

    request.CardNumber = "number";
    request.ExpDate = "12/2008";
    request.Ccv = "CCV is not used unless you set it up on the Authorize end (" +
                  " this costs extra )";
    
    request.ClientEmail = "this is for a receipt emailed by Authorize";
    request.MerchantEmail = "this is for an email sent to the merchant";

    // Now add the items to be purchased.
    request.LineItems.Add(new AuthorizeRequest.LineItem("001", "product standard", 
                                              "product standard", 1, 19.95, false));
    request.LineItems.Add(new AuthorizeRequest.LineItem("002", "product upgrade", 
                                              "product upgrade", 1, 9.95, false));

    // finally add the price
    request.Freight = 9.95;

    // Note the shipping is specified separately for invoicing purposes, but Amount is 
    // the exact amount that will be charged. This includes tax, you need to calculate 
    // it separately, if need be.
    request.Amount = (Decimal)(19.95 + 9.95 + 9.95); 

    // Now send the transaction
    AuthorizeResponse response = AuthoriseTransaction.SendRequest(request);

    if (response.TransactionResult != AuthorizeResponse.Result.Approved)
    {
        // work out what went wrong
    }
    else
    {
        // provide the transaction Id to the user
    }
}

History

  • 11th April, 2008: Version 1.0 - Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Christian Graus
Software Developer (Senior)
Australia Australia
Programming computers ( self taught ) since about 1984 when I bought my first Apple ][. Was working on a GUI library to interface Win32 to Python, and writing graphics filters in my spare time, and then building n-tiered apps using asp, atl and asp.net in my job at Dytech. After 4 years there, I've started working from home, at first for Code Project and now for a vet telemedicine company. I owned part of a company that sells client education software in the vet market, but we sold that and I worked for the owners for five years before leaving to get away from the travel, and spend more time with my family. I now work for a company here in Hobart, doing all sorts of Microsoft based stuff in C++ and C#, with a lot of T-SQL in the mix.

Comments and Discussions

 
QuestionIs it susceptible to man in the middle attack? Pinmemberzyxeasy23-Jul-10 2:00 
GeneralThanks - and a little help please. PinmemberGlen Harvy18-Jun-08 12:59 
GeneralConsumers Beware Pinmemberterphi19-May-08 12:29 
Questionreal account?? PinmemberSuperEric17-May-08 0:57 
GeneralLooks Good, but you mispelled Authorize PinmemberMember 356657113-May-08 10:56 
GeneralCool Pinmember leppie 11-Apr-08 22:47 
GeneralNice! PinmemberRavi Bhavnani11-Apr-08 19:02 
GeneralRe: Nice! PinmvpChristian Graus11-Apr-08 22:18 
GeneralNice and clean Pinmemberaxelriet11-Apr-08 15:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 11 Apr 2008
Article Copyright 2008 by Christian Graus
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid