- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
A lot of users may use this one on their support forums registrations.
I decided to make a function that checks a purchase using the Envato API , your username, your api key, and the customers “Item Purchase Code” ( they can get this from the license file ) .
I wanted to check it and make sure that it works 100%, but i got banned from the API
(“You have been locked out of the API for 1 hour because of too many requests. Please complain to the author of your widget/application.” ) Here is the function. Please test it and tell me if it works well, and also use it as you like in your support forums.
<?php function envato_verify_purchase($purchase_code)
{
//SETUP THE API DATA
$username = '';
$api_key = '';
//CHECK IF THE CALL FOR THE FUNCTION WAS EMPTY
if ( $purchase_code != '' ):
/*
STEPS IN THE CODE BELOW:
- QUERY ENVATO API FOR JSON RESULT
- DECODE THE RESULT AND TRANSFORM IT FROM OBJECTS TO AN ARRAY
- CHECK IF THERE IS A ITEM TITLE == THE PURCHASE WAS MADE OR NOT
*/
$result_from_json = file_get_contents('http://marketplace.envato.com/api/edge/'.$username.'/'.$api_key.'/verify-purchase:'.$purchase_code.'.json');
$result = json_decode($result_from_json, true);
if ( $result['verify-purchase']['item_name'] ) :
return 1;
else:
return 0;
endif;
endif;
}
?>
the comments explain the code- Envato Staff
- Reviewer
- Community Moderator
- Venezuela
- Has been a member for 4-5 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Microlancer Beta Tester
- Sold between 10 000 and 50 000 dollars
- Exclusive Author
Hey thanks man. 
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
This code may fail if they have purchased more than 1 license of the item.
It may also fail because it doesn’t check exactly which item the user has purchased from you. Only that the user has made a purchase from you.
Also file_get_contents on a url may not work on a lot of hosting accounts. Suggest using curl. Possibly try something like this:
$result = false; // have we got a valid purchase code?
$our_item_id = 149180; // check if they've bought this item id.
$username = 'dtbaker'; // authors username
$api_key = 'gphyrdsomething'; // api key from my account area
$url = "http://marketplace.envato.com/api/edge/$username/$api_key/verify-purchase:$code.json";
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$json_res = curl_exec($ch);
$data = json_decode($json_res,true);
$purchases = $data['verify-purchase'];
if(isset($purchases['buyer'])){
// format single purchases same as multi purchases
$purchases=array($purchases);
}
$purchase_details = array();
foreach($purchases as $purchase){
$purchase=(array)$purchase; // json issues
if((int)$purchase['item_id']==(int)$our_item_id){
// we have a winner!
$result = true;
$purchase_details = $purchase;
}
}
// do something with the users purchase details,
// eg: check which license they've bought, save their username something
if($result){
echo 'user has bought our item';
print_r($purchase_details);
}else{
echo 'invalid purchase code';
}
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
FYI here’s an example reply from the API :
{"verify-purchase":{"buyer":"buyer_id_here","created_at":"Wed Dec 01 05:00:47 +1100 2010","licence":"Regular Licence","item_name":"Your Item Name Here","item_id":"116430"}}how to implement this into a registration page?
Hi! thanks to @duotive and @dtbaker for the explanation. My WP theme still in progress and I have a plan to make the Purchase Code as option to enable the updater (Product Serial Number likes).
Some of Themeforest authors give a notification about their purchased theme/plugin(s) have an update from WP dashboard than the buyer have to go to the theme/plugin themeforest page to get the new file(s). Cause of that, I got an idea to make a “setup installation” after theme/plugin activated, than the user must input their Purchase Code > click the Finish button and after that buyer can get the updated files directly on their WP dashbord or Theme option as well.
My question is.
can I use the Purchase Code as Product Serial Number likes?
I wonder what I can do with this function, may be integrating the supports directly from WP dashboard and much more 
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
Hi. That is kinda useless now. Study this: https://github.com/JeffreyWay/Envato-Marketplace-API-Wrapper-in-PHP – this is what all of us are using. 
thanks for the repo, i’m already on it 
um, can you give me your consideration about my idea?
thanks and regard 
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
You’re welcome. I tried to think about that too, but did not do that because of bad ratings that will come with it, because customers will not know how to use it.
The timing for something like this couldn’t be better. I was just wondering how to do this very thing. I am looking into using another tutorial on tuts plus to make a custom logon to my site
http://wp.tutsplus.com/tutorials/creative-coding/bringing-the-membership-process-to-the-front-of-your-site/I wanted to grab the purchase code and or the persons username for themeforest and have the system check to see if they are a buyer. This would make a fantastic plugin for one of you guys smart enough to code it. I would buy that.
