• Resolved Cristi S.

    (@cristiscu)


    Both the SLM plugin and yours provide a great missing functionality, congrats for your work!

    Here is a problem: when someone buys more than one software product – let’s say one license of “Office Manager” and one of “ABC Video Player” – the license issued for “Office Manager” can be used to activate “ABC Video Player”! And we don’t want this…

    This is because the current SLM client API activation cannot handle and check the product id as well. And reject the request if the key was not generated for that product type.

    The SLM guy exposed a hook there that I could eventually use to extend his plugin, but I need to know first the product id (the ID from wp_posts I suppose) for which a license key was actually generated. And this is actually part of your implementation.

    I’ll appreciate all your help. Thanks.

    https://www.ads-software.com/plugins/wc-software-license-manager/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Cristi S.

    (@cristiscu)

    …answering my own question, in case anyone else encounters the same problem… It looks like the “Unique Transaction ID”, associated to a License Key, is in fact the Product ID (set by the WooCommerce integration plugin).

    In your theme’s functions.php, you can add this:

    // check product id on the activation/deactivation of a license key
    add_action('slm_api_listener_slm_activate', 'check_license_and_product_on_slm' );
    add_action('slm_api_listener_slm_deactivate', 'check_license_and_product_on_slm' );
    function check_license_and_product_on_slm() {
       if (isset($_REQUEST['product_id'])) {
          $prod_id = intval(trim(strip_tags($_REQUEST['product_id'])));
          $key = trim(strip_tags($_REQUEST['license_key']));
    
          global $wpdb;
          $tbl_name = SLM_TBL_LICENSE_KEYS;
          $sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key);
          $retLic = $wpdb->get_row($sql_prep1, OBJECT);
    
          if ($retLic && $retLic->txn_id != $prod_id) {
             $args = (array('result' => 'error', 'message' => 'Your license key was not issued for this product'));
             SLM_API_Utility::output_api_response($args);
          }
       }
    }

    When your client app appends a &product_id= at the end of the query string, a check will be performed and the query fails if the key was actually issued for another product.

    Hi, can you help me out? How do Woocommerce SLM addon know the stored Product name?
    To check the requested ‘product_id’, i suppose there shoud be a product id collumn in the database to check against. But mine only have ‘product_ref’, and it is empty.

    I got Easy digital download addon running as it adds the product name to the ‘txn_id’, so i have something to check the request with.

    I wonder how you got it working.
    See my database table.
    postimage

    • This reply was modified 7 years, 8 months ago by supermagna.
    • This reply was modified 7 years, 8 months ago by supermagna.
    • This reply was modified 7 years, 8 months ago by supermagna.

    To answer my own question, I got it working by modifying wc-software-license-manager.php. Now the Product name is stored in the database, so it can be checked at activation time.

    search for ‘txn_id’, and comment out the line:
    //$api_params[‘txn_id’] = $order_id;
    and add a new line under that one:
    $api_params[‘txn_id’] = $order_id . ” – ” . $item_name; //example ‘022 – Appname’ (as EDD).

    To complete the Sofware License Manager – Product Control function, I made a plugin that can be found here:
    https://www.ads-software.com/support/topic/the-same-licence-key-can-activate-all-my-prodcts/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to check if a license key was issued for a specific product (by ID)?’ is closed to new replies.