Software Licensing API - Example using jQuery

This document is a subset of the Software Licensing API document which lists all features available via the API. The following is example code showcasing how to implement those features with jQuery.

Request

var data = {
		edd_action: 'check_license', // Valid actions are activate_license, deactivate_license, get_version, check_license
		license:    '<license key>',
		item_name:  encodeURIComponent('<item name>'),
		url: 'domain.com' // If you Disable URL Checking, you do not need this entry
};

// The url to the site running Easy Digital Downloads w/ Software Licensing
var postUrl = 'http://<domain.com>/edd-sl/';

var requestSettings = {
	type: 'POST',
	data: data,
	dataType: 'jsonp'
};

var request = jQuery.ajax( postUrl, requestSettings );

request.always( function(response) {

var slData = jQuery.parseJSON( response.responseText );

if ( slData.success && slData.success == true ) {
	// License check returned data
	// Parse the request for the necessary action requested above
} else {
	// License check did not return successfully
}

Response

A response to the above query would be a JSON object that would look something like this:

{
	"license": "valid",
	"item_name": "EDD Product name",
	"expires": "2014-10-23 00:00:00",
	"payment_id": 54224,
	"customer_name": "John Doe",
	"customer_email": "john@sample.com"
}