Hey guys,
I was wondering if you can help me with the Envato API and BBPress to register users and verify there purchase.
I know this can be done as DDStudios and Kriesi has implemented the system to there forums.
I have attached the register.php file as a zip.
http://www.lifeofstrange.com/register.php.zip
This is the default code for the register.php file:
<?php if ( !bb_is_user_logged_in() ) : ?>
<form method="post" action="<?php bb_uri(); ?>register.php">
<fieldset>
<p>Your password will be emailed to the address you provide.</p>
<table width="100%">
<?php if ( $user_safe === false ) : ?>
<tr class="error">
<th scope="row"><label for="user_login">Username:</label></th>
<td><input name="user_login" maxlength="30" size="30" class="input" id="user_login" type="text" /><br />
<?php _e('Your username was not valid, please try again'); ?></td>
</tr>
<?php else : ?>
<tr class="required">
<th scope="row"><label for="user_login"><sup class="required">*</sup> Username:</label></th>
<td><input name="user_login" maxlength="30" size="30" class="input" id="user_login" value="<?php if (!is_bool($user_login)) echo $user_login; ?>" type="text" /></td>
</tr>
<?php endif; ?>
<?php if ( is_array($profile_info_keys) ) : foreach ( $profile_info_keys as $key ?> $label ) : ?>
<tr<?php if ( $label[0] ) { echo ' class="required"'; $label[1] = '<sup class="required?>* ' . $label[1]; } ?>>
<th scope="row"><label for="<?php echo $key; ?>"><?php echo $label[1]; ?>:</label></th>
<td><input name="<?php echo $key; ?>" maxlength="140" size="30" class="input" id="<?php echo $key; ?>" value="<?php echo $$key; ?>" type="text" /><?php if ( $$key === false ) :
if ( $key == 'user_email' )
_e('<br ?><div class="error">There was a problem with your email; please check it.</class="error">');
else
_e('<br /><div class="error">The above field is required.</div>');
endif; ?>
</div></td>
<?php endforeach; endif; ?>
</table>
<p class="error"><sup>*</sup><?php _e('These items are required.') ?></p>
</fieldset>
<p class="submit">
<input name="Submit" class="button" value="Register" type="submit" />
</p>
</form>
<?php else : ?>
<p>You are already registered to the support forums.</p>
<?php endif; ?>
Any help or point in direction is much appreciated.
Cheers 
- 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
I’d wack an extra box in there under “username” asking for their verification purchase key.
Then find the code that creates a bbpress registration in the database. Just before creating a database entry, put some code in to check the purchase key (maybe something like http://codecanyon.net/forums/thread/envato-api-verify-purchase/37974) and if the purchase key comes back as success continue on creating the bbpress user. If the code is invalid, return an error (similar to how the invalid username error comes back)
There’s some direction pointing
if you’re stuck I might be able to boot up a copy of bbpress and have a fiddle on the weekend.
Thanks for the response dt, 
I did discover the code you provided in the thread but i decided to go by this tutorial:
Could you take a look at this code, at the moment everything works well but i want it to include a php file once the code has been verified:
include('classes/envato.api.class.php');
if(isset($_POST['submit']))
{
// Assign data to variables
$username = $_POST['username'];
$item_id = '41292';
$purchase_code = $_POST['purchase_code'];
$download = true;
// Check if all fields are filled in
if(!empty($username) && !empty($purchase_code))
{
$API = new envatoAPI();
$API->set_api_key('hazcfphr0e1k91xzekw7gmycaemidyfw');
$API->set_username('MattStrange');
// If download is checked request the download-purchase set
if(!empty($download))
{
$API->set_api_set('download-purchase:' . $purchase_code);
$data = $API->request();
// Set the header location to the download URL provided by the API
header("Location: " . $data['download-purchase']['download_url']);
}
else
{
// Response from the API was empty, return error
echo '<p>Sorry, we are unable to verify your purchase.</p>';
}
}
}
I have a basic html form with two inputs, username and purchase code.
When i change this line of code:
header("Location: " . $data['download-purchase']['download_url']);
to include a php file or even an echo rather than going to the download url the whole verification system fails, any information used in the form will work.
The tutorial is here: http://net.tutsplus.com/tutorials/how-to-use-the-latest-updates-to-the-marketplace-api/
Cheers
Also on subject when i submit the form with nothing in the inputs the else echo doesn’t show:
else
{
// Response from the API was empty, return error
echo '<p>Sorry, we are unable to verify your purchase.</p>';
- 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
oo yer forgot about that article. good one.
maybe try something like
nclude('classes/envato.api.class.php');
if(isset($_POST['submit']))
{
// Assign data to variables
$username = $_POST['username'];
$item_id = '41292';
$purchase_code = $_POST['purchase_code'];
$download = true;
// Check if all fields are filled in
if(!empty($username) && !empty($purchase_code))
{
$API = new envatoAPI();
$API->set_api_key('hazcfphr0e1k91xzekw7gmycaemidyfw');
$API->set_username('MattStrange');
$API->set_api_set('verify-purchase:' . $purchase_code);
$data = $API->request();
echo 'done: ';
print_r($data);
}else{
echo 'failed to verify';
}
}
- 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
(and re-set your private api key if that is yours above)
- Community Moderator
- United States
- Was featured in a podcast
- Attended a Community Meetup
- Author had a Free File of the Month
- Bought between 50 and 99 items
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
- Contributed a Tutorial to a Tuts+ Site
dtbaker said
(and re-set your private api key if that is yours above)
((And filter those raw POST vars!)) 
Hey,
Thanks guys for the help but unfortunately its still saying the the item has been verified when both inputs in the form have been submitted… I have no idea what i’m doing wrong 
http://www.lifeofstrange.com/api_demo/private.php
PS: API Regenerated!
- 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 output mean they haven’t bought anything:
done: Array ( [verify-purchase] => Array ( ) )
if you enter a valid purchase code (ie: buy something from yourself via a test account) you will get a bunch of information in that “verify-purchase” array.
you check this information against the item id to confirm that purchase code is for that item.
- 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 Matt, did you finally manage to get this?
