Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //TODO: set your API key found in http://wyday.com/limelm/settings/
- $api_key = 'PASTE THE API KEY HERE';
- //TODO: set the version id to generate & find keys for
- // the version id is found in the url. For example http://wyday.com/limelm/version/100/
- // the version id is 100.
- $version_id = '100';
- date_default_timezone_set('America/Toronto');
- function urlEncodePostData($post_data)
- {
- $post_string = '';
- foreach ($post_data as $key => $value)
- {
- if (is_array($value))
- {
- foreach ($value as $sub_value)
- {
- $post_string .= $key.'[]='.urlencode($sub_value).'&';
- }
- }
- else
- $post_string .= $key.'='.urlencode($value).'&';
- }
- $post_string = rtrim($post_string, '& ');
- $request = curl_init('https://wyday.com/limelm/api/rest/');
- curl_setopt($request, CURLOPT_HEADER, 0);
- curl_setopt($request, CURLOPT_ENCODING, "");
- curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);
- curl_setopt($request, CURLOPT_SSL_VERIFYPEER, TRUE);
- return $request;
- }
- function getProductKeyDetails($post_data)
- {
- $request = urlEncodePostData($post_data);
- $jObj = json_decode(curl_exec($request));
- if ($jObj->stat == 'ok')
- {
- foreach ($jObj->pkeys->pkey as $pkey)
- {
- return array
- (
- 'key' => $pkey->key,
- 'id' => $pkey->id
- );
- }
- }
- else
- {
- // Uncomment the next line to see the error LimeLM is giving you.
- //echo $jObj->message;
- }
- return null;
- }
- function getProductKeyExpiry($post_data)
- {
- $request = urlEncodePostData($post_data);
- $jObj = json_decode(curl_exec($request));
- if ($jObj->stat == 'ok')
- {
- foreach ($jObj->pkey->features->feature as $feature)
- {
- if($feature->name == 'subscription_expiry')
- return $feature->value;
- }
- }
- else
- {
- // Uncomment the next line to see the error LimeLM is giving you.
- //echo $jObj->message;
- }
- return null;
- }
- function setProductKeyDetails($post_data)
- {
- $request = urlEncodePostData($post_data);
- $jObj = json_decode(curl_exec($request));
- if ($jObj->stat !== 'ok')
- {
- // Uncomment the next line to see the error LimeLM is giving you.
- //echo $jObj->message;
- }
- }
- try
- {
- $post_data = array(
- 'method' => 'limelm.pkey.advancedSearch',
- 'api_key' => $api_key,
- 'version_id' => $version_id,
- 'email' => $email,
- 'feature_name' => array('fastspring_subscription_id'),
- 'feature_value' => array($reference),
- 'feature_match' => array('exact'),
- 'nojsoncallback' => 1,
- 'format' => 'json'
- );
- $product_key_details = getProductKeyDetails($post_data);
- if($product_key_details !== null)
- {
- $product_key = $product_key_details['key'];
- $product_key_id = $product_key_details['id'];
- $post_data = array(
- 'method' => 'limelm.pkey.getDetails',
- 'api_key' => $api_key,
- 'pkey_id' => $product_key_id,
- 'nojsoncallback' => 1,
- 'format' => 'json'
- );
- $product_key_expiry = getProductKeyExpiry($post_data);
- $current_date_time = date('Y-m-d H:i:s', time());
- if($current_date_time > $product_key_expiry)
- {
- $new_product_key_expiry = date('Y-m-d H:i:s', strtotime($current_date_time . '+1 year'));
- }
- else
- {
- $new_product_key_expiry = date('Y-m-d H:i:s', strtotime($product_key_expiry . '+1 year'));
- }
- $post_data = array(
- 'method' => 'limelm.pkey.setDetails',
- 'api_key' => $api_key,
- 'pkey_id' => $product_key_id,
- 'feature_name' => array('subscription_expiry'),
- 'feature_value' => array($new_product_key_expiry),
- 'nojsoncallback' => 1,
- 'format' => 'json'
- );
- setProductKeyDetails($post_data);
- echo $product_key . "\r\n";
- }
- }
- catch (Exception $e)
- {
- // Uncomment the next line to see the exception.
- //echo 'Failure: '.$e->getMessage();
- }
- ?>
Add Comment
Please, Sign In to add comment