PHP integration
Files location and description
- php/luckycart.php : the php library
- php/sample.php : an example of use
Integration steps
1. Library installation
Copy the luckycart.php library on the server to a place that is accessible from the order confirmation page.
2. Library inclusion
Modify the order confirmation page to include the library:
// Include LC library
require_once('path/to/luckycart.php');
3. Initialisation of the library and sending data
Always on the order confirmation page.
// Use exception to catch error
try {
// Create a Lucky Cart object with your key and secret
$lucky = new LuckyCart('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 data.
$postdata = array(
// 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,
'currency' => $cart->currency,
'lang' => $customer->language,
'shopId' => $cart->shopId,
'optin' => $customer->optin,
'products' => array(
array('id' => $cart->products[0]->id, 'ttc' => $cart->products[0]->ttc,
'ht' => $cart->products[0]->ht, 'qty' => $cart->products[0]->quantity,
'cat' => $cart->products[0]->category, 'brand' => $cart->products[0]->brand),
array('id' => $cart->products[1]->id, 'ttc' => $cart->products[1]->ttc,
'ht' => $cart->products[1]->ht, 'qty' => $cart->products[1]->quantity,
'cat' => $cart->products[1]->category, 'brand' => $cart->products[1]->brand),
array('id' => $cart->products[2]->id, 'ttc' => $cart->products[2]->ttc,
'ht' => $cart->products[2]->ht, 'qty' => $cart->products[2]->quantity,
'cat' => $cart->products[2]->category, 'brand' => $cart->products[2]->brand),
),
// add here any other specific data
);
// Sends the request to LC servers
$plugin = $lucky->plugin($postdata);
}
catch (LuckyException $e)
{
// Do something with the error... retry or log
// the error message for example... ($e->getMessage())
}
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 -->
<?php echo $plugin->gamediv; ?>
...
<!-- Add this script tag at the bottom of the page (in order not to interfere with page loading) -->
<?php echo $plugin->script; ?>
</body>