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.jsonIn 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!
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!
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.
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.
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
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.
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?
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/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/
