ログイン
始める

Easy Digital Downloads ドキュメント

Easy Digital Downloads のドキュメント、参考資料、チュートリアル

ソフトウェアライセンスAPI – JavaScriptを使用した例

このドキュメントは、APIで利用可能なすべての機能をリストしたソフトウェアライセンスAPIドキュメントのサブセットです。以下は、それらの機能をJavaScriptで実装する方法を示すサンプルコードです。

jQueryを使用している場合は、jQueryの例を参照してください。

GETリクエストの例

const url = new URL( 'https://yoursite.com/' ); // Site with Software Licensing activated.
const urlParams = new URLSearchParams( {
	edd_action: 'check_license',
	license: '59cc77ea94a2d867069a9d96142a35b8', // License key
	item_id: '356', // Product ID
	url: 'domain.com' // Domain the request is coming from.
} );
url.search = urlParams.toString();
fetch( url.toString() )
	.then( response => {
		if ( response.ok ) {
			return response.json();
		} else {
			return Promise.reject( response );
		}
	} ).then( data => {
		// Software Licensing has a valid response to parse
		console.log( 'Successful response', data );
	} ).catch( error => {
		// Error handling.
		console.log( 'Error', error );
	} );

POSTリクエストの例

const formData = new FormData();
formData.append( 'edd_action', 'check_license' ); // Valid actions are activate_license, deactivate_license, get_version, check_license
formData.append( 'license', '59cc77ea94a2d867069a9d96142a35b8' ); // License key
formData.append( 'item_id', '356' ); // Product ID
formData.append( 'url', 'domain.com' ); // If you disable URL checking you do not need this entry.

// Site with Software Licensing activated.
fetch( 'https://yoursite.com/', {
	method: 'POST',
	body: formData
} ).then( response => {
	if ( response.ok ) {
		return response.json();
	} else {
		return Promise.reject( response );
	}
} ).then( data => {
	// Software Licensing has a valid response to parse
	console.log( 'Successful response', data );
} ).catch( error => {
	// Error handling.
	console.log( 'Error', error );
} );

レスポンス

上記のクエリに対する応答は、次のようなJSONオブジェクトになります。

{
    "success": true,
    "license": "valid",
    "item_id": 12534,
    "item_name": "Your Product Name",
    "expires": "2022-02-26 23:59:59",
    "payment_id": 123456,
    "customer_name": "Jane Doe",
    "customer_email": "[email protected]",
    "price_id": 0,
}

古いブラウザ向けのサンプルリクエスト

上記​​の例は、最新のブラウザを念頭に置いて作成されています。IEのサポートが必要な場合は、XMLHttpRequestオブジェクトの使用を検討してください。

// Handling a Software licensing request without jQuery in pure JavaScript. Support for older browsers.
var xhttp = new XMLHttpRequest();

// The url to the site running Easy Digital Downloads w/Software Licensing
var postUrl = 'https://yoursite.com/';

xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
        var slData = JSON.parse(xhttp.responseText);
        handleSoftwareLicensingResponse( slData );
    }   
}

var data = {
	edd_action: 'check_license', // Valid actions are activate_license, deactivate_license, get_version, check_license
	license: '59cc77ea94a2d867069a9d96142a35b8', // License key.
	item_id: '356', // Product ID
	url: 'domain.com' // If you Disable URL Checking, you do not need this entry
};

xhttp.open("POST", postUrl, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("Access-Control-Allow-Origin", "https://local.dev");

var values = '';
for (var key in data){
    values += key + '=' + data[ key ] + '&';
}
values = values.substring(0, values.length - 1);

xhttp.send(values);


function handleSoftwareLicensingResponse( slData ) {
    if ( slData.success == true ) {
        console.log(slData);
        // Software Licensing has a valid response to parse
    } else {
        // Invalid request was made to software licensing
    }
}
この記事は役に立ちましたか?

今日から販売を開始しましょう!

50,000人以上のスマートなストアオーナーに参加して、WordPressでデジタル製品を販売する最も簡単な方法を使い始めましょう。

Copyright © 2025 Sandhills Development, LLC

[universally_switcher]