I wanted to be able to capture the post-order event so I can enter the information into Authorize.Net's Customer Information Manager. This is what I ended up with:
public override void Init()
{
// Assigns a handler to the Insert.After event for the Ecommerce object type
// This event occurs after the creation of every new order
CMS.Ecommerce.OrderInfo.TYPEINFO.Events.Insert.After += Insert_After;
}
void Insert_After(object sender, ObjectEventArgs e)
{
AuthorizeNet.CustomerGateway gateway = new CustomerGateway("", "", ServiceMode.Test);
CMS.Ecommerce.OrderInfo orderInfo = (CMS.Ecommerce.OrderInfo)sender;
int userID = orderInfo.OrderCompletedByUserID;
CMS.Membership.UserInfo Ui = (CMS.Membership.UserInfo)CMS.Membership.UserRoleInfoProvider.GetInfoById(MembershipInfo.OBJECT_TYPE, userID);
AuthorizeNet.Customer customer = gateway.GetCustomer(Ui.GetCIMid().ToString());
if (customer == null)
{
// creating the profile, we add billing address, shipping address
customer = gateway.CreateCustomer(Ui.Email, "Auto created " + DateTime.Now.ToString("MMM dd yyyy HH:mm:ss"));
customer.ID = userID.ToString();
AuthorizeNet.Address shipping = new AuthorizeNet.Address();
shipping.City = orderInfo.OrderShippingAddress.AddressCity;
CMS.Globalization.CountryInfo ciShipping = CMS.Globalization.CountryInfoProvider.GetCountryInfo(orderInfo.OrderShippingAddress.AddressCountryID);
shipping.Country = ciShipping.CountryDisplayName;
shipping.Street = orderInfo.OrderShippingAddress.AddressLine1 + ", " + orderInfo.OrderShippingAddress.AddressLine2;
shipping.Zip = orderInfo.OrderShippingAddress.AddressZip;
List<AuthorizeNet.Address> sAddys = new List<AuthorizeNet.Address>();
sAddys.Add(shipping);
customer.ShippingAddresses = sAddys;
AuthorizeNet.Address billing = new AuthorizeNet.Address();
billing.City = orderInfo.OrderBillingAddress.AddressCity;
CMS.Globalization.CountryInfo ciBilling = CMS.Globalization.CountryInfoProvider.GetCountryInfo(orderInfo.OrderBillingAddress.AddressCountryID);
billing.Country = ciBilling.CountryDisplayName;
billing.Street = orderInfo.OrderBillingAddress.AddressLine1 + "," + orderInfo.OrderBillingAddress.AddressLine2;
StateInfo si = StateInfoProvider.GetStateInfo(orderInfo.OrderBillingAddress.AddressStateID);
billing.State = si.StateDisplayName;
billing.Zip = orderInfo.OrderBillingAddress.AddressZip;
customer.BillingAddress = billing;
gateway.UpdateCustomer(customer);
}
}