Skip to content

Commit

Permalink
added a sample plugin that can do the API query remotely.
Browse files Browse the repository at this point in the history
Updated the API response to use JSON Encode and Decode.
  • Loading branch information
amin0_000 committed Sep 22, 2014
1 parent 8b2c03f commit 1c1cca5
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 434 deletions.
83 changes: 0 additions & 83 deletions license-manager/client-side/api-tester-stand-alone.php

This file was deleted.

13 changes: 0 additions & 13 deletions license-manager/client-side/client-custom-configs.php

This file was deleted.

71 changes: 69 additions & 2 deletions license-manager/client-side/sample-plugin/slm-sample-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function sample_license_management_page() {
echo '<div class="wrap">';
echo '<h2>Sample License Management</h2>';

/*** License activate button was clicked ***/
if (isset($_REQUEST['activate_license'])) {
$license_key = $_REQUEST['sample_license_key'];

Expand All @@ -48,14 +49,79 @@ function sample_license_management_page() {
echo "Unexpected Error! The query returned with an error.";
}

var_dump($response);
//var_dump($response);//uncomment it if you want to look at the full response

// License data.
$license_data = json_decode(wp_remote_retrieve_body($response));

// TODO - Do something with it.
//var_dump($license_data);//uncomment it to look at the data

if($license_data->result == 'success'){//Success was returned for the license activation

//Uncomment the followng line to see the message that returned from the license server
echo '<br />The following message was returned from the server: '.$license_data->message;

//Save the license key in the options table
update_option('sample_license_key', $license_key);
}
else{
//Show error to the user. Probably entered incorrect license key.

//Uncomment the followng line to see the message that returned from the license server
echo '<br />The following message was returned from the server: '.$license_data->message;
}

}
/*** End of license activation ***/

/*** License activate button was clicked ***/
if (isset($_REQUEST['deactivate_license'])) {
$license_key = $_REQUEST['sample_license_key'];

// API query parameters
$api_params = array(
'slm_action' => 'slm_deactivate',
'secret_key' => YOUR_SPECIAL_SECRET_KEY,
'license_key' => $license_key,
'registered_domain' => $_SERVER['SERVER_NAME'],
'item_reference' => urlencode(YOUR_ITEM_REFERENCE),
);

// Send query to the license manager server
$response = wp_remote_get(add_query_arg($api_params, YOUR_LICENSE_SERVER_URL), array('timeout' => 20, 'sslverify' => false));

// Check for error in the response
if (is_wp_error($response)){
echo "Unexpected Error! The query returned with an error.";
}

//var_dump($response);//uncomment it if you want to look at the full response

// License data.
$license_data = json_decode(wp_remote_retrieve_body($response));

// TODO - Do something with it.
var_dump($license_data);
//var_dump($license_data);//uncomment it to look at the data

if($license_data->result == 'success'){//Success was returned for the license activation

//Uncomment the followng line to see the message that returned from the license server
echo '<br />The following message was returned from the server: '.$license_data->message;

//Remove the licensse key from the options table. It will need to be activated again.
update_option('sample_license_key', '');
}
else{
//Show error to the user. Probably entered incorrect license key.

//Uncomment the followng line to see the message that returned from the license server
echo '<br />The following message was returned from the server: '.$license_data->message;
}

}
/*** End of sample license deactivation ***/

?>
<p>Please enter the license key for this product to activate it. You were given a license key when you purchased this item.</p>
<form action="" method="post">
Expand All @@ -71,5 +137,6 @@ function sample_license_management_page() {
</p>
</form>
<?php

echo '</div>';
}
51 changes: 0 additions & 51 deletions license-manager/client-side/usage-example.php

This file was deleted.

42 changes: 0 additions & 42 deletions license-manager/client-side/wp-license-mgr-config.php

This file was deleted.

Loading

0 comments on commit 1c1cca5

Please sign in to comment.