Sending carts and displaying the game

Steps and examples to send shopping carts and display the game.

ASP .NET integration

Files location and description the ASP .NET library example of use page example of use code

Integration steps

1. Library installation

Copy the luckycart.dll library into the Bin subdirectory of the order confirmation page.

2. Library inclusion

Modify the order confirmation page code to include library:

// Include LC library
Using LuckyCart;

3. Library initialisation and sending data

Always in the order confirmation page code:

// Use exception to catch error
try {
  // Create a Lucky Cart object with your key and secret
  LuckyLib lc = new LuckyLib(Key, Secret);

  // Create an array of data to send to associate with the token.
  // Assuming data from the site are store in Customer and Cart object. 
  Dictionary<string, object> PostData = new Dictionary<string, object>()
    // mandatory data
    {"customerId", Customer.Id},
    {"cartId"    , Cart.Id},
    {"ttc", Cart.Ttc},
    {"ht", Cart.Ht},
    {"country", Customer.Country},
    {"email", Customer.Email},
    {"payment", Cart.Payment},
    {"firstName", Customer.FirstName},
    {"lastName", Customer.LastName},
    {"codePromo", Cart.Code},
    {"payment", Cart.Currency},
    {"lang", Customer.Language},
    {"shopId", Cart.ShopId},
    {"optin", Customer.Optin},
    {"products", new List() {
      new NameValueCollection() {{"id", Cart.Products[0].Id},
        {"ttc", Cart.Products[0].Ttc}, {"ht", Cart.Products[0].Ht},
        {"qty", Cart.Products[0].Qty}, {"cat", Cart.Products[0].Category},
        {"brand", Cart.Products[0].Brand}},
      new NameValueCollection() {{"id", Cart.Products[1].Id},
        {"ttc", Cart.Products[1].Ttc}, {"ht", Cart.Products[1].Ht},
        {"qty", Cart.Products[1].Qty}, {"cat", Cart.Products[1].Category},
        {"brand", Cart.Products[1].Brand}},
      new NameValueCollection() {{"id", Cart.Products[2].Id}, {"ttc",
        {"ttc", Cart.Products[2].Ttc}, {"ht", Cart.Products[2].Ht},
        {"qty", Cart.Products[2].Qty}, {"cat", Cart.Products[2].Category},
        {"brand", Cart.Products[2].Brand}},

    // add here any other specific data

    // Sends the creation request to LC servers
    var plugin = lc.Plugin(PostData);

    // Injects the game container into a div tag
    lcgame.InnerHtml = plugin.gamediv;

    // Injects the script to run into a div tag
    lcscript.InnerHtml = plugin.script;
catch (Exception ex)
    //handle exception here (retry, log, ...)
    throw ex;

4. Game display

Completed by positioning the following containers on the order confirmation page:

<!-- Add this div tag anywhere in the order confirmation page to render the game plugin -->
<div id="lcgame" runat="server"></div>  
<!-- Add this div tag at the bottom of the page (in order not to interfere with page loading) -->
<div id="lcscript" runat="server"></div>