forked from Arsenal21/software-license-manager
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
amin0_000
committed
Sep 26, 2014
1 parent
79f33e5
commit c773263
Showing
5 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
software-license-manager/includes/slm-third-party-integration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ***/ | ||
/************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |