This tutorial shows you how to integrate eCommerce API into your add-on.
Configure your Visual Studio project
- Start a Contensive addon Collection project and an addon collection that will call the API (Creating a new addon collection)
- Checkout the GitHub Release project (GitHub.com/Contensive/Release)
- Add a project reference to accountBillingApi (accountBillingApi.dll from the release project)
- The api object is class apiClass, in namespace Contensive.Addons.aoAccountBilling
Install supporting add-on collection to your application
- From the addon manager, add eCommerce - https://github.com/contensive/aoEcommerce
To get the user's account, or create a new one
- 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() - 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
- 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
- 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())
- 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