This article focuses on how to simply and efficiently converse with Envato’s API in order to verify the authors’ customers’ purchase codes in the author’s own applications. I talk through all the steps to set up this function, covering how to create the unique API key required, using the PHP cURL function and interpreting the output.
<?php
function verify_envato_purchase_code($code_to_verify) {
// Your Username
$username = 'USERNAME';
// Set API Key
$api_key = 'API KEY';
// Open cURL channel
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, "http://marketplace.envato.com/api/edge/". $username ."/". $api_key ."/verify-purchase:". $code_to_verify .".json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Decode returned JSON
$output = json_decode(curl_exec($ch), true);
// Close Channel
curl_close($ch);
// Return output
return $output;
}
$purchase_key = 'PURCHASE KEY TO CHECK';
$purchase_data = verify_envato_purchase_code( $purchase_key );
if( isset($purchase_data['verify-purchase']['buyer']) ) {
echo '<strong>Valid License Key!</strong><br>Details;<ul>';
echo '<li>Item ID: ' . $purchase_data['verify-purchase']['item_id'] . '</li>';
echo '<li>Item Name: ' . $purchase_data['verify-purchase']['item_name'] . '</li>';
echo '<li>Buyer: ' . $purchase_data['verify-purchase']['buyer'] . '</li>';
echo '<li>License: ' . $purchase_data['verify-purchase']['licence'] . '</li>';
echo '<li>Created At: ' . $purchase_data['verify-purchase']['created_at'] . '</li>';
echo '</ul>';
} else {
echo 'Invalid license key.';
}
?>
Sources:
http://www.wpeka.com/verify-item-purchases-envato.html
http://hbt.io/verify-item-purchases-envato/