Tutorial: How to verify your customer license key with envato marketplace api
CriticalGears CriticalGears
January 26, 2011

We provide support only for the customers who bought our files on envato marketplaces or who purchased our non-exclusive items through our site. Each sale comes with a license key. There is no problem to check direct site sales licenses, however how would you check when envato customer sends some request (directly to your support email for example)?


Here’s how.
All you need to get from your customer – license key (located in my account-> downloads, next to each download).

  • Now, locate your API key from your account in the "My Settings" area.
  • Create a file somewhere on your computer with any prefered name
  • Paste the following code inside:

      <?php 
      $envato_apikey = "your_api_key";
      $envato_username = "your_username";
      $license_to_check = preg_replace(‘/[^a-zA-Z0-9_ -]/s\’, ‘\’, !empty($_REQUEST["license"])?$_REQUEST["license"]:"");

      if(!empty($license_to_check) && !empty($envato_apikey) && !empty($envato_username)){
      //Initialize curl
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, ‘http://marketplace.envato.com/api/edge/’.$envato_username.’/’.$envato_apikey.’/verify-purchase:’.$license_to_check.’.json’);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $ch_data = curl_exec($ch);
      curl_close($ch);
      if(!empty($ch_data))
      {
      $json_data = json_decode($ch_data, true);
      if(isset($json_data[\’verify-purchase\’]) && count($json_data[\’verify-purchase\’])>0){
      echo "License Type: ".$json_data[\’verify-purchase\’][\’licence\’]."<br />";
      echo "Item Name (ID): ".$json_data[\’verify-purchase\’][\’item_name\’]." (".$json_data[\’verify-purchase\’][\’item_id\’].")<br />";
      echo "Buyer Username: ".$json_data[\’verify-purchase\’][\’buyer\’]."<br />";
      echo "Purchase Date: ".$json_data[\’verify-purchase\’][\’created_at\’]."<br />";
      } else {
      echo "Error fetching the info. Possible reason: license key invalid. Here\’s the curl return: ";
      print_r($json_data);
      }
      }
      else
      {
      echo ‘Something went terribly wrong!’;
      }
      } else { 
      echo ‘You either didn`t pass the license key into the url or didn`t enter your envato username/apikey into configuration’;
      }
      ?>


  • Replace your_api_key with your api key
  • Replace your_username with your username
  • Save and upload your file to some web host which supports cURL

 

Now open your favorite browser, and point it to the file you just uploaded. You will see the error 🙂
Add ?license=license_key_for_verification to the address bar – and swap license_key_for_verification with license key which needs to be verified. If customer purchased your product and the license key is valid you will see following on the screen:

License Type: "purchased_license_type"
Item Name (ID): "your_product_name (your_product_envato_id)"
Buyer Username: "some_username_here"
Purchase Date: "purchase_date"

We hope that this tutorial will help some authors in dealing with people who downloaded your products on some warez sites and demand the support from you 🙂

We\’d love to hear if any of you have implemented envato api for license verification purposes.

Note: part of the code was taken from NetTuts – http://net.tutsplus.com/tutorials/php/display-anything-you-want-from-the-envato-api-using-php/ 

Liked this post? We’d like to hear from you...