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:
AuthorizeRequest.Login = "myLogin";
AuthorizeRequest.Password = "MyPassword";
AuthorizeRequest.TransactionKey = "whatever";
AuthorizeRequest.Operation = AuthorizeRequest.Type.AUTH_CAPTURE;
AuthorizeRequest.TransactionType = AuthorizeRequest.Method.CC;
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";
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));
request.Freight = 9.95;
request.Amount = (Decimal)(19.95 + 9.95 + 9.95);
AuthorizeResponse response = AuthoriseTransaction.SendRequest(request);
if (response.TransactionResult != AuthorizeResponse.Result.Approved)
{
}
else
{
}
}
History
- 11th April, 2008: Version 1.0 - Initial release
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.