Custom Events

 

 

Enable OnCheckout Complete Event (Stored Procedure) – Allows you to call a custom SQL Server stored procedure that you program. The event that triggers the stored procedure being executed is a successful checkout in the cart.  This is useful if you need to populate a backend ERP or Accounting system with new store orders.  When you check the Enable OnCheckout Complete Event (Stored Procedure) checkbox a textbox will be displayed where you can enter the stored procedure you want to call:

 

 

 

 

 

Store Procedure Naming Convention

 

The following is the naming convention for the stored procedure:

 

DatabaseOwner + ObjectQualifier + ModuleQualifier in front of your stored procedure.

 

      DatabaseOwner is usually “dbo”

      ObjectQualifier – Is assigned when you installed DNN.  The objectqualifier in your database could be "dnn" or you may not be using one.  If you are not sure you can check by logging into your database using SSMS.

      ModuleQualifier is “Smith”

 

For example, a stored procedure titled “TransferOrder” should be named as follows:

 

“dbo.dnn_Smith_ TransferOrder”

 

 

Parameters Passed To Stored Procedure

 

The following two parameters are passed to the stored procedure:

 

1.   OrderID (String) – SmithCart order id generated for the new order.

 

2.  SCData (String) – Custom parameter that passes the value of a session variable (SCData) to your stored procedure when checkout is complete.  The "SCData" parameter allows the cart to integrate with another Asp.Net application or other modules in your portal.  Note:  SmithCart does not populate the SCData session object, it is only populated by another application or module on your site.  If you don’t have a requirement for passing additional data using SCData it will be passed as an empty string. 

 

Please Note:  It is required that the “OrderID” and “SCData” parameters are defined as varchar or nvarchar parameters at the top of your stored procedure.

 

 

Enable OnCheckout Complete Event (Web Service) - Allows you to call a custom web service that you program.  The web service that is called can be on the same web server as the cart or on another externally hosted web server.   The event that triggers the web service call is a successful checkout in the cart.  When you check the Enable OnCheckout Complete Event (Web Service) checkbox a textbox will be displayed where you can enter the web service URL you want to call:

 

 

 

 

The following is the naming convention for the Web Service URL:

 

http://domain.com/service1.svc/GetLicense?oid=[ORDERID],odids=[ORDERDETAILIDS]

 

      Domain Name – The domain name, server name or IP address for your web service

      Service Name – The full path to your web service

      oid=[ORDERID] – Token used by the cart to pass the order id to the web service

      odids=[ORDERDETAILIDS] – Token used by the cart to pass the order id to the web service

 

On successful order the cart will do an http post with name value pairs (NVP) in the querystring populated by tokens. 

 

Example:

In the BuyNow settings in the web service URL field enter the following URL:

 

http://domain.com/service1.svc/GetLicense?oid=[ORDERID],odids=[ORDERDETAILIDS]

 

[ORDERID] – The Order ID from the cart order.

[ORDERDETAILID]  - Comma separated list of Order Detail IDs from the cart order.

 

1.  The customer successfully checks out and purchases three products.

2.  The cart saves the order to the database

a.  OrderID 123 is saved to the Smith_StoreOrders table

b.  OrderDetail IDs 4,5 and 6 are saved to the StoreOrderDetails table

3.  The cart  makes the following web request to your custom web service:

 

http://domain.com/service1.svc/GetLicense?oid=123,odids=4,5,6

 

4.  Your custom web service receives the web service call and does the following:

a.  Consumes the parameters passed and executes some business logic based on your requirements (i.e.  Query the Smith_StoreOrderDetail table and create license keys).

b.  Generates web response in the following format:

 

OrderDetailID1, LicenseKey1, OrderDetailID2, LicenseKey2, OrderDetailID3, LicenseKey3

 

For Example:  4, ABC2X55YTR, 5, RTY856PKIL, 6, EWS321BNH

 

 

Summary Web Service Request and Response:

 

Web Client Request:  http://domain.com/service1.svc/GetLicense?oid=123,odids=4,5,6

Web Server Response:  4, ABC2X55YTR, 5, RTY856PKIL, 6, EWS321BNH

 

SmithCart uses the built in Dot Net “DataContractSerializer” class to parse the response from your custom web service.  Please see the following c# code as an example of how SmithCart consumes the response from your custom web service.

 

WebResponse wsRes = wsReq.GetResponse();

DataContractSerializer wsData = new DataContractSerializer(typeof(string));

string info = (string)wsData.ReadObject(wsRes.GetResponseStream());

 

Please see the following link for more info on the Dot Net “DataContractSerializer” class:

 

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer(v=vs.90).aspx

 

Because SmithCart uses the “DataContractSerializer” class to parse the response, your custom web service should be implemented using the newer “RESTful” web service .svc web service model instead of the old .asmx model.

 

This is the simplest and most open technique for communicating with a web service and is not tied to any specific platform or technology.  Rather than passing all the order information in the querystring the cart passes the unique keys (Order ID and Order Detail IDs) that enables the web service to lookup any or all order information required.  The only caveat is that the data returned from your custom web service may not contain any commas in the actual data because the comma is used as a field delimiter for the cart to parse the response.

 

Database

The order is saved to the database before the web service call and the confirmation email is sent after the web service call returns.  The purpose for this is to allow the custom web service to query the Order ID and Order Detail IDs in the SmithCart database to get the order info (if needed) and the customer will get the order confirmation email with the fields the web service sends back.

 

The data passed back from the web service is saved to the “Smith_StoreOrderDetail”  table in a field titled “WebServiceData”.

 

Email Confirmation

To insert the data returned from the web service to the confirmation email add the token called [WebServiceData] in the email template in SmithCart.

 

My Accounts Module

The “WebServiceData” field is viewable in the SmithCart "My Account" module in the order detail section.

 

Real World Applications

The following are a few possible uses of the web service on checkout complete event:

      Updating another system with new cart orders.

      Sending orders to a 3rd party fulfillment house.

      Generating license keys  when selling software