Skip to content

Instantly share code, notes, and snippets.

@Zenger
Created January 23, 2014 07:37
Show Gist options
  • Save Zenger/8574493 to your computer and use it in GitHub Desktop.
Save Zenger/8574493 to your computer and use it in GitHub Desktop.
Confirm user license key on envato marketplaces
<?php
class Envato
{
protected static $key = "";
protected static $username = "";
public static function verify( $code )
{
if (empty(self::$key))
{
throw new Exception("No key was set");
}
if (empty(self::$username))
{
throw new Exception("No username was set");
}
$url = sprintf( "http://marketplace.envato.com/api/v3/%s/%s/verify-purchase:%s.json", self::$username, self::$key, $code );
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ch_data = curl_exec($ch);
curl_close($ch);
if (empty($ch_data))
{
throw new Exception("Couldn't connect to the server");
}
$data = json_decode( $ch_data , true );
if (empty($data['verify-purchase']))
{
throw new Exception("Invalid item purchase code");
return false;
}
return true;
}
public static function set_key( $key )
{
self::$key = $key;
}
public static function set_username($username)
{
self::$username = $username;
}
}
<?php
Envato::set_key("YOUR-ENVATO-API-KEY");
Envato::set_username("YOUR-USERNAME");
try {
$test = Envato::verify("4efd2738-02fd-4e2f-92f0-2b07149203d4");
if ($test)
{
echo "We have a legit user";
}
}
catch(Exception $e)
{
echo $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment