Sample code for IBillIt AIM/ARB epayment control for Authorize.net

IBillIt Shopping Cart Sample Code: C# in ASP.NET

(Note: Click to download a fully working ASP.NET 2.0 website that demonstrates different ways to leverage IBillIt on your site.)

Using IBillIt, on an ASP.NET page in Visual Basic.NET is quite simple. There are two different paths to creating a payment depending upon the needs of your site. The easy way is to use the SubmitCreditCardPayment() method of the BillIt object. The code looks like this:

// Create the Billit object and set login credentials
ITDevWorks.BillIt.BillIt billit = new ITDevWorks.BillIt.BillIt();
billit.MerchantId = "xxxxxxxxxxxxxxx";
billit.TransactionKey = "xxxxxxxxxxxxxxx";
// Submit the actual payment
ITDevWorks.BillIt.Response resp = billit.SubmitCreditCardPayment(
    249.99M, "4111111111111111", DateTime.Parse("12/31/2010"), "111");

On the other hand, to take full advantage of the features that IBillIt offers, create a Payment object, set properties on it to suit your site's needs, then call the Payment.Submit() method.

const string AUTHNET_API_LOGIN = "";
const string AUTHNET_TRANSACTION_KEY = "";
ITDevWorks.BillIt.Response MakePayment()
{
    //
    // Create the BillIt object
    //
    ITDevWorks.BillIt.BillIt billit = new BillIt();
    //
    // Set the login credentials
    //
    billit.MerchantId = AUTHNET_API_LOGIN;
    billit.TransactionKey = AUTHNET_TRANSACTION_KEY;
    //
    // Create the Payment object
    //
    ITDevWorks.BillIt.Payment pmt = billit.CreatePayment();
    //
    // This reduces the chances of getting "A duplication
    // transaction has already been submitted" responses
    // from the gateway when doing testing.
    //
    pmt.DuplicateCheckTimeout = 1;
    //
    // Add some products to the list of purchased items.
    //
    pmt.OrderLineItems.Add("ITM0496", "Digital Camera",
        "10 M-Pixel digital camera", 1, 249.99M, false);
    pmt.OrderLineItems.Add("ITM0395", "Camera Carry Bag",
        "Nylon camera carrying case", 1, 49.99M, false);
    pmt.OrderLineItems.Add("ITM9655", "AA Btry 4-pack",
        "Package of 4 AA Alkaline batteries", 4, 3.99M, false);
    //
    // Add the shipping costs for each item
    //
    pmt.Freight.Add(7.99M, "Digital camera S&H", String.Empty);
    pmt.Freight.Add(3.99M, "Camera carrying case S&H", String.Empty);
    pmt.Freight.Add(4.99M, "Batteries S&H", String.Empty);
    //
    // NOTE: The following line of code must be called.
    // The OrderLineItem, Tax, Freight, and Duty collections
    // do not automatically set the amount that will be billed.
    //
    pmt.Amount = pmt.CalculateTotalAmount(true, true, true, false);
    //
    // Set the credit card properties
    //
    pmt.CreditCardNumber = "4111111111111111";
    pmt.CreditCardExpiration = DateTime.Parse("12/31/2008");
    pmt.CreditCardCode = "111";
    //
    // Set the customer properties (optional for most payments)
    //
    pmt.CustomerBillTo.FirstName = "John";
    pmt.CustomerBillTo.LastName = "Doe";
    pmt.CustomerEmail = "";
    pmt.CustomerPhone = "";
    //
    // Submit the payment to the Authorize.Net gateway
    //
    return pmt.Submit();
}

There is no requirement to use .OrderLineItems or any of the .Tax, .Freight, or .Duty collections, but doing so can capture much more detail about transactions in your Authorize.net account. By caching the Payment object, the OrderLineItems collection can also be your in-session shopping cart data store. Every object in IBillIt supports a .UserData property, which allows you to attach any data of your own to it. For the OrderLineItems collection, you could store the CartId from your database, or even a whole object representing the persisted cart in your database.

The IBillIt control gives you the flexibility to create your own shopping cart the way you want. Use it to build a reliable e-commerce site while simplifying your development effort and shortening your time to market. To test IBillIt, try our trial version.