Goal: Provide an entity type which represents the resource purchased when a non-physical product is sold.

Examples:
- Site role
- File download
- Group membership
- Remote service
- Software license
- Membership plan

1. Commerce License entity
- References a product variation
- Has a variety of statuses (created, pending, active, suspended, revoked, expired)
- Belongs to the user who purchased the product variation
- Can be thought of as a representation of the purchased product, analogous to a shipment item
- Based on product configuration (see below) can be configured as:
- Single-purchase license, with optional expiration dates, automatic expiration behavior, and the option of manual renewal-by-purchase
- Recurring license which attaches itself to recurring billing behavior (by implementing the Subscription plugin type that Commerce Recurring defines)
- This configuration is exclusive -- each product type can be licensable (purchase) or licensable (recurring) but not both.
- At checkout, licenses are automatically activated and synchronization is scheduled if required
- Synchronization normally happens via queue items in the background while a post-checkout page awaits and displays the relevant access details
- We also need to provide really easy ways to use these access details in various UI elements, Views, etc.
- Licenses in non-recurring mode can be automatically expired by cron or cron+queue items
2. Commerce License Type plugin
- Using entity bundle plugin, each license type is a class which describes the fields on that type
- In addition, the license type implements a plugin interface which handles the type-specific methods:
- Synchronize
- Status changes
- Activate
- Expire
- Suspend
- Revoke
- Renew
- Form(Validate/Submit)
- Configurable
- Checkout messages
- Access details
- This is different from 1.x and most of the code will look like $license->getPlugin()->suspend()

Comments

colan created an issue. See original summary.

bojanz’s picture

This module can be ported at any time. License content entity type + License type plugin type (use the PluginBundle API that ships with Commerce 2.x and is used by payment methods as an example).

grasmash’s picture

What do you think of splitting the "license" functionality (reference to a user and another licensed entity) into a separate module? commerce_license could then act as a connector between license and commerce, but developers could use license in conjunction with different ecommerce solutions or perhaps with no ecommerce solution.

bojanz’s picture

I think there's not enough functionality there to get any benefits from such a split.
D8 entity types are cheap enough that enough can just write their own licence entity type with different (non-Commerce) semantics.

grasmash’s picture

The following features could be split into a non-commerce-specific module:

  • The license entity type
    • User reference
    • Expiry date and time
    • Expires automatically
    • Licensed entity
    • Status
  • Default views
    • Licenses by status
    • Licenses referencing a particular entity
    • Licenses belonging to a particular user
  • Cron processing to update status of expired licenses
  • Node access control via licenses

I've started work on this separate module because I am certain that I want these features, but I am not yet certain what commerce solution I will use. I could use inline entity forms to bake this directly into a commerce checkout process, or I could simply implement endpoints that grant or revoke licenses via webhooks from a third party service.

Initial work is here: https://github.com/grasmash/drupal-license. When I've implemented all listed features, I will move it to d.o. For now, I've simply defined the entity type.

grasmash’s picture

I've moved my work-in-progress to the Licensing module:
https://www.drupal.org/project/licensing

I'd like to build the D8 version in such a way that it can be easily integrated with Commerce. Please let me know what I can do to that effect. I think it's in our best interest to promote collaboration over competition and focus on one module to provide licensing functionality.

cmcintosh’s picture

Is this something being actively worked on still @grasmash?

Anonymous’s picture

Questions for anyone who can advise:

1. Would it be possible to use the Licensing module ( https://www.drupal.org/project/licensing ) and set up a rule that triggers the license when a Commerce order is complete? If I understand how the Commerce License module works, that's seems to be the underlying process.

2. If the answer to #2 is no, what can I do to help move this along as my entire plan to upgrade to D8 depends on Commerce License (or equivalent functionality)? I don't have much experience in module development, but I'm happy to help however I can.

cmcintosh’s picture

Hey anne, not terribly sure what the plan is. I have done a bit of work on two modules that fulfill this functionality. The first being https://github.com/cmcintosh/commerce_license which focuses just on the Digital product rights aspect of things (ie access / roles). In addition to that module I have another module where I am specifically handling the subscription aspect of things, https://github.com/cmcintosh/commerce_subs

The version of license i built automatically handles things when orders are complete meaning, the users are not awarded the Role / digital good until the transaction is marked complete. Ping me on skype if you want to chat more about what i got I could use more hands to make it more stable.

jmomandown’s picture

@cmcintosh The version of commerce_license you have provided works fairly well albeit a few bugs. Can we possibly get a accessible dev branch started and I would be happy to provide some contributions as well. I believe this pretty much takes care of 95% of the use cases.

The module was tested on a copy of a high volume live Drupal 8 Commerce site which we forked to a dev branch to test this module. The site relies heavily on roles for limited period access to software applications hosted internally within the framework.

cmcintosh’s picture

Sounds like a good plan, it has been a while since working on D.O repos, I think we will need to get bojanz to open up the branch and then I can create a patch against that with what I have on the Github repo.

Also, feel free to post issues over there that you found. It is still a very rough workup on License so I am sure there are lots to be done as of yet. Also if your looking for time based products I also have another repo for this called https://github.com/cmcintosh/commerce_subs which handles awarding licenses on a recurring nature. It too is still rough and i am actively working on it this / next week.

Idea is to have things like conditions for allowing users to be able to purchase the subscriptions, etc.

jmomandown’s picture

So am I correct in understanding that the subs module is essentially the license module with conditional checking on recurring purchases? In most use cases the product itself is redundant if a role is established or visa versa.

If bojanz will open a branch relatively soon it may be more efficient to propose a patch subsequently to your initial as the bugs are mostly minor in nature and occur in specific use cases. Would be easier to track them all initially and start fresh with development moving forward. I will likely be up for significant time on progressing this as it is a necessity to our project.

ron.du’s picture

I believe for recurring billing in D7 for commerce license is
https://www.drupal.org/project/commerce_license_billing

How commerce_sub is different form this one ?

cmcintosh’s picture

They pretty much fill the same roll, the big difference being that not only is it for Digital goods ie licenses, additionally it can be used for physical (standard) commerce products. In addition to that I am utilizing the Field plugin system in Drupal 8 to allow for extending the functionality.

Commerce sub will allow you to use the UI to create a subscription plan by selecting Products / Licenses. Setting conditions on who can purchase the subscription(atm in development), and will generate unique invoices for each billing cycle. Additionally I have some controls for manually re-subbing the customers when needed.

Because the subscription is setup to create multiple order invoices, you could also refund specific invoices or a series of invoices.

ron.du’s picture

Sounds Good. Thumbs up :D

bojanz’s picture

I've looked at https://github.com/cmcintosh/commerce_license but it appears to be a copy of the commerce_product module, and it doesn't use entity_bundle_plugin for license types. So I fear that we won't be able to use much of that code.

cmcintosh’s picture

I did take a lot from the commerce_product module. Im using the Drupal Plugin api for extending the type of things to be able to license. It would be good to chat a bit more later on, and maybe share some links to exactly the structure we are looking towards. This first draft i did was mostly because it was something I needed for a project so I am open for suggestions / direction on things.

cmcintosh’s picture

Ill read through, https://bojanz.wordpress.com/2013/07/19/entity-bundle-plugin/ a bit more and refactor things around that.

bojanz’s picture

Issue summary: View changes

Mixed up the comment & summary fields, ignore this comment.

bojanz’s picture

Issue summary: View changes

Transferring notes from a conversation I had with Kazanir.
This architecture matches the D7 one, and might evolve in time.

The best example for bundle plugins in D8 is payment method types in the commerce_payment module.

Kazanir’s picture

We're making an official port of this based on long experience using it in production and designing around various use cases. I'll open another meta thread for tracking various sub-issues and also gathering feedback. In addition to our plans for unified recurring module (bringing together Commerce License Billing and Commerce Recurring) we feel like this module still has a place and shouldn't be generalized in the way that was discussed upthread.

The basic module scaffolding, which does not yet even work, is in the 8.x-2.x branch. New issues forthcoming.

Kazanir’s picture

Kazanir’s picture

Assigned: Unassigned » Kazanir
Status: Active » Fixed
cmcintosh’s picture

Ok sounds good, so then i guess ill leave you to it then. Seems like my help is not wanted here.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

chrisrockwell’s picture

@Kazanir were you able to create the meta with sub-issues? I'm struggling to find it - thanks!

plato1123’s picture

Any status on a working recurring/subscription system on D8? Is there another thread with more updated info?
+1 sub

chrisrockwell’s picture

@plato1123 bojanz and mglaman mentioned in slack that work is underway, but I don't think a meta-thread exists yet.