Sending carts and displaying the game

Steps and examples of how to use the chosen integration technology or language to send shopping carts and display the game.

Server-side Integration: Java

Files location and description

java/luckycart.jar: the Java library
java/lc_plugin_sample.jsp: an example of use
java/lc-dependencies.zip: Lucky Cart library dependencies
java/lc-javadoc.zip: library documentation

Integration steps

1. Library installation

Copy the library luckycart.jar, as well as its dependencies (contained in lc-dependencies.zip), into the lib directory of your web or server application.

Be careful not to duplicate libraries. It is possible that a log4, commons-logging or commons-codec version is already installed on your application server.

2. Library inclusion

Modify the order confirmation page code in order to include the library:

// Include LC library
import com.luckycart.client.LuckyCart;
import com.luckycart.client.domain.*;

3. Library initialisation and data sending

Always in the order confirmation page code:

// Create a LuckyCart object with your key and secret
LuckyCart luckyCart = LuckyCart.builder().setKey("key").setSecret("secret").createLuckyCart();

// Create a LuckyCartTransaction object
// Assuming data from the site are store in a customer and cart object. 
LuckyCartTransaction transaction = new LuckyCartTransaction();
// mandatory data
transaction.setCustomerId(customer.getId());
transaction.setCartId(cart.getId());
transaction.setTtc(cart.getTtc());
transaction.setHt(cart.getHt());
transaction.setCountry(customer.getCountry());
transaction.setEmail(customer.getEmail());
transaction.setPayment(cart.getPayment());
transaction.setFirstName(customer.getFirstName());
transaction.setLastName(customer.getLastName());
transaction.setCodePromo(cart.getCode());
transaction.setCurrency(cart.getCurrency());
transaction.setLang(cart.getLang());
transaction.setProducts(Arrays.asList(
  new LuckyCartProduct(cart.products[0].getId(), cart.products[0].getHt(),
    cart.products[0].getTtc(), cart.products[0].getQty()),
  new LuckyCartProduct(cart.products[1].getId(), cart.products[1].getHt(),
    cart.products[1].getTtc(), cart.products[1].getQty())
);

// You can add more transaction information by overriding the LuckyCartTransaction class

// Sends the request to LC servers
LuckyCartPluginResponse pluginResponse = luckyCart.plugin(transaction);

4. Game display

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

<body>
...
<!-- Add this div tag anywhere in the order confirmation page to render the game plugin -->
<% out.println(pluginResponse.getGamediv()); %>
...
<!-- Add this script tag at the bottom of the page (in order not to interfere with page loading) -->
<% out.println(pluginResponse.getScript()); %>
</body>

5. Sending additional data

The LuckyCartTransaction class contains predefined mandatory and optional attributes.

If required, it is possible to send additional information for each cart by overloading the LuckyCartTransaction class according to the following method:

public class MyCompanyLuckyCartTransaction extends LuckyCartTransaction
{
    private String myExtraInfo;
    public String getMyExtraInfo() {
        return myExtraInfo;
    }

    public void setMyExtraInfo(String myExtraInfo) {
        this.myExtraInfo = myExtraInfo;
    }
}