Example of a custom Luckycycle® implementation in a PHP environment with cURL.
Sending HTTP requests
Sending HTTP requests with PHP requires a HTTP extension such as cURL to be installed. Please make sure your e-commerce allows you to make HTTP requests.
You will have to gather data from your e-commerce environment, such as user ID, order ID, order value, etc. This step varies from one environment to the other.
When all data is fetched, is must be passed to a POST request to the Luckycycle® "poke" API.
API Key header
Don't forget to put your API Key (found in the Luckycycle® dashboard) in the header, under the name : X-LuckyApiKey.
If this call is successful, the response will contain a "html_data" field that you have to echo out in order the generate de Luckycycle® iframe.
Replace placeholders by real values
In the example below, replace all placeholders (in double brackets) with real data from your client's order. They way to achieve this depend on your store implementation.
Below is a short example:
<?php
$ch = curl_init();
// Set the request URL
curl_setopt($ch,CURLOPT_URL, 'https://www.luckycycle.com/api/v1/operations/{{OPERATION_ID}}/poke');
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-LuckyApiKey: {{API_KEY}}'));
curl_setopt($ch, CURLOPT_POST, 1);
// Add POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS,"item_currency={{ORDER_CURRENCY}}&item_value={{ORDER_VALUE}}&language={{LANGUAGE}}&user_uid={{USER_ID}}&item_uid={{ORDER_ID}}");
// Set connexion settings
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($ch,CURLOPT_TIMEOUT, 20);
$response = curl_exec($ch);
curl_close ($ch);
$decode = json_decode($response, true);
echo $decode['html_data'];
?>
