Intégration en ASP.NET
Description et emplacement des fichiers à utiliser
- asp.net/luckycart.dll : la librairie ASP .NET
- asp.net/lc_plugin_sample.aspx : la page de l’exemple d’utilisation
- asp.net/lc_plugin_sample.aspx.cs : le code de l’exemple d’utilisation
Etapes d'intégration
1. Installation de la librairie
Placez la librairie luckycart.dll dans un sous-répertoire Bin de celui contenant la page de confirmation de commande.
2. Inclusion de la librairie
Modifiez le code de la page de confirmation de commande pour inclure la librairie :
// Include LC library
Using LuckyCart;
3. Initialisation de la librairie et envoi des données
Modifiez le code de la page de confirmation de commande pour inclure la librairie :
// 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. Affichage du jeu
Il s’effectue en positionnant les containers suivants sur la page de confirmation de commande :
<body>
...
<!-- Add this div tag anywhere in the order confirmation page to render the game plugin -->
<div id="lcgame" runat="server"></div>
</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>
</body>