Commerce License

Provides a framework for selling access to site resources such as roles through Commerce products.

commerce_license
2,613 sites
65
drupal.org

インストール

Drupal 11, 10, 9 v3.0.2
composer require 'drupal/commerce_license:^3.0'
Drupal 8 v8.x-2.0
composer require 'drupal/commerce_license:8.x-2.0'

概要

Commerce Licenseは、サイトの特定の機能へのアクセスを販売する製品の作成を可能にします。これはロール、Nodeの公開、またはカスタムライセンスタイププラグインによって制御されるその他のアクセス権限などが該当します。

製品が購入されると、ユーザー用のLicenseエンティティが作成されます。Licenseエンティティが付与するものの性質はライセンスタイププラグインによって処理され、各Licenseエンティティは1つのライセンスタイププラグインに関連付けられます。ライセンスを販売する製品バリエーションには、ユーザーがその製品バリエーションを購入した際にライセンスを作成するためのテンプレートとして機能する、設定済みのライセンスタイププラグインフィールド値があります。

このモジュールは、新規、保留中、アクティブ、一時停止、期限切れ、取り消し、キャンセルなどの状態を含むライセンスの包括的なワークフロー管理を提供します。Commerce Checkoutと統合して認証済みユーザーのみがライセンスを購入できるようにし、オプションでCommerce Recurringと統合してサブスクリプションベースのライセンス更新をサポートします。

Features

  • 設定可能なワークフロー状態(new、pending、active、renewal_in_progress、suspended、expired、revoked、canceled、failed)を持つLicenseエンティティタイプ
  • ライセンスのアクティブ化/非アクティブ化時にユーザーロールを付与/取り消すRoleライセンスタイププラグイン
  • Unlimited、Rolling Interval、Fixed Reference Date Intervalの期間プラグインによる柔軟なライセンス有効期限システム
  • 製品バリエーション用('Provides a license')および注文アイテム用('Provides an order item type for use with licenses')のエンティティトレイト
  • 注文の支払い時または注文確定時の自動ライセンスアクティブ化(製品バリエーションタイプごとに設定可能)
  • 設定可能なウィンドウ内で有効期限前に顧客が再購入できるライセンス更新サポート
  • Advanced Queue統合による信頼性の高い処理を伴うCronベースの自動ライセンス期限切れ処理
  • ライセンス期限切れ時にユーザーに送信されるメール通知
  • 設定要件と検証のステータスレポートを提供するライセンスダッシュボード
  • フィルタリングと一括操作が可能なすべてのライセンスを管理するViewsベースの管理インターフェース
  • ライセンス状態変更を追跡するCommerce Log統合
  • 自動更新されるサブスクリプションベースのライセンス用のオプションのCommerce Recurring統合
  • ユーザーが既に持っているライセンスの購入を防ぐ既存権限チェック
  • ライセンス付与されたロールの手動削除を防ぐユーザー編集フォームでの付与ロール保護

Use Cases

Membership Site with Role-Based Access

Create a membership site where users purchase access to premium content. Configure a 'Premium Member' role with appropriate permissions, create a product variation with the license trait that grants this role, set an expiration period (e.g., 1 year rolling interval), and when users purchase the product, they automatically receive the role for the configured period. The role is automatically removed when the license expires.

Software License Sales

Sell time-limited software licenses where the license grants a role that provides access to download or support areas. Use the rolling interval expiration to provide licenses valid for a set period from purchase. Customers receive email notifications when licenses expire and can repurchase to renew.

Subscription-Based Access with Commerce Recurring

Create recurring subscription products where licenses automatically renew with payment. Configure the product variation with both the license trait and subscription trait, set license expiration to 'Unlimited', and choose a billing schedule. The subscription handles payment and renewal, while the license handles access. When a subscription is canceled, the license is automatically canceled.

Annual Membership with Fixed Renewal Date

Implement memberships that all expire on the same date (e.g., December 31st) regardless of when purchased. Use the 'Interval based on reference date' expiration type with a reference date of January 1st and a 1-year interval. All licenses expire at year end, creating synchronized renewal periods.

Early Renewal Window

Allow customers to renew their licenses before expiration. Configure the product variation type with 'Allow renewal before expiration' enabled and set the renewal window (e.g., 30 days). Customers with active licenses within the renewal window can repurchase to extend their license; their expiration date extends from the current expiration rather than from the renewal date.

Tips

  • Use the License Dashboard at /admin/commerce/config/licenses/dashboard to validate your entire license configuration chain from checkout flow to products.
  • For testing, create a simple checkout flow with minimal steps but ensure guest checkout is disabled.
  • When using Commerce Recurring for subscriptions, always set the license expiration to 'Unlimited' as the subscription controls the lifecycle.
  • The Role license type protects granted roles on user edit forms, preventing accidental removal of licensed roles by administrators.
  • License state transitions are logged to Commerce Log when enabled, providing an audit trail of license changes.
  • Custom license types can be created by implementing LicenseTypeInterface - useful for granting access to custom functionality beyond roles.
  • The expiration email template (commerce-license-expire.html.twig) can be overridden in your theme to customize notification emails.

Technical Details

Admin Pages 7
Licenses /admin/commerce/licenses

View and manage all licenses in the system. Provides a filterable table listing all licenses with columns for ID, Label, License Type, Owner, State, Granted date, Expires date, and Updated date. Supports bulk operations including delete.

Licenses /admin/commerce/config/licenses

License configuration section providing access to License Dashboard and License Types management.

License dashboard /admin/commerce/config/licenses/dashboard

Displays a comprehensive status report validating the complete license configuration chain. Shows the status of checkout flows, order types, order item types, product variation types, product types, and products to ensure all components are properly configured for selling licenses.

License types /admin/commerce/config/licenses/license-types

Manage fields, form and display settings for license entities by license type bundle.

View License /admin/commerce/licenses/{commerce_license}

View a single license entity showing all fields including type, owner, state, licensed product variation, expiration type, created/granted/renewed/expires timestamps, and activity log.

Edit License /admin/commerce/licenses/{commerce_license}/edit

Edit form for license entities. Displays owner information, license state with available transitions, timestamps (expires, renewed, granted, changed, created), and license-type-specific fields.

Add license /admin/commerce/licenses/add/{type}

Administrative form for manually creating a new license. This bypasses the normal product purchase flow and should only be used by administrators who understand the implications.

権限 9
Administer Commerce License

Full administrative access to Commerce License configuration and entities

Access license overview

View the licenses listing page (restricted access)

Create license

Create licenses in administrative mode, bypassing the purchase of a product

View license

View license entities

View own license

View own license entities

Update license

Edit license entities

Update own license

Edit own license entities

Delete license

Delete license entities

Delete own license

Delete own license entities

Hooks 2
hook_commerce_license_type_info_alter

Modify the list of available License Type plugins. Can be used to remove plugins or change plugin labels.

hook_commerce_license_period_info_alter

Modify the list of available License Period plugins. Can be used to remove plugins or change plugin labels.

Troubleshooting 6
Licenses are not being created when orders are placed

Verify that the checkout flow does not allow guest checkout (Login pane must have 'Guest checkout: Not allowed'). Check that the order item type has the 'Provides an order item type for use with licenses' trait. Use the License Dashboard at /admin/commerce/config/licenses/dashboard to validate your configuration.

Licenses are not activating after payment

Ensure the product variation's 'Activate license when order is placed' setting matches your expected behavior. If using asynchronous payment gateways, licenses activate on payment confirmation via the ORDER_PAID event.

Users can purchase products for which they already have an active license

The existing rights checker should prevent this. Verify the license type plugin implements ExistingRightsFromConfigurationCheckingInterface and the checkUserHasExistingRights() method returns appropriate results.

Licenses are not expiring automatically

Ensure cron is running regularly. Check that the Advanced Queue module is properly configured and the 'commerce_license' queue is being processed. The commerce_license.cron service queues expiration jobs during cron, and Advanced Queue processes them.

Role is not being granted/revoked when license state changes

Verify the license has the correct role configured in its license_role field. Check that the user entity is being saved properly by the Role license type plugin's grantLicense() and revokeLicense() methods.

Subscription licenses not working correctly

Ensure the license expiration is set to 'Unlimited' when using subscriptions. The subscription controls the lifecycle; the license should not expire independently. Verify the LicenseSubscriptionType plugin is handling subscription events.

Security Notes 5
  • The 'administer commerce_license' permission is marked as 'restrict access' and should only be granted to trusted administrators.
  • The 'access commerce_license overview' permission is also restricted as it provides access to view all licenses in the system.
  • License type plugins can escalate user privileges (e.g., granting administrative roles). The module validates that only allowed license types can be selected on product variations.
  • The admin forms for creating/editing licenses directly should only be used by developers who understand the implications - changing values can break license state consistency.
  • Guest checkout must be disabled for license-selling checkout flows to ensure licenses are always associated with authenticated users.