35 posts
  • Has been part of the Envato Community for over 3 years
Delpierooo says

Hi.

I am trying to verify the purchase code of an item using: http://marketplace.envato.com/api/edge/USERNAME/API-KEY/verify-purchase:550e8400-e29b-41d4-a716-446655440000.json

In the javascript code I am using:

var url='http://marketplace.envato.com/api/edge/USERNAME/API-KEY/verify-purchase:550e8400-e29b-41d4-a716-446655440000.json';

$.getJSON(url, function(jd) {     
 var entire_purchase = jd["verify-purchase"];     
 var buyer_name = entire_purchase.buyer;         
 alert(buyer_name);
 });

I have the api key and username inserted but still can’t get it to work. So somewhere taht adding ?callback=? in the end of the url would help but it doesn’t.

Any idea what I am doing wrong? The code itself work ok if I have the json file localy for example, but need to read that one.

TNX!

35 posts
  • Has been part of the Envato Community for over 3 years
Delpierooo says

Hi,

yes I am using the right username and api. If I open the js in a browser the json file is displayed ok. And if are put that content in a local file(was trying this on my localhost) it works ok. It seems that something is missing if using a JSON file from other server. Read something about that, but none solution worked. Any idea for the fix?

TNX!

590 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
  • Sells items exclusively on Envato Market
+5 more
CodeSwift says

I’m pretty sure you’ll get the info about a purchase only if you use the username and api of the item author.

Basically, only the author of the purchased item can verify a purchase.

35 posts
  • Has been part of the Envato Community for over 3 years
Delpierooo says

This is what I get in the Console:

XMLHttpRequest cannot load http://marketplace.envato.com/api/edge/XXXXXXX/YYYYYYY/verify-purchase:550e8400-e29b-41d4-a716-446655440000.json. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers.

Any idea?

P.S. I am using the right username and api key, just didn’t insert it here on the forum.

316 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
+2 more
SyamilMJ says

You can’t do that. Read same origin policy – https://developer.mozilla.org/en-US/docs/JavaScript/Same_origin_policy_for_JavaScript

Print your json output on a local file, and fetch it via js from there

35 posts
  • Has been part of the Envato Community for over 3 years
Delpierooo says

Hi again.

This is how it would look like:

http://jsfiddle.net/SQGqp/

tnx.

316 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
+2 more
SyamilMJ says

Here’s another read if what I posted earlier did not somewhat convince you – http://stackoverflow.com/questions/9327218/access-control-allow-origin-not-allowed-by

Bottom line is, you simply can’t.

Do it the smart way, use ajax + server side scripting to fetch the json output dynamically.

35 posts
  • Has been part of the Envato Community for over 3 years
Delpierooo says

Hi,

if I use php to check the purchase code all goes ok. But I am testing this before submiting a form(bbpress: form.user-register)

<form … onsubmit=”return checkPurchaseCode()”.. >

So I have a js function called before submiting.

If I change action so some custom file (checkPurchase.php), I can(successful) check the purchase code there using php, but don’t know how to get back to submit the form (bbpress: form.user-register)

Any idea about this maybe?

5 posts
  • Has been part of the Envato Community for over 3 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
fraserjilani says

I got it working via the Ajax call but since the server always returns a 403 when an invalid purchase code is supplied I tested it with the total users API request, it is going to be very similar for you.

http://jsfiddle.net/P9Tuu/
5 posts
  • Has been part of the Envato Community for over 3 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
fraserjilani says

Just an update, it doesn’t seem to be working with older browsers due to cross domain request restrictions. If this is a concern I would suggest using a php proxy method that sushipasta posted previously, you should also look into the following to get a better idea with how to work whit the API php side ;) :-

http://net.tutsplus.com/tutorials/php/display-anything-you-want-from-the-envato-api-using-php/

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by