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

IBillIt Shopping Cart Sample Code: .NET VB Script

IBillIt .NET VB

(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 IBillIt object. The code looks like this:

' Create the BillIt object and set login credentials
Dim oBillIt As ITDevWorks.BillIt.BillIt = New ITDevWorks.BillIt.BillIt()
oBillIt.MerchantId = "xxxxxxxxxxxxxxx"
oBillIt.TransactionKey = "xxxxxxxxxxxxxxx"
' Submit the actual payment
Dim oResp As ITDevWorks.BillIt.Response = _
    oBillIt.SubmitCreditCardPayment(249.99, "4111111111111111", _
        Date.Parse("12/31/2010"), "111")

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

Const AUTHNET_API_LOGIN As String = ""
Const AUTHNET_TRANSACTION_KEY As String = ""
Function MakePayment() As ITDevWorks.BillIt.Response
    '
    ' Create the BillIt object
    '
    Dim oBillit As ITDevWorks.BillIt.BillIt = New BillIt()
    '
    ' Set the login credentials
    '
    oBillit.MerchantId = AUTHNET_API_LOGIN
    oBillit.TransactionKey = AUTHNET_TRANSACTION_KEY
    '
    ' Create the Payment object
    '
    Dim pmt As ITDevWorks.BillIt.Payment = oBillit.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 Megapixel digital camera", 1, 249.99, False)
    pmt.OrderLineItems.Add("ITM0395", "Camera Carry Bag", _
        "Nylon camera carrying case", 1, 49.99, False)
    pmt.OrderLineItems.Add("ITM9655", "AA Btry 4-pack", _
        "Package of 4 AA Alkaline batteries", 4, 3.99, False)
    '
    ' Add the shipping costs for each item
    '
    pmt.Freight.Add(7.99, "Digital camera S&H", String.Empty)
    pmt.Freight.Add(3.99, "Camera carrying case S&H", String.Empty)
    pmt.Freight.Add(4.99, "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
    '
    MakePayment = pmt.Submit()
End Function

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.