The power of post-purchase processing hooks in Ecommerce!

October 04, 2011 Digital Experience

We introduced a very powerful feature in Sitefinity 4.2 SP 1 that allows you to implement customized code through a post-purchase processing hook in the Ecommerce module.   A software developer can create  custom code and register the code to be called after two specific events.  The first event that can be subscribed to occurs immediately after the payment gateway returns a response.  The second event that can be subscribed to occurs after the order is placed.   You can write a custom service in either event handler or you may prefer to write one service and execute your custom code just after the order is placed.

There are endless reasons for implementing a web service after these two events.   Below are just a few ideas on how you may take advantage of this extendable and powerful new feature in Sitefinity Ecommerce.

  1. Export order information to an ERP (Oracle, SAP, QuickBooks, etc…) in any format required by the ERP.  You could write an export in any data format such as  xml, csv or some custom defined format.
  2. Integrate with Accounting and Inventory Management software such as QuickBooks, Peachtree, etc…
  3. Deduct real-time inventory quantities in an Inventory Management Software program
  4. Export customer information to a CRM such as NetSuite or Microsoft Dynamics
  5. Send an email to a drop-shipper or send a text message to the merchant notifying them another order has been placed.
  6. Alternative uses for membership/provider system. 
  7. Import or export data to/from the Sitefinity Ecommerce module.

 

To use these events developers should add Global.asax file to SitefinityWebApp project and subscribe to the Ecommerce events.

 

The Ecommerce specific events can only be registered after Sitefinity’s Bootstrapper has initialized.  So, first subscribe to the Bootstrapper.Initialized method. In the Bootstapper_Initialized method you can subscribe to Ecommerce specific events like EcommerceEvents.OrderPlaced or EcommerceEvents.PaymentResponse.

 

See the code below for an example.

 

using System;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Modules.Ecommerce;
  
namespace SitefinityWebApp
{
    public class Global : System.Web.HttpApplication
    {
  
        protected void Application_Start(object sender, EventArgs e)
        {
            Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);
        }
  
        void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
        {
            if (e.CommandName == "Bootstrapped")
            {
                EcommerceEvents.OrderPlaced += new EcommerceEvents.OnOrderPlaced(EcommerceEvents_OrderPlaced);
                EcommerceEvents.PaymentResponse += new EcommerceEvents.OnPostPaymentResponse(EcommerceEvents_PaymentResponse);
            }
  
        }
  
        void EcommerceEvents_PaymentResponse(Telerik.Sitefinity.Ecommerce.Payment.Model.IPaymentResponse paymentResponse)
        {
            //Write your own customizations 
        }
  
        void EcommerceEvents_OrderPlaced(Guid orderId)
        {
            // Write your own customizations
        }
  
    }
}

 

I am sure you will find this feature very helpful allowing you to integrate customizations that you may need for your online store.  All future exposed events will be in the EcommerceEvents class.  Upcoming will be another pre-purchase hook that will allow you to write a web service to do anything that you want to do before going into the payment processing section.

We would love to hear about your experiences with these events.  We would also like to hear any other specific scenarios that developers might need to make Sitefinity Ecommerce a more extensible product.

The Progress Team