Skip to content

Commit

Permalink
WP estore plugin integration added
Browse files Browse the repository at this point in the history
  • Loading branch information
amin0_000 committed Sep 26, 2014
1 parent 79f33e5 commit c773263
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 7 deletions.
16 changes: 16 additions & 0 deletions software-license-manager/includes/slm-api-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ static function verify_secret_key() {
}
}

static function insert_license_data_internal($fields) {
/* The fields array should have values for the following keys
//$fields['license_key']
//$fields['lic_status']
//$fields['first_name']
//$fields['last_name']
//$fields['email']
//$fields['company_name']
//$fields['txn_id']
//$fields['max_allowed_domains']
*/
global $wpdb;
$tbl_name = SLM_TBL_LICENSE_KEYS;
$result = $wpdb->insert($tbl_name, $fields);
}

}
73 changes: 73 additions & 0 deletions software-license-manager/includes/slm-third-party-integration.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,75 @@
<?php

/* * ********************************* */
/* * * WP eStore Plugin Integration ** */
/* * ********************************* */
add_filter('eStore_notification_email_body_filter', 'slm_handle_estore_email_body_filter', 10, 3);

function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) {
global $slm_debug_logger, $wpdb;
$slm_debug_logger->log_debug("WP eStore integration - checking if a license key needs to be created for this transaction.");
$products_table_name = $wpdb->prefix . "wp_eStore_tbl";
$slm_data = "";

foreach ($cart_items as $current_cart_item) {
$prod_id = $current_cart_item['item_number'];
$retrieved_product = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$prod_id'", OBJECT);
$package_product = eStore_is_package_product($retrieved_product);
if ($package_product) {
$slm_debug_logger->log_debug('Checking license key generation for package/bundle product.');
$product_ids = explode(',', $retrieved_product->product_download_url);
foreach ($product_ids as $id) {
$id = trim($id);
$retrieved_product_for_specific_id = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$id'", OBJECT);
$slm_data .= slm_estore_check_and_generate_key($retrieved_product_for_specific_id, $payment_data, $cart_items);
}
} else {
$slm_debug_logger->log_debug('Checking license key generation for single item product.');
$slm_data .= slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items);
}
}

$body = str_replace("{slm_data}", $slm_data, $body);
return $body;
}

function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items) {
global $slm_debug_logger;
$license_data = '';

if ($retrieved_product->create_license == 1) {
$slm_debug_logger->log_debug('Need to create a license key for this product (' . $retrieved_product->id . ')');
$slm_key = slm_estore_create_license($payment_data, $cart_items);
$license_data = "\n" . __('Item Name: ', 'slm') . $retrieved_product->name . " - " . __('License Key: ', 'slm') . $slm_key;
$slm_debug_logger->log_debug('Liense data: ' . $license_data);
$license_data = apply_filters('slm_estore_item_license_data', $license_data);
}
return $license_data;
}

function slm_estore_create_license($payment_data, $cart_items) {
global $slm_debug_logger;

$options = get_option('slm_plugin_options');
$lic_key_prefix = $options['lic_prefix'];

$fields = array();
$fields['license_key'] = uniqid($lic_key_prefix);
$fields['lic_status'] = 'pending';
$fields['first_name'] = $payment_data['first_name'];
$fields['last_name'] = $payment_data['last_name'];
$fields['email'] = $payment_data['payer_email'];
$fields['company_name'] = $payment_data['company_name'];
$fields['txn_id'] = $payment_data['txn_id'];
$fields['date_created'] = date ("Y-m-d");//Today's date
$fields['max_allowed_domains'] = $options['default_max_domains']; //TODO - later take from estore's product configuration

$slm_debug_logger->log_debug('Inserting license data into the license manager DB table.');
SLM_API_Utility::insert_license_data_internal($fields);

return $fields['license_key'];
}

/************************************/
/*** End of WP eStore integration ***/
/************************************/
3 changes: 2 additions & 1 deletion software-license-manager/menu/lic_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ function wp_lic_mgr_general_settings() {
<tr valign="top">
<th scope="row">Enable Debug Logging</th>
<td><input name="enable_debug" type="checkbox"<?php if ($options['enable_debug'] != '') echo ' checked="checked"'; ?> value="1"/>
<p class="description">If checked, debug output will be written to log files (keep it disabled unless you are troubleshooting).</p>
&nbsp;<a href="<?php echo WP_LICENSE_MANAGER_URL. '/logs/log.txt'; ?>" target="_blank">View Log File</a>
<p class="description">If checked, debug output will be written to log files (keep it disabled unless you are troubleshooting).</p>
</td>
</tr>

Expand Down
9 changes: 8 additions & 1 deletion software-license-manager/slm_installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@
update_option("wp_lic_mgr_db_version", WP_LICENSE_MANAGER_DB_VERSION);

// Add default options

$options = array(
'lic_creation_secret' => uniqid('', true),
'lic_prefix' => '',
'default_max_domains' => '1',
'lic_verification_secret' => uniqid('', true),
'enable_debug' => '',
);
add_option('slm_plugin_options', $options);
5 changes: 0 additions & 5 deletions software-license-manager/to-do.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@

//Complete the create API function
//Complete the check API function
//Add capability for logging to debug file
//Add a items custom post type to configure license products?
//Add a simple PayPal integration
//Language translation
//Add datepicker on the date fields in add/edit license interface [done]
//Fix the date time columns so it can save just the "date" value (no time) [done]
//Refactor WP_LICENSE_MANAGER to SLM

=================
//Logs menu with a WP list table that lists all the incoming API requests using custom post type.
//Have an email settings menu?
//Remove "api" folder after the new API is coded in?
//Use WordPress's http query functions everywhere - http://codex.wordpress.org/Function_Reference/wp_remote_get

0 comments on commit c773263

Please sign in to comment.