Login

Recover Your Password

Return to Product Support > Learning Center > Developer References > Developer Tutorials > eCommerce API workflow

eCommerce API workflow

This tutorial shows you how to integrate eCommerce API into your add-on.

Configure your Visual Studio project

  1. Start a Contensive addon Collection project and an addon collection that will call the API (Creating a new addon collection)
  2. Checkout the GitHub Release project (GitHub.com/Contensive/Release)
  3. Add a project reference to accountBillingApi (accountBillingApi.dll from the release project)
  4. The api object is class apiClass, in namespace Contensive.Addons.aoAccountBilling

Install supporting add-on collection to your application

  1. From the addon manager, add eCommerce - https://github.com/contensive/aoEcommerce

To get the user's account, or create a new one

  1. Get the accountId from the user's record

    dim cs as cpcsbaseClass = cp.csNew()
    dim accountId as integer=0
    if cs.Open( "people", "id=" & cp.user.id ) then
       accountId = cs.getInteger( "accountId" )
    end if
    call cs.close()
  2. Check if the user's account is valid, if not create a new account for them

    Dim accountStatus As New apiClass.accountStatusStruct
    accountStatus = api.getAccountStatus(cp, returnUserError, accountId)
    ' accountStatus.closed is a valid account that has been closed
    ' accountStatus.currentBalance is the balance due
    ' accountStatus.exists is true if the account exists
    ' accountStatus.pastDueAmount is the past due balance
    ' returnUserError if not blank, this is a user appropriate message
    if (not accountStatus.exists) or (accountStatus.closed) then
        if cs.Open( "people", "id=" & cp.user.id ) then
            call cs.setField( "accountId", 0 )
        end if
        call cs.close()
       accountId = api.createAccount( cp.user.id, "New Account Name" )
    end if

To create an order and add an item

  1. Create the order and assign the account

    dim orderId as integer
    orderId = api.createOrder()
    call setOrderAccount( orderId, accountId )
    call addOrderItem( orderId, itemId )

Create a page with the generic online payment form and process the results

  1. Create an addon that returns the onlinePaymentFields in a form. Place it on a page with secure certificate (https:// is required)

    returnHtml = cp.html.form( api.getOnlinePaymentFields())

  2. When this form is submitted, process it

    if not api.payOrdersByOnlinePaymentFields( cp, returnUserError, orderIdList, paymentComment1, paymentComment2 ) then
        ' there was a problem with the order, a user compatible message is in returnUserError
    else
        ' the order processed correctly.
    end if

Process the order with the user's account


if not api.chargeOrder( cp, returnUserError, orderId, paymentComment1, paymentComment2 ) then
    ' there was a problem with the order, a user compatible message is in returnUserError
else
    ' the order processed correctly.
end if

Process the order with a credit card or online check (ACH)

dim method as onDemandMethodStruct
method.creditCardNumber = ""        ' card number
method.creditCardExpiration = ""     ' mm/dd/yyyy string of last day of the month the card expires
method.creditSecurityCode = ""       ' CVV code on the back of the card
if not api.payOrder( cp, returnUserError, orderId, paymentComment1, paymentComment2 ) then
    ' there was a problem with the order, a user compatible message is in returnUserError
else
    ' the order processed correctly.
end if