{"id":1011,"date":"2025-11-30T06:48:13","date_gmt":"2025-11-30T06:48:13","guid":{"rendered":"https:\/\/easycommerce.dev\/docs\/?post_type=ek_doc&#038;p=1011"},"modified":"2026-03-12T06:18:50","modified_gmt":"2026-03-12T06:18:50","slug":"license-manager-api-documentation","status":"publish","type":"ek_doc","link":"https:\/\/easycommerce.dev\/docs\/addons\/license-manager-api-documentation\/","title":{"rendered":"License Manager (API Documentation)"},"content":{"rendered":"\n<h2>Overview<\/h2>\n\n<p>The EasyCommerce License Manager is an addon for EasyCommerce that enables selling licensed products such as WordPress plugins, themes, games, or any software. It provides a REST API for managing licenses, including activation, deactivation, and retrieval of license information.<\/p>\n\n<p>This API allows developers to integrate license management into their products, enabling automatic license validation and activation tracking.<\/p>\n\n<h2>Base URL<\/h2>\n\n<p>All API endpoints are prefixed with your WordPress site&#8217;s REST API base:<\/p>\n\n<pre><code>https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/<\/code><\/pre>\n\n<h2>Authentication<\/h2>\n\n<h3>For Admin Operations<\/h3>\n<ul>\n    <li>Requires WordPress authentication (logged in as admin)<\/li>\n    <li>Uses WordPress nonce for CSRF protection<\/li>\n<\/ul>\n\n<h3>For Customer Operations<\/h3>\n<ul>\n    <li>Requires WordPress authentication (logged in as customer)<\/li>\n    <li>Uses WordPress nonce for CSRF protection<\/li>\n<\/ul>\n\n<h3>For Public Operations (Activation\/Deactivation)<\/h3>\n<ul>\n    <li>No authentication required<\/li>\n    <li>License key and email validation used for security<\/li>\n<\/ul>\n\n<h2>Endpoints<\/h2>\n\n<h3>1. List Licenses<\/h3>\n\n<p>Retrieve a list of licenses with optional filtering.<\/p>\n\n<p><strong>Endpoint:<\/strong> <code>GET \/wp-json\/easycommerce\/v1\/licenses<\/code><\/p>\n\n<p><strong>Permissions:<\/strong><\/p>\n<ul>\n    <li>Admin: Can view all licenses<\/li>\n    <li>Customer: Can only view their own licenses<\/li>\n<\/ul>\n\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n    <li><code>order_id<\/code> (integer, optional): Filter by order ID<\/li>\n    <li><code>customer_id<\/code> (integer, optional): Filter by customer ID<\/li>\n    <li><code>status<\/code> (string, optional): Filter by status (<code>active<\/code>, <code>inactive<\/code>, <code>expired<\/code>, <code>blocked<\/code>)<\/li>\n    <li><code>per_page<\/code> (integer, optional): Number of results per page (default: 10)<\/li>\n    <li><code>page<\/code> (integer, optional): Page number (default: 1)<\/li>\n<\/ul>\n\n<p><strong>Sample Request:<\/strong><\/p>\n<pre><code>curl -X GET \"https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses?per_page=5&page=1\" \\\n  -H \"X-WP-Nonce: your_nonce_here\" \\\n  -H \"Content-Type: application\/json\"<\/code><\/pre>\n\n<p><strong>Sample Response:<\/strong><\/p>\n<pre><code>{\n  \"success\": true,\n  \"data\": {\n    \"licenses\": [\n      {\n        \"id\": 123,\n        \"key\": \"ABC123-DEF456-GHI789\",\n        \"order_id\": 456,\n        \"customer_id\": 789,\n        \"customer_name\": \"John Doe\",\n        \"product_id\": 101,\n        \"product_name\": \"Premium Plugin\",\n        \"product_variation\": \"Pro Version\",\n        \"price_id\": 1,\n        \"status\": \"active\",\n        \"expiry\": \"2024-12-31 23:59:59\",\n        \"activation_limit\": 5,\n        \"activations\": 2\n      }\n    ],\n    \"total\": 25,\n    \"per_page\": 5,\n    \"page\": 1,\n    \"total_pages\": 5\n  }\n}<\/code><\/pre>\n\n<h3>2. Get Single License<\/h3>\n\n<p>Retrieve detailed information about a specific license.<\/p>\n\n<p><strong>Endpoint:<\/strong> <code>GET \/wp-json\/easycommerce\/v1\/licenses\/{key}<\/code><\/p>\n\n<p><strong>Permissions:<\/strong> Customer (can only view their own licenses)<\/p>\n\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n    <li><code>key<\/code> (string, required): License ID or license key<\/li>\n<\/ul>\n\n<p><strong>Sample Request:<\/strong><\/p>\n<pre><code>curl -X GET \"https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/ABC123-DEF456-GHI789\" \\\n  -H \"X-WP-Nonce: your_nonce_here\" \\\n  -H \"Content-Type: application\/json\"<\/code><\/pre>\n\n<p><strong>Sample Response:<\/strong><\/p>\n<pre><code>{\n  \"success\": true,\n  \"data\": {\n    \"id\": 123,\n    \"key\": \"ABC123-DEF456-GHI789\",\n    \"order_id\": 456,\n    \"customer_id\": 789,\n    \"customer_name\": \"John Doe\",\n    \"product_id\": 101,\n    \"product_name\": \"Premium Plugin\",\n    \"price_id\": 1,\n    \"status\": \"active\",\n    \"expiry\": \"2024-12-31 23:59:59\",\n    \"activation_limit\": 5,\n    \"activations\": [\n      {\n        \"site\": \"https:\/\/example.com\",\n        \"activated_at\": \"2024-01-15 10:30:00\"\n      },\n      {\n        \"site\": \"https:\/\/testsite.com\",\n        \"activated_at\": \"2024-01-20 14:45:00\"\n      }\n    ]\n  }\n}<\/code><\/pre>\n\n<h3>3. Create License<\/h3>\n\n<p>Create a new license (admin only).<\/p>\n\n<p><strong>Endpoint:<\/strong> <code>POST \/wp-json\/easycommerce\/v1\/licenses<\/code><\/p>\n\n<p><strong>Permissions:<\/strong> Admin<\/p>\n\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n    <li><code>license_key<\/code> (string, optional): Custom license key. If omitted, one will be auto-generated<\/li>\n    <li><code>order_id<\/code> (integer, required): Associated order ID<\/li>\n    <li><code>customer_id<\/code> (integer, required): Associated customer ID<\/li>\n    <li><code>product_id<\/code> (integer, required): Associated product ID<\/li>\n    <li><code>price_id<\/code> (integer, optional): Associated price ID (default: 1)<\/li>\n    <li><code>status<\/code> (string, optional): License status (<code>active<\/code>, <code>inactive<\/code>, <code>expired<\/code>, <code>blocked<\/code>) (default: <code>active<\/code>)<\/li>\n    <li><code>expiry<\/code> (string, optional): Expiration datetime in <code>Y-m-d H:i:s<\/code> format (default: empty)<\/li>\n    <li><code>activation_limit<\/code> (integer, optional): Maximum number of activations (default: 1)<\/li>\n<\/ul>\n\n<p><strong>Sample Request:<\/strong><\/p>\n<pre><code>curl -X POST \"https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\" \\\n  -H \"X-WP-Nonce: your_nonce_here\" \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{\n    \"order_id\": 456,\n    \"customer_id\": 789,\n    \"product_id\": 101,\n    \"price_id\": 1,\n    \"status\": \"active\",\n    \"expiry\": \"2024-12-31 23:59:59\",\n    \"activation_limit\": 5\n  }'<\/code><\/pre>\n\n<p><strong>Sample Response:<\/strong><\/p>\n<pre><code>{\n  \"success\": true,\n  \"data\": {\n    \"message\": \"License created\",\n    \"id\": 124\n  }\n}<\/code><\/pre>\n\n<h3>4. Delete License<\/h3>\n\n<p>Delete a license (admin only).<\/p>\n\n<p><strong>Endpoint:<\/strong> <code>DELETE \/wp-json\/easycommerce\/v1\/licenses\/{key}<\/code><\/p>\n\n<p><strong>Permissions:<\/strong> Admin<\/p>\n\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n    <li><code>key<\/code> (string, required): License ID or license key to delete<\/li>\n<\/ul>\n\n<p><strong>Sample Request:<\/strong><\/p>\n<pre><code>curl -X DELETE \"https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/ABC123-DEF456-GHI789\" \\\n  -H \"X-WP-Nonce: your_nonce_here\" \\\n  -H \"Content-Type: application\/json\"<\/code><\/pre>\n\n<p><strong>Sample Response:<\/strong><\/p>\n<pre><code>{\n  \"success\": true,\n  \"data\": {\n    \"message\": \"License deleted\"\n  }\n}<\/code><\/pre>\n\n<h3>5. Activate License<\/h3>\n\n<p>Activate a license for a specific site\/domain.<\/p>\n\n<p><strong>Endpoint:<\/strong> <code>POST \/wp-json\/easycommerce\/v1\/licenses\/{key}\/activate<\/code><\/p>\n\n<p><strong>Permissions:<\/strong> Public<\/p>\n\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n    <li><code>key<\/code> (string, required): License key<\/li>\n    <li><code>product<\/code> (string, required): Product slug<\/li>\n    <li><code>email<\/code> (string, required): Email address associated with the license<\/li>\n    <li><code>site_url<\/code> (string, required): URL of the site to activate<\/li>\n    <li><code>is_test<\/code> (boolean, optional): Whether this is a test activation (default: false)<\/li>\n<\/ul>\n\n<p><strong>Sample Request:<\/strong><\/p>\n<pre><code>curl -X POST \"https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/ABC123-DEF456-GHI789\/activate\" \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{\n    \"product\": \"premium-plugin\",\n    \"email\": \"customer@example.com\",\n    \"site_url\": \"https:\/\/mysite.com\",\n    \"is_test\": false\n  }'<\/code><\/pre>\n\n<p><strong>Sample Response (Success):<\/strong><\/p>\n<pre><code>{\n  \"success\": true,\n  \"data\": {\n    \"code\": \"license_activated\",\n    \"message\": \"License activated\",\n    \"activation_id\": 567,\n    \"expiry\": \"2024-12-31 23:59:59\"\n  }\n}<\/code><\/pre>\n\n<p><strong>Sample Response (Error &#8211; Invalid License):<\/strong><\/p>\n<pre><code>{\n  \"success\": false,\n  \"data\": {\n    \"code\": \"license_not_found\",\n    \"message\": \"The license key you entered is invalid!\"\n  }\n}<\/code><\/pre>\n\n<p><strong>Sample Response (Error &#8211; Email Mismatch):<\/strong><\/p>\n<pre><code>{\n  \"success\": false,\n  \"data\": {\n    \"code\": \"license_email_mismatch\",\n    \"message\": \"The license key and the email don't match!\"\n  }\n}<\/code><\/pre>\n\n<p><strong>Sample Response (Error &#8211; Limit Reached):<\/strong><\/p>\n<pre><code>{\n  \"success\": false,\n  \"data\": {\n    \"code\": \"license_limit_reached\",\n    \"message\": \"License activation limit was reached\"\n  }\n}<\/code><\/pre>\n\n<h3>6. Deactivate License<\/h3>\n\n<p>Deactivate a license from a specific site\/domain.<\/p>\n\n<p><strong>Endpoint:<\/strong> <code>POST \/wp-json\/easycommerce\/v1\/licenses\/{key}\/deactivate<\/code><\/p>\n\n<p><strong>Permissions:<\/strong> Public<\/p>\n\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n    <li><code>key<\/code> (string, required): License key<\/li>\n    <li><code>site_url<\/code> (string, required): URL of the site to deactivate<\/li>\n<\/ul>\n\n<p><strong>Sample Request:<\/strong><\/p>\n<pre><code>curl -X POST \"https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/ABC123-DEF456-GHI789\/deactivate\" \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{\n    \"site_url\": \"https:\/\/mysite.com\"\n  }'<\/code><\/pre>\n\n<p><strong>Sample Response (Success):<\/strong><\/p>\n<pre><code>{\n  \"success\": true,\n  \"data\": {\n    \"code\": \"license_deactivated\",\n    \"message\": \"License deactivated\"\n  }\n}<\/code><\/pre>\n\n<p><strong>Sample Response (Error):<\/strong><\/p>\n<pre><code>{\n  \"success\": false,\n  \"data\": {\n    \"code\": \"license_deactivation_failed\",\n    \"message\": \"Failed to deactivate site\"\n  }\n}<\/code><\/pre>\n\n<h3>7. Update License<\/h3>\n\n<p>Update license status.<\/p>\n\n<p><strong>Endpoint:<\/strong> <code>PUT \/wp-json\/easycommerce\/v1\/licenses\/{key}<\/code><\/p>\n\n<p><strong>Permissions:<\/strong> Public<\/p>\n\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n    <li><code>key<\/code> (string, required): License ID or license key<\/li>\n    <li><code>status<\/code> (string, required): New status (<code>active<\/code>, <code>inactive<\/code>, <code>expired<\/code>, <code>blocked<\/code>)<\/li>\n<\/ul>\n\n<p><strong>Sample Request:<\/strong><\/p>\n<pre><code>curl -X PUT \"https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/ABC123-DEF456-GHI789\" \\\n  -H \"Content-Type: application\/json\" \\\n  -d '{\n    \"status\": \"blocked\"\n  }'<\/code><\/pre>\n\n<p><strong>Sample Response:<\/strong><\/p>\n<pre><code>{\n  \"success\": true,\n  \"data\": {\n    \"message\": \"License updated\"\n  }\n}<\/code><\/pre>\n\n<h2>PHP Integration Examples<\/h2>\n\n<h3>License Activation Check<\/h3>\n\n<pre><code>function check_license_activation($license_key, $product_slug, $site_url) {\n    $api_url = 'https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/' . $license_key . '\/activate';\n    \n    $response = wp_remote_post($api_url, array(\n        'body' => json_encode(array(\n            'product' => $product_slug,\n            'email' => get_option('admin_email'), \/\/ or user's email\n            'site_url' => $site_url\n        )),\n        'headers' => array(\n            'Content-Type' => 'application\/json'\n        )\n    ));\n    \n    if (is_wp_error($response)) {\n        return false;\n    }\n    \n    $body = json_decode(wp_remote_retrieve_body($response), true);\n    \n    if ($body['success']) {\n        \/\/ License activated successfully\n        update_option('my_plugin_license_status', 'active');\n        update_option('my_plugin_license_expiry', $body['data']['expiry']);\n        return true;\n    } else {\n        \/\/ Handle error\n        update_option('my_plugin_license_status', 'inactive');\n        return false;\n    }\n}<\/code><\/pre>\n\n<h3>Daily License Validation<\/h3>\n\n<pre><code>function validate_license_daily() {\n    $license_key = get_option('my_plugin_license_key');\n    $site_url = get_site_url();\n    $last_check = get_option('my_plugin_last_license_check');\n    \n    \/\/ Check once per day\n    if (!$last_check || (time() - $last_check) > 86400) {\n        $api_url = 'https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/' . $license_key;\n        \n        $response = wp_remote_get($api_url, array(\n            'headers' => array(\n                'Content-Type' => 'application\/json'\n            )\n        ));\n        \n        if (!is_wp_error($response)) {\n            $body = json_decode(wp_remote_retrieve_body($response), true);\n            \n            if ($body['success']) {\n                $license_data = $body['data'];\n                \n                \/\/ Check if current site is activated\n                $is_activated = false;\n                foreach ($license_data['activations'] as $activation) {\n                    if ($activation['site'] === $site_url) {\n                        $is_activated = true;\n                        break;\n                    }\n                }\n                \n                if (!$is_activated || $license_data['status'] !== 'active') {\n                    \/\/ Deactivate plugin functionality\n                    update_option('my_plugin_license_status', 'inactive');\n                } else {\n                    update_option('my_plugin_license_status', 'active');\n                }\n            }\n        }\n        \n        update_option('my_plugin_last_license_check', time());\n    }\n}\nadd_action('init', 'validate_license_daily');<\/code><\/pre>\n\n<h3>JavaScript Integration<\/h3>\n\n<pre><code>\/\/ License activation\nasync function activateLicense(licenseKey, productSlug, email, siteUrl) {\n    const response = await fetch('https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/' + licenseKey + '\/activate', {\n        method: 'POST',\n        headers: {\n            'Content-Type': 'application\/json'\n        },\n        body: JSON.stringify({\n            product: productSlug,\n            email: email,\n            site_url: siteUrl\n        })\n    });\n    \n    const result = await response.json();\n    \n    if (result.success) {\n        console.log('License activated:', result.data);\n        localStorage.setItem('license_status', 'active');\n        localStorage.setItem('license_expiry', result.data.expiry);\n    } else {\n        console.error('License activation failed:', result.data.message);\n        localStorage.setItem('license_status', 'inactive');\n    }\n}\n\n\/\/ Check license status\nasync function checkLicenseStatus(licenseKey) {\n    const response = await fetch('https:\/\/your-site.com\/wp-json\/easycommerce\/v1\/licenses\/' + licenseKey);\n    const result = await response.json();\n    \n    if (result.success) {\n        const license = result.data;\n        console.log('License status:', license.status);\n        console.log('Activations:', license.activations);\n        return license;\n    }\n    \n    return null;\n}<\/code><\/pre>\n\n<h2>Error Codes<\/h2>\n\n<ul>\n    <li><code>license_not_found<\/code>: License key does not exist<\/li>\n    <li><code>license_email_mismatch<\/code>: Email doesn&#8217;t match the license purchaser<\/li>\n    <li><code>license_limit_reached<\/code>: Maximum activations exceeded<\/li>\n    <li><code>license_expired<\/code>: License has expired<\/li>\n    <li><code>license_mismatch<\/code>: License doesn&#8217;t belong to the specified product<\/li>\n    <li><code>license_activation_failed<\/code>: Failed to activate (database error)<\/li>\n    <li><code>license_deactivation_failed<\/code>: Failed to deactivate (database error)<\/li>\n<\/ul>\n\n<h2>Rate Limiting<\/h2>\n\n<p>The API includes standard WordPress rate limiting. For public endpoints (activation\/deactivation), implement additional client-side rate limiting to prevent abuse.<\/p>\n\n<h2>Security Considerations<\/h2>\n\n<ol>\n    <li>Always validate license keys server-side<\/li>\n    <li>Use HTTPS for all API calls<\/li>\n    <li>Implement proper error handling<\/li>\n    <li>Store sensitive data securely<\/li>\n    <li>Regularly validate licenses (recommended: daily)<\/li>\n    <li>Handle network failures gracefully<\/li>\n<\/ol>\n\n<h2>Support<\/h2>\n\n<p>For additional support or questions about the EasyCommerce License Manager API, please contact the EasyCommerce support team.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"author":1,"featured_media":0,"template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}}},"easy_topic":[21],"easy_product":[19],"class_list":["post-1011","ek_doc","type-ek_doc","status-publish","hentry","easy_topic-addons","easy_product-easycommerce"],"_links":{"self":[{"href":"https:\/\/easycommerce.dev\/docs\/wp-json\/wp\/v2\/ek_doc\/1011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/easycommerce.dev\/docs\/wp-json\/wp\/v2\/ek_doc"}],"about":[{"href":"https:\/\/easycommerce.dev\/docs\/wp-json\/wp\/v2\/types\/ek_doc"}],"author":[{"embeddable":true,"href":"https:\/\/easycommerce.dev\/docs\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/easycommerce.dev\/docs\/wp-json\/wp\/v2\/media?parent=1011"}],"wp:term":[{"taxonomy":"easy_topic","embeddable":true,"href":"https:\/\/easycommerce.dev\/docs\/wp-json\/wp\/v2\/easy_topic?post=1011"},{"taxonomy":"easy_product","embeddable":true,"href":"https:\/\/easycommerce.dev\/docs\/wp-json\/wp\/v2\/easy_product?post=1011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}